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