Skip to content

Commit b017ef5

Browse files
authored
fix: Wait for build result before opening submodule update PRs
1 parent fdbc1b2 commit b017ef5

File tree

2 files changed

+67
-102
lines changed

2 files changed

+67
-102
lines changed

.github/workflows/update-pr-build-status.yaml

Lines changed: 0 additions & 80 deletions
This file was deleted.

.github/workflows/update-submodule.yaml

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,64 @@ jobs:
142142
git commit -m "chore: update ${{ matrix.provider.name }} docs to ${{ steps.check.outputs.short_sha }}"
143143
git push origin "${{ steps.check.outputs.branch_name }}"
144144
145+
- name: Trigger test build and wait for result
146+
if: steps.check.outputs.needs_update == 'true'
147+
id: build
148+
uses: actions/github-script@v7
149+
with:
150+
script: |
151+
const branchName = '${{ steps.check.outputs.branch_name }}';
152+
153+
// github-actions[bot] PRs do not trigger pull_request events —
154+
// GitHub suppresses them to prevent infinite loops. We dispatch
155+
// the build manually and wait for it to finish before opening the
156+
// PR, so the PR body already shows the final build status.
157+
await github.rest.actions.createWorkflowDispatch({
158+
owner: context.repo.owner,
159+
repo: context.repo.repo,
160+
workflow_id: 'test-build.yaml',
161+
ref: branchName,
162+
inputs: { ref: branchName }
163+
});
164+
165+
// Give GitHub 10s to register the run before we start polling.
166+
await new Promise(resolve => setTimeout(resolve, 10000));
167+
168+
// Poll every 20s, up to 30 attempts (10 min total).
169+
// A typical Docusaurus build finishes in ~2-3 min.
170+
let conclusion = null;
171+
let runUrl = null;
172+
173+
for (let attempt = 0; attempt < 30; attempt++) {
174+
const { data: runs } = await github.rest.actions.listWorkflowRuns({
175+
owner: context.repo.owner,
176+
repo: context.repo.repo,
177+
workflow_id: 'test-build.yaml',
178+
branch: branchName,
179+
event: 'workflow_dispatch',
180+
per_page: 5
181+
});
182+
183+
const run = runs.workflow_runs.find(r => r.status === 'completed' || r.status === 'in_progress' || r.status === 'queued');
184+
if (run && run.status === 'completed') {
185+
conclusion = run.conclusion;
186+
runUrl = run.html_url;
187+
console.log(`Build completed: ${conclusion} — ${runUrl}`);
188+
break;
189+
}
190+
191+
console.log(`Attempt ${attempt + 1}/30: status=${run?.status ?? 'not found'}, waiting 20s...`);
192+
await new Promise(resolve => setTimeout(resolve, 20000));
193+
}
194+
195+
if (!conclusion) {
196+
// Timed out after 10 min — open the PR anyway with unknown status.
197+
conclusion = 'unknown';
198+
}
199+
200+
core.setOutput('conclusion', conclusion);
201+
core.setOutput('run_url', runUrl ?? '');
202+
145203
- name: Open pull request
146204
if: steps.check.outputs.needs_update == 'true'
147205
id: open_pr
@@ -154,6 +212,14 @@ jobs:
154212
const shortSha = '${{ steps.check.outputs.short_sha }}';
155213
const branchName = '${{ steps.check.outputs.branch_name }}';
156214
const docFiles = `${{ steps.check.outputs.doc_files }}`;
215+
const conclusion = '${{ steps.build.outputs.conclusion }}';
216+
const runUrl = '${{ steps.build.outputs.run_url }}';
217+
218+
const statusIcon = conclusion === 'success' ? '✅ passed'
219+
: conclusion === 'failure' ? '❌ failed'
220+
: `⚠️ ${conclusion}`;
221+
222+
const runLink = runUrl ? `[View run](${runUrl})` : '—';
157223
158224
const { data: pr } = await github.rest.pulls.create({
159225
owner: context.repo.owner,
@@ -171,31 +237,10 @@ jobs:
171237
``,
172238
`| Test | Status | Run |`,
173239
`| ---- | ------ | --- |`,
174-
`| Docusaurus build | ⏳ pending | — |`,
175-
``,
176-
`> The build test is triggered automatically and will update this table when complete.`
240+
`| Docusaurus build | ${statusIcon} | ${runLink} |`,
177241
].join('\n'),
178242
head: branchName,
179243
base: 'main',
180244
draft: false
181245
});
182246
core.setOutput('pr_number', pr.number);
183-
184-
- name: Trigger test build for new PR
185-
if: steps.check.outputs.needs_update == 'true'
186-
uses: actions/github-script@v7
187-
with:
188-
script: |
189-
// Trigger test-build.yaml via workflow_dispatch on the new branch.
190-
// Note: github-actions[bot] PRs do not trigger pull_request events
191-
// (GitHub suppresses them to prevent infinite loops), so we must
192-
// dispatch the build manually. The result is written back to the PR
193-
// body by the update-pr-build-status.yaml workflow, which listens
194-
// for this workflow_dispatch run to complete via workflow_run.
195-
await github.rest.actions.createWorkflowDispatch({
196-
owner: context.repo.owner,
197-
repo: context.repo.repo,
198-
workflow_id: 'test-build.yaml',
199-
ref: '${{ steps.check.outputs.branch_name }}',
200-
inputs: { ref: '${{ steps.check.outputs.branch_name }}' }
201-
});

0 commit comments

Comments
 (0)