From 6c980d0e621b4b511d8ec68e381518604676f7e8 Mon Sep 17 00:00:00 2001 From: castellon Date: Tue, 1 Dec 2026 11:03:45 +0100 Subject: [PATCH] CI: wait for the uploaded artifact before exposing it in the Playground preview The expose step downloads the artifact by its ID right after it is uploaded. GitHub sometimes answers "No artifacts found for ID" because the upload is not visible yet, and the whole job fails for a reason unrelated to the pull request. Poll the run's artifact list first, for up to a minute. --- .github/workflows/pr-playground-preview.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/pr-playground-preview.yml b/.github/workflows/pr-playground-preview.yml index 1f1331f8..eb2146d3 100644 --- a/.github/workflows/pr-playground-preview.yml +++ b/.github/workflows/pr-playground-preview.yml @@ -85,6 +85,26 @@ jobs: if-no-files-found: error retention-days: 5 + # The expose step downloads the artifact by its ID a moment after it is uploaded, and GitHub sometimes + # answers "No artifacts found for ID" because the upload is not visible yet. Wait until the run lists it. + - name: Wait until the uploaded artifact is available + env: + GH_TOKEN: ${{ github.token }} + ARTIFACT_NAME: frontblocks-zip-pr${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} + run: | + for attempt in 1 2 3 4 5 6 7 8 9 10; do + found=$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts" \ + --jq "[.artifacts[] | select(.name == env.ARTIFACT_NAME and .expired == false)] | length") + if [ "${found}" -gt 0 ]; then + echo "Artifact listed after ${attempt} attempt(s)." + sleep 5 + exit 0 + fi + echo "Artifact not listed yet (attempt ${attempt}/10), waiting." + sleep 6 + done + echo "::warning::The artifact was not listed after 60 seconds; trying the next step anyway." + - name: Expose built artifact as a public URL id: expose uses: WordPress/action-wp-playground-pr-preview/.github/actions/expose-artifact-on-public-url@v4