when:
  - event: push
    branch: sv-fe
    paths:
      - web/**
      - flake.nix
      - flake.lock
      - nix/pkgs/web-static-files.nix
      - .tangled/workflows/deploy-web-dev.yml

engine: microvm
image: alpine

environment:
  SVELTE_ADAPTER: cloudflare
  VITE_OAUTH_CLIENT_ID: https://next.tangled.org/oauth-client-metadata.json
  VITE_OAUTH_REDIRECT_URI: https://next.tangled.org/oauth/callback

steps:
  - name: install nodejs, pnpm
    command: apk add nodejs pnpm

  - name: install web dependencies
    command: |
      cd web
      pnpm install --frozen-lockfile

  - name: sync web static assets
    command: |
      out=$(nix build .#web-static-files --no-link --print-out-paths)
      mkdir -p web/static
      rm -rf web/static/fonts web/static/logos
      cp -fr "$out"/* web/static

  - name: run web unit tests
    command: |
      cd web
      pnpm run test:unit -- --run

  - name: build and deploy web dev worker
    command: |
      cd web
      CLOUDFLARE_API_TOKEN=$CLOUDFLARE_WORKER_DEPLOY_TOKEN pnpm run deploy:cloudflare-dev
