diff --git a/.github/workflows/docs-pr-preview.yml b/.github/workflows/docs-pr-preview.yml index 090ec66..52fb6ad 100644 --- a/.github/workflows/docs-pr-preview.yml +++ b/.github/workflows/docs-pr-preview.yml @@ -70,24 +70,30 @@ jobs: target: pr/${{ github.event.number }} commit-message: "Deploy PR #${{ github.event.number }} preview" - - name: Post or update PR comment + - name: Wait for deployment + id: wait uses: actions/github-script@v7 with: script: | const url = '${{ steps.deploy.outputs.url }}'; - - // Wait for deployment to be live (poll every 10s, up to 5 min) - let live = false; - for (let i = 0; i < 30; i++) { + const maxAttempts = 30; + const intervalMs = 10_000; + for (let i = 0; i < maxAttempts; i++) { try { const res = await fetch(url); - if (res.ok) { live = true; break; } + if (res.ok) { core.setOutput('live', 'true'); return; } } catch (e) {} - await new Promise(r => setTimeout(r, 10000)); + await new Promise(r => setTimeout(r, intervalMs)); } + core.setOutput('live', 'false'); + - name: Post or update PR comment + uses: actions/github-script@v7 + with: + script: | + const url = '${{ steps.deploy.outputs.url }}'; const marker = ''; - const status = live ? '' : '\n\n> **Note:** The preview may not be ready yet.'; + const status = '${{ steps.wait.outputs.live }}' === 'true' ? '' : '\n\n> **Note:** The preview may not be ready yet.'; const body = `${marker}\nšŸ“– Docs preview: ${url}${status}`; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner,