Skip to content
Merged
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
80 changes: 80 additions & 0 deletions .github/workflows/update-pr-build-status.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Update PR build status

# Triggered when a "Test build" workflow run completes.
#
# Why a separate workflow instead of polling in update-submodule.yaml:
# The test build is dispatched via workflow_dispatch and can take several
# minutes. Polling from within update-submodule.yaml would block the job
# and waste runner time. Using workflow_run here lets GitHub notify us
# exactly when the build finishes — no sleep, no polling.
#
# Why the job condition below:
# This workflow fires for EVERY completed "Test build" run, including those
# triggered by human PRs via pull_request. We only want to update the PR body
# for bot-created submodule update PRs. Those are identified by:
# 1. The triggering event being workflow_dispatch (not pull_request)
# 2. The branch name starting with "chore/update-" (set by update-submodule.yaml)

on:
workflow_run:
workflows: ["Test build"]
types: [completed]

jobs:
update-pr-body:
name: Update PR body with build result
runs-on: ubuntu-latest
permissions:
pull-requests: write

# Only run for test builds triggered by the bot's workflow_dispatch on
# a submodule update branch — not for human PRs via pull_request.
if: >
github.event.workflow_run.event == 'workflow_dispatch' &&
startsWith(github.event.workflow_run.head_branch, 'chore/update-')

steps:
- name: Update PR body with build result
uses: actions/github-script@v7
with:
script: |
const run = context.payload.workflow_run;
const branchName = run.head_branch;
const runUrl = run.html_url;
const conclusion = run.conclusion;

// Map the workflow conclusion to a human-readable status icon
const statusIcon = conclusion === 'success' ? '✅ passed'
: conclusion === 'failure' ? '❌ failed'
: `⚠️ ${conclusion}`;

// Find the open PR for this branch
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:${branchName}`
});

if (prs.length === 0) {
console.log(`No open PR found for branch ${branchName}, skipping.`);
return;
}

const pr = prs[0];

// Replace the pending placeholder row in the test results table
// with the actual result and a direct link to the run.
const updatedBody = pr.body.replace(
/\| Docusaurus build \| .*? \| .*? \|/,
`| Docusaurus build | ${statusIcon} | [View run](${runUrl}) |`
);

await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
body: updatedBody
});

console.log(`Updated PR #${pr.number} with build result: ${conclusion}`);
18 changes: 16 additions & 2 deletions .github/workflows/update-submodule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ jobs:

- name: Open pull request
if: steps.check.outputs.needs_update == 'true'
id: open_pr
uses: actions/github-script@v7
with:
script: |
Expand All @@ -154,7 +155,7 @@ jobs:
const branchName = '${{ steps.check.outputs.branch_name }}';
const docFiles = `${{ steps.check.outputs.doc_files }}`;

await github.rest.pulls.create({
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `chore: update ${provider} docs to ${shortSha}`,
Expand All @@ -166,18 +167,31 @@ jobs:
`**Changed doc files:**`,
docFiles.split('\n').map(f => `- \`${f}\``).join('\n'),
``,
`Please review the documentation changes before merging.`
`## Test results`,
``,
`| Test | Status | Run |`,
`| ---- | ------ | --- |`,
`| Docusaurus build | ⏳ pending | — |`,
``,
`> The build test is triggered automatically and will update this table when complete.`
].join('\n'),
head: branchName,
base: 'main',
draft: false
});
core.setOutput('pr_number', pr.number);

- name: Trigger test build for new PR
if: steps.check.outputs.needs_update == 'true'
uses: actions/github-script@v7
with:
script: |
// Trigger test-build.yaml via workflow_dispatch on the new branch.
// Note: github-actions[bot] PRs do not trigger pull_request events
// (GitHub suppresses them to prevent infinite loops), so we must
// dispatch the build manually. The result is written back to the PR
// body by the update-pr-build-status.yaml workflow, which listens
// for this workflow_dispatch run to complete via workflow_run.
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
Loading