Skip to content

Commit e24d4c1

Browse files
committed
make run_id automatic for pr preview
Signed-off-by: Aritra Dey <[email protected]>
1 parent 4562db8 commit e24d4c1

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

.github/workflows/publish-docs.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ on:
1111
description: 'PR number to deploy preview for'
1212
required: true
1313
type: number
14-
run_id:
15-
description: 'Run ID of the build workflow (from the PR checks)'
16-
required: true
17-
type: string
1814

1915
permissions:
2016
contents: write
@@ -51,12 +47,27 @@ jobs:
5147
- name: Checkout
5248
uses: actions/checkout@v4
5349

50+
- name: Find latest run ID
51+
id: find-run
52+
env:
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
run: |
55+
BRANCH=$(gh pr view ${{ inputs.pr_number }} --json headRefName --jq .headRefName)
56+
echo "Found branch: $BRANCH"
57+
RUN_ID=$(gh run list --workflow "Publish Docs" --branch "$BRANCH" --event pull_request --status success --limit 1 --json databaseId --jq '.[0].databaseId')
58+
echo "Found run ID: $RUN_ID"
59+
if [ -z "$RUN_ID" ]; then
60+
echo "::error::No successful 'Publish Docs' run found for PR #${{ inputs.pr_number }} (branch: $BRANCH)"
61+
exit 1
62+
fi
63+
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
64+
5465
- name: Download build artifact
5566
uses: actions/download-artifact@v4
5667
with:
5768
name: site
5869
path: site
59-
run-id: ${{ inputs.run_id }}
70+
run-id: ${{ steps.find-run.outputs.run_id }}
6071
github-token: ${{ secrets.GITHUB_TOKEN }}
6172

6273
- name: Deploy PR Preview

0 commit comments

Comments
 (0)