# Manual workflow: regenerate e2e Linux snapshot in CI and push it (fallback when not using the devcontainer).
# Prefer updating snapshots in the devcontainer (same image as CI); use this workflow if you don't use the
# devcontainer (e.g. macOS-only) or can't run the update locally. Trigger manually; choose the branch to update.
#
# Required secret: git_push_token — repo push token (e.g. Gitea/Forgejo personal access token).
# Add in Woodpecker → Repo → Settings → Secrets.
when:
    event: manual

steps:
    - name: update e2e snapshots
      image: mcr.microsoft.com/playwright:v1.58.0-noble
      commands:
          - corepack enable && corepack prepare pnpm@10.28.2 --activate
          - pnpm install --frozen-lockfile || pnpm install
          - pnpm run build
          - npx serve dist -p 4173 &
          - sleep 2
          - CI=1 pnpm exec playwright test --update-snapshots

    - name: commit and push snapshot
      image: alpine/git
      environment:
          GIT_PUSH_TOKEN:
              from_secret: git_push_token
      commands:
          - set -e
          - 'git config user.email "ci@woodpecker"'
          - 'git config user.name "Woodpecker CI"'
          # Push URL with token for write access (Gitea/Forgejo: token as username)
          - 'PUSH_URL="https://$${GIT_PUSH_TOKEN}@$${CI_REPO_CLONE_URL#https://}"'
          - git remote set-url origin "$PUSH_URL"
          - git add tests/visual.spec.ts-snapshots/
          - |
            if git diff --staged --quiet; then
              echo "No snapshot changes to commit."
            else
              git commit -m "chore: update e2e snapshot from CI [skip ci]"
              git push origin "$CI_COMMIT_BRANCH"
              echo "Snapshot pushed to $CI_COMMIT_BRANCH"
            fi
