Skip to content

Commit 537b162

Browse files
[CI] Dispatch circt-tests via workflow_run, support fork PRs (#10453)
PRs from forks of CIRCT currently cannot trigger a circt-tests run, since repository secrets are not available in the CI of those PRs. To fix this, split the dispatch into a separate workflow triggered by `workflow_run`, which always runs in the context of the upstream repository and therefore has access to the secret regardless of where the PR originated. The build workflow only uploads a small metadata artifact with the PR number. The remaining dispatch parameters come straight off the `workflow_run` event payload. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ef6d818 commit 537b162

2 files changed

Lines changed: 84 additions & 29 deletions

File tree

.github/workflows/buildAndTest.yml

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -230,35 +230,27 @@ jobs:
230230

231231
# --- end of build-circt job.
232232

233-
# Dispatch a test run in circt/circt-tests once the entire build matrix has
234-
# succeeded.
235-
dispatch-circt-tests:
236-
name: Dispatch circt-tests
237-
needs: build-and-test
233+
# Upload metadata about the triggering event so the companion
234+
# `dispatchCirctTests.yml` workflow can pick it up. That workflow runs on
235+
# `workflow_run`, which executes in the context of this repository and
236+
# therefore has access to `CIRCT_TESTS_DISPATCH_TOKEN` even for PRs opened
237+
# from forks (regular `pull_request` runs from forks do not).
238+
#
239+
# We deliberately do not depend on `build-and-test` here: the dispatcher
240+
# gates on `workflow_run.conclusion == 'success'`, which already reflects
241+
# whether the build matrix passed.
242+
upload-dispatch-metadata:
243+
name: Upload Dispatch Metadata
238244
runs-on: ubuntu-latest
239-
env:
240-
GH_TOKEN: ${{ secrets.CIRCT_TESTS_DISPATCH_TOKEN }}
241245
steps:
242-
- name: Dispatch circt-tests
243-
if: env.GH_TOKEN != ''
246+
- name: Write PR number
244247
run: |
245-
if [ "${{ github.event_name }}" = "push" ]; then
246-
KIND=main
247-
SHA=main
248-
REPO="${{ github.repository }}"
249-
PR_NUMBER=""
250-
elif [ "${{ github.event_name }}" = "pull_request" ]; then
251-
KIND=pr
252-
SHA="${{ github.event.pull_request.head.ref }}"
253-
REPO="${{ github.event.pull_request.head.repo.full_name }}"
254-
PR_NUMBER="${{ github.event.pull_request.number }}"
255-
else
256-
echo "Unhandled event type: ${{ github.event_name }}, skipping."
257-
exit 0
258-
fi
259-
DISPATCH_ARGS="-f kind=$KIND -f sha=$SHA -f repo=$REPO"
260-
if [ -n "$PR_NUMBER" ]; then
261-
DISPATCH_ARGS="$DISPATCH_ARGS -f pr_number=$PR_NUMBER"
262-
fi
263-
echo "Dispatching circt-tests with args: $DISPATCH_ARGS"
264-
gh workflow run test.yml --repo circt/circt-tests $DISPATCH_ARGS
248+
mkdir -p dispatch-metadata
249+
echo "${{ github.event.pull_request.number }}" \
250+
> dispatch-metadata/pr_number
251+
- name: Upload artifact
252+
uses: actions/upload-artifact@v4
253+
with:
254+
name: dispatch-metadata
255+
path: dispatch-metadata/
256+
retention-days: 1
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Dispatch circt-tests
2+
3+
# Trigger a test run in circt/circt-tests once a "Build and Test" run has
4+
# finished. We use `workflow_run` rather than driving the dispatch directly
5+
# from `buildAndTest.yml` because `pull_request` events from forks run with a
6+
# read-only token and no access to repository secrets. `workflow_run`, by
7+
# contrast, executes in the context of this repository and has the
8+
# `CIRCT_TESTS_DISPATCH_TOKEN` available regardless of where the PR
9+
# originated.
10+
on:
11+
workflow_run:
12+
workflows: ["Build and Test"]
13+
types: [completed]
14+
15+
jobs:
16+
dispatch:
17+
name: Dispatch circt-tests
18+
# Only dispatch when the upstream build matrix actually succeeded.
19+
if: github.event.workflow_run.conclusion == 'success'
20+
runs-on: ubuntu-latest
21+
env:
22+
GH_TOKEN: ${{ secrets.CIRCT_TESTS_DISPATCH_TOKEN }}
23+
steps:
24+
# Pull the small metadata artifact uploaded by buildAndTest.yml. It
25+
# contains only the PR number (when applicable); everything else we
26+
# need is already on the `workflow_run` event payload.
27+
- name: Download dispatch metadata
28+
if: env.GH_TOKEN != ''
29+
uses: actions/download-artifact@v4
30+
with:
31+
name: dispatch-metadata
32+
path: dispatch-metadata
33+
github-token: ${{ secrets.GITHUB_TOKEN }}
34+
run-id: ${{ github.event.workflow_run.id }}
35+
36+
- name: Dispatch circt-tests
37+
if: env.GH_TOKEN != ''
38+
env:
39+
EVENT_NAME: ${{ github.event.workflow_run.event }}
40+
HEAD_REF: ${{ github.event.workflow_run.head_branch }}
41+
HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
42+
BASE_REPO: ${{ github.repository }}
43+
run: |
44+
if [ "$EVENT_NAME" = "push" ]; then
45+
KIND=main
46+
SHA=main
47+
REPO="$BASE_REPO"
48+
PR_NUMBER=""
49+
elif [ "$EVENT_NAME" = "pull_request" ]; then
50+
KIND=pr
51+
SHA="$HEAD_REF"
52+
REPO="$HEAD_REPO"
53+
PR_NUMBER=$(cat dispatch-metadata/pr_number)
54+
else
55+
echo "Unhandled event type: $EVENT_NAME, skipping."
56+
exit 0
57+
fi
58+
DISPATCH_ARGS="-f kind=$KIND -f sha=$SHA -f repo=$REPO"
59+
if [ -n "$PR_NUMBER" ]; then
60+
DISPATCH_ARGS="$DISPATCH_ARGS -f pr_number=$PR_NUMBER"
61+
fi
62+
echo "Dispatching circt-tests with args: $DISPATCH_ARGS"
63+
gh workflow run test.yml --repo circt/circt-tests $DISPATCH_ARGS

0 commit comments

Comments
 (0)