Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions .github/workflows/documentation-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
permissions:
actions: read
contents: read
pull-requests: read
jobs:
deploy:
name: Deploy
Expand All @@ -25,33 +24,17 @@ jobs:
with:
skip-build: true

- name: Resolve PR number
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
REPOSITORY: ${{ github.repository }}
WORKFLOW_PRS: ${{ toJSON(github.event.workflow_run.pull_requests) }}
- name: Download PR number
uses: actions/download-artifact@v4
with:
name: pr-number
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Read PR number
run: |
set -euo pipefail
PR_COUNT=$(jq 'length // 0' <<< "${WORKFLOW_PRS:-null}")
if [ "$PR_COUNT" -eq 1 ]; then
PR_NUM=$(jq -r '.[0].number' <<< "$WORKFLOW_PRS")
elif [ "$PR_COUNT" -eq 0 ]; then
if ! [[ "$HEAD_SHA" =~ ^[0-9a-fA-F]{40,64}$ ]]; then
echo "Invalid source workflow head SHA"
exit 1
fi
PR_JSON=$(gh api --paginate "repos/${REPOSITORY}/commits/${HEAD_SHA}/pulls")
PR_COUNT=$(jq 'length // 0' <<< "$PR_JSON")
if [ "$PR_COUNT" -ne 1 ]; then
echo "Failed to uniquely resolve PR number for commit ${HEAD_SHA} (found ${PR_COUNT} pull requests)"
exit 1
fi
PR_NUM=$(jq -r '.[0].number' <<< "$PR_JSON")
else
echo "Ambiguous PR metadata: found ${PR_COUNT} pull requests on the source workflow run"
exit 1
fi
PR_NUM=$(cat pr_number.txt)
if ! [[ "$PR_NUM" =~ ^[0-9]+$ ]]; then
echo "Failed to resolve a valid PR number"
exit 1
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,14 @@ jobs:
with:
name: a11y-coverage
path: packages/react-docs/coverage

- name: Save PR number
if: github.event_name == 'pull_request'
run: echo "${{ github.event.pull_request.number }}" > pr_number.txt

- name: Upload PR number
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: pr-number
path: pr_number.txt
Loading