diff --git a/.github/scripts/publish_pr_homepage_screenshot.js b/.github/scripts/publish_pr_homepage_screenshot.js index 99505033..1f00b92e 100644 --- a/.github/scripts/publish_pr_homepage_screenshot.js +++ b/.github/scripts/publish_pr_homepage_screenshot.js @@ -16,7 +16,10 @@ const sha = process.env.GITHUB_SHA; const prNumber = process.env.PR_NUMBER; const prHeadRef = process.env.PR_HEAD_REF; -if (!token) throw new Error('GITHUB_TOKEN or GH_TOKEN is required.'); +if (!token) { + console.warn('Warning: GITHUB_TOKEN or GH_TOKEN is not set. Skipping PR screenshot publish step.'); + process.exit(0); +} if (!repository || !prNumber || !runId || !prHeadRef || !sha) { throw new Error('Missing one or more required GitHub environment variables.'); } diff --git a/.github/workflows/pr_frontend_e2e.yml b/.github/workflows/pr_frontend_e2e.yml index d55948f4..3494192e 100644 --- a/.github/workflows/pr_frontend_e2e.yml +++ b/.github/workflows/pr_frontend_e2e.yml @@ -67,7 +67,7 @@ jobs: - name: Publish screenshot to PR comment if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false env: - GITHUB_TOKEN: ${{ secrets.CRAZYGO_PAT }} + GITHUB_TOKEN: ${{ secrets.GH_TOKEN || github.token }} GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_RUN_ID: ${{ github.run_id }} GITHUB_SHA: ${{ github.sha }} diff --git a/docs/plans/2026-04-02-14-20-UTC-pr-homepage-screenshot-token-fallback.md b/docs/plans/2026-04-02-14-20-UTC-pr-homepage-screenshot-token-fallback.md new file mode 100644 index 00000000..3c7e14e6 --- /dev/null +++ b/docs/plans/2026-04-02-14-20-UTC-pr-homepage-screenshot-token-fallback.md @@ -0,0 +1,24 @@ +# Background +The `PR Frontend E2E` workflow can fail in the `Publish screenshot to PR comment` step when no dedicated PAT-like secret is configured. The publish script currently throws immediately if neither `GITHUB_TOKEN` nor `GH_TOKEN` is present, which causes the job to fail even though screenshot generation itself succeeded. + +# Goals +1. Prevent false-negative workflow failures caused by missing optional custom token configuration. +2. Keep PR screenshot publishing functional by using built-in GitHub token fallbacks. +3. Provide clearer script behavior when no token is available. + +# Implementation Plan (phased) +## Phase 1: Workflow token fallback +- Update `.github/workflows/pr_frontend_e2e.yml` so the publish step injects `GITHUB_TOKEN` from a fallback chain (`GH_TOKEN`, then default `github.token`). + +## Phase 2: Script resilience +- Update `.github/scripts/publish_pr_homepage_screenshot.js` to avoid hard failure when no token is available. +- Add a warning and exit successfully when token is missing so E2E validation/artifact upload still pass. + +## Phase 3: Validation +- Run targeted checks (`node --check`) for the updated script and verify git diff for workflow/script consistency. + +# Acceptance Criteria +1. A PR run without custom PAT configuration no longer fails solely due to missing token in screenshot publish step. +2. Screenshot publish step still attempts to post/update PR comment when any valid token is available. +3. If no token is present, logs show a clear warning and the step exits without failing the full workflow. +4. Updated script passes `node --check .github/scripts/publish_pr_homepage_screenshot.js`.