Skip to content

Commit 20bd067

Browse files
authored
fix: support workflow_dispatch in commit-recordings via PR metadata artifact (#5202)
## Summary - Adds `upload-pr-metadata` job to record-integration-tests workflow that creates an artifact with PR information - Updates commit-recordings workflow to download and use this metadata artifact - Enables workflow_dispatch triggers to properly commit recordings back to PRs ## Problem When recording tests are triggered via `workflow_dispatch`, the commit-recordings companion workflow skips committing because it can't determine which PR to commit to. Example of skipped run: https://github.com/llamastack/llama-stack/actions/runs/23264433521/job/67641289839 ## Solution The record-integration-tests workflow now creates a metadata artifact containing PR information (number, branch, SHA, repo). The commit-recordings workflow downloads this artifact and uses it to determine where to commit, falling back to the original pull_request event logic if no metadata is found. ## Note After this merges, the pinned SHAs in record-integration-tests.yml will need to be updated again to point to the commit that includes this change. ## Test plan - [ ] Manual workflow_dispatch trigger should now commit recordings to the specified PR - [ ] Auto-trigger on pull_request should continue to work as before --------- Signed-off-by: Charlie Doern <cdoern@redhat.com>
1 parent 5a9b9f2 commit 20bd067

File tree

2 files changed

+102
-19
lines changed

2 files changed

+102
-19
lines changed

.github/workflows/commit-recordings.yml

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,93 @@ jobs:
5959
fi
6060
done
6161
62-
- name: Get PR information
63-
id: pr-info
62+
- name: Download PR metadata artifact
6463
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
6564
with:
6665
script: |
67-
// Get PR number from the triggering workflow
68-
const runInfo = await github.rest.actions.getWorkflowRun({
66+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
6967
owner: context.repo.owner,
7068
repo: context.repo.repo,
7169
run_id: ${{ github.event.workflow_run.id }},
7270
});
7371
72+
const metadataArtifact = artifacts.data.artifacts.find(a => a.name.startsWith('pr-metadata-'));
73+
if (metadataArtifact) {
74+
console.log(`Found PR metadata artifact: ${metadataArtifact.name}`);
75+
const download = await github.rest.actions.downloadArtifact({
76+
owner: context.repo.owner,
77+
repo: context.repo.repo,
78+
artifact_id: metadataArtifact.id,
79+
archive_format: 'zip',
80+
});
81+
82+
const fs = require('fs');
83+
fs.writeFileSync('pr-metadata.zip', Buffer.from(download.data));
84+
} else {
85+
console.log('No PR metadata artifact found');
86+
}
87+
88+
- name: Extract PR metadata
89+
run: |
90+
if [ -f pr-metadata.zip ]; then
91+
unzip -o pr-metadata.zip
92+
echo "PR metadata contents:"
93+
cat pr-info.json
94+
else
95+
echo "No PR metadata file to extract"
96+
fi
97+
98+
- name: Get PR information
99+
id: pr-info
100+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
101+
with:
102+
script: |
103+
const fs = require('fs');
74104
let prNumber = null;
75105
let headRepo = null;
76106
let headRef = null;
77107
let headSha = null;
78108
79-
// Check if this was triggered by a pull_request event
80-
if (runInfo.data.event === 'pull_request' && runInfo.data.pull_requests.length > 0) {
81-
const pr = runInfo.data.pull_requests[0];
82-
prNumber = pr.number;
109+
// Try to load from metadata artifact first
110+
if (fs.existsSync('pr-info.json')) {
111+
try {
112+
const metadata = JSON.parse(fs.readFileSync('pr-info.json', 'utf8'));
113+
prNumber = parseInt(metadata.pr_number, 10);
114+
headRepo = metadata.pr_head_repo;
115+
headRef = metadata.pr_head_ref;
116+
headSha = metadata.pr_head_sha;
117+
console.log(`Loaded PR info from metadata: PR #${prNumber}`);
118+
} catch (e) {
119+
console.log(`Failed to parse metadata: ${e.message}`);
120+
}
121+
}
83122
84-
// Fetch full PR details
85-
const prData = await github.rest.pulls.get({
123+
// Fallback: check if triggered by pull_request event
124+
if (!prNumber) {
125+
const runInfo = await github.rest.actions.getWorkflowRun({
86126
owner: context.repo.owner,
87127
repo: context.repo.repo,
88-
pull_number: prNumber,
128+
run_id: ${{ github.event.workflow_run.id }},
89129
});
90130
91-
headRepo = prData.data.head.repo.full_name;
92-
headRef = prData.data.head.ref;
93-
headSha = prData.data.head.sha;
94-
} else {
95-
// workflow_dispatch - try to extract from run name or skip
96-
console.log('Not a pull_request event, skipping commit');
97-
core.setOutput('skip', 'true');
98-
return;
131+
if (runInfo.data.event === 'pull_request' && runInfo.data.pull_requests.length > 0) {
132+
const pr = runInfo.data.pull_requests[0];
133+
prNumber = pr.number;
134+
135+
const prData = await github.rest.pulls.get({
136+
owner: context.repo.owner,
137+
repo: context.repo.repo,
138+
pull_number: prNumber,
139+
});
140+
141+
headRepo = prData.data.head.repo.full_name;
142+
headRef = prData.data.head.ref;
143+
headSha = prData.data.head.sha;
144+
} else {
145+
console.log('No PR metadata and not a pull_request event, skipping commit');
146+
core.setOutput('skip', 'true');
147+
return;
148+
}
99149
}
100150
101151
core.setOutput('pr_number', prNumber);

.github/workflows/record-integration-tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,39 @@ jobs:
140140
echo " Fork PR: ${IS_FORK_PR}"
141141
echo " Providers: ${PROVIDERS}"
142142
143+
# Upload PR metadata for companion workflow
144+
upload-pr-metadata:
145+
needs: compute-pr-info
146+
runs-on: ubuntu-latest
147+
steps:
148+
- name: Create PR metadata artifact
149+
env:
150+
# Pass via env vars to prevent code injection (same pattern as compute-pr-info step)
151+
PR_NUMBER: ${{ needs.compute-pr-info.outputs.pr_number }}
152+
PR_HEAD_REF: ${{ needs.compute-pr-info.outputs.pr_head_ref }}
153+
PR_HEAD_SHA: ${{ needs.compute-pr-info.outputs.pr_head_sha }}
154+
PR_HEAD_REPO: ${{ needs.compute-pr-info.outputs.pr_head_repo }}
155+
IS_FORK_PR: ${{ needs.compute-pr-info.outputs.is_fork_pr }}
156+
run: |
157+
mkdir -p pr-metadata
158+
cat > pr-metadata/pr-info.json <<EOF
159+
{
160+
"pr_number": "${PR_NUMBER}",
161+
"pr_head_ref": "${PR_HEAD_REF}",
162+
"pr_head_sha": "${PR_HEAD_SHA}",
163+
"pr_head_repo": "${PR_HEAD_REPO}",
164+
"is_fork_pr": "${IS_FORK_PR}"
165+
}
166+
EOF
167+
cat pr-metadata/pr-info.json
168+
169+
- name: Upload PR metadata
170+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
171+
with:
172+
name: pr-metadata-${{ github.run_id }}
173+
path: pr-metadata/
174+
retention-days: 1
175+
143176
# Record tests for each provider
144177
record-providers:
145178
needs: compute-pr-info

0 commit comments

Comments
 (0)