Skip to content

Commit f9ebb42

Browse files
committed
fix(ci): trigger checks for version package PRs (#14)
## Summary - add manual dispatch support to the CI workflow - have the release workflow trigger CI on the `changeset-release/<base>` branch after Changesets updates the version PR - grant the release workflow the permissions needed to dispatch that run ## Testing - yarn test - yarn lint work: amend version-pr check handling
1 parent 09aa3bb commit f9ebb42

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [main]
66
pull_request:
77
branches: [main]
8+
workflow_dispatch:
89

910
jobs:
1011
check:

.github/workflows/release.yml

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
release:
1111
runs-on: ubuntu-latest
1212
permissions:
13+
checks: write
1314
contents: write
1415
pull-requests: write
1516
id-token: write
@@ -27,9 +28,92 @@ jobs:
2728

2829
- run: yarn build
2930

30-
- uses: changesets/action@v1
31+
- id: changesets
32+
uses: changesets/action@v1
3133
with:
3234
version: yarn ci:version
3335
publish: yarn ci:publish
3436
env:
3537
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Load version PR metadata
40+
if: steps.changesets.outputs.pullRequestNumber != ''
41+
id: version_pr
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
pr_number='${{ steps.changesets.outputs.pullRequestNumber }}'
46+
pr_json="$(gh api repos/${{ github.repository }}/pulls/$pr_number)"
47+
merge_sha="$(printf '%s' "$pr_json" | jq -r '.merge_commit_sha')"
48+
49+
if [ -z "$merge_sha" ] || [ "$merge_sha" = "null" ]; then
50+
echo "Version PR merge commit SHA is unavailable" >&2
51+
exit 1
52+
fi
53+
54+
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
55+
echo "merge_sha=$merge_sha" >> "$GITHUB_OUTPUT"
56+
57+
- name: Create version PR check run
58+
if: steps.version_pr.outputs.merge_sha != ''
59+
id: version_pr_check
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
payload="$(jq -n \
64+
--arg name check \
65+
--arg head_sha '${{ steps.version_pr.outputs.merge_sha }}' \
66+
--arg status in_progress \
67+
--arg started_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
68+
--arg details_url '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
69+
'{name: $name, head_sha: $head_sha, status: $status, started_at: $started_at, details_url: $details_url}')"
70+
response="$(gh api repos/${{ github.repository }}/check-runs --input - <<<"$payload")"
71+
echo "id=$(printf '%s' "$response" | jq -r '.id')" >> "$GITHUB_OUTPUT"
72+
73+
- name: Check out version PR merge ref
74+
if: steps.version_pr.outputs.number != ''
75+
uses: actions/checkout@v4
76+
with:
77+
ref: refs/pull/${{ steps.version_pr.outputs.number }}/merge
78+
79+
- name: Install dependencies for version PR validation
80+
if: steps.version_pr.outputs.number != ''
81+
run: yarn install --immutable
82+
83+
- name: Validate version PR merge
84+
if: steps.version_pr.outputs.number != ''
85+
id: validate_version_pr
86+
continue-on-error: true
87+
run: |
88+
yarn lint
89+
yarn build
90+
yarn test
91+
92+
- name: Finalize version PR check run
93+
if: always() && steps.version_pr_check.outputs.id != ''
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
run: |
97+
conclusion=success
98+
summary='Version PR checks passed on the pull request merge commit.'
99+
100+
if [ '${{ steps.validate_version_pr.outcome }}' != 'success' ]; then
101+
conclusion=failure
102+
summary='Version PR checks failed on the pull request merge commit. See this workflow run for details.'
103+
fi
104+
105+
payload="$(jq -n \
106+
--arg status completed \
107+
--arg conclusion "$conclusion" \
108+
--arg completed_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
109+
--arg details_url '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
110+
--arg title 'Version PR validation' \
111+
--arg summary "$summary" \
112+
'{status: $status, conclusion: $conclusion, completed_at: $completed_at, details_url: $details_url, output: {title: $title, summary: $summary}}')"
113+
gh api repos/${{ github.repository }}/check-runs/${{ steps.version_pr_check.outputs.id }} \
114+
-X PATCH \
115+
--input - <<<"$payload"
116+
117+
- name: Fail workflow if version PR validation failed
118+
if: steps.validate_version_pr.outcome == 'failure'
119+
run: exit 1

0 commit comments

Comments
 (0)