diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 9699a18213..8d2b18e7da 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -60,9 +60,15 @@ jobs: - name: Read PR metadata id: meta + # Fail loudly if the metadata is missing. A bare `$(cat missing)` + # inside `echo` yields empty output and exit 0, so the step would + # "pass" with empty pr-number/action and the deploy would silently + # skip (the regression this workflow pair just recovered from). run: | - echo "pr-number=$(cat _preview_download/meta/pr-number.txt)" >> "$GITHUB_OUTPUT" - echo "action=$(cat _preview_download/meta/action.txt)" >> "$GITHUB_OUTPUT" + pr_number=$(cat _preview_download/meta/pr-number.txt) || { echo "::error::Missing pr-number.txt in preview artifact"; exit 1; } + action=$(cat _preview_download/meta/action.txt) || { echo "::error::Missing action.txt in preview artifact"; exit 1; } + echo "pr-number=$pr_number" >> "$GITHUB_OUTPUT" + echo "action=$action" >> "$GITHUB_OUTPUT" - name: Deploy PR Preview if: steps.meta.outputs.action == 'deploy' diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 4d7b4cde01..6a50590292 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -42,18 +42,28 @@ jobs: contents: read steps: - - name: Save PR metadata - run: | - mkdir -p _preview_upload/meta - echo "${{ github.event.pull_request.number }}" > _preview_upload/meta/pr-number.txt - echo "${{ github.event.action == 'closed' && 'remove' || 'deploy' }}" > _preview_upload/meta/action.txt - - name: Check out repository if: github.event.action != 'closed' uses: actions/checkout@v5 with: submodules: recursive + # IMPORTANT: write the metadata AFTER checkout. actions/checkout runs + # `git clean -ffdx` (clean: true is the default), which deletes any + # untracked files already in the workspace — including a + # `_preview_upload/` directory created beforehand. With the metadata + # written before checkout, `_preview_upload/meta/` was wiped and never + # reached the artifact, so preview-deploy.yml read an empty pr-number, + # the deploy step's `action == 'deploy'` guard was false, and every + # deploy-path preview was silently skipped (the job still passed). + # For the 'closed'/remove event the checkout step is skipped, but this + # step is unguarded and still runs, so the remove path is unaffected. + - name: Save PR metadata + run: | + mkdir -p _preview_upload/meta + echo "${{ github.event.pull_request.number }}" > _preview_upload/meta/pr-number.txt + echo "${{ github.event.action == 'closed' && 'remove' || 'deploy' }}" > _preview_upload/meta/action.txt + - name: Set up Quarto if: github.event.action != 'closed' uses: quarto-dev/quarto-actions/setup@v2