Skip to content

Commit 3b1ef08

Browse files
steve-downeyclaude
andcommitted
Rewrite docs.yml: build on all pushes/PRs, artifact upload, PR comment
Previous workflow only triggered on pushes to main, ran npx antora directly without MRDOCS_ROOT (causing the extension to re-download MrDocs), and used a hardcoded wrong output path. Changes: - Trigger on all pushes and all PRs so every branch and PR gets a docs build, not just main. - Use `make docs` throughout: it sets MRDOCS_ROOT correctly, handles npm ci, and auto-detects the clang compiler. - Cache .tools/mrdocs (keyed on install script hash) and node_modules (keyed on package-lock.json hash) to speed up repeated runs. - Capture the output path with `make -s print-docs-out` so the artifact upload and gh-pages deploy always use the right directory. - Upload the built site as a docs-site artifact (14-day retention) on every run so any branch build is downloadable for inspection. - Post a PR comment with a link to the workflow run and instructions for downloading and opening the artifact. The comment is updated (not duplicated) on subsequent pushes to the same PR. continue-on-error so fork PRs without write permission don't fail CI. - Keep the GitHub Pages deploy step for pushes to main. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 4bef0e2 commit 3b1ef08

1 file changed

Lines changed: 83 additions & 21 deletions

File tree

.github/workflows/docs.yml

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,117 @@
1+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
13
name: Documentation
24

35
on:
46
push:
5-
branches:
6-
- main
77
pull_request:
8-
branches:
9-
- main
8+
workflow_dispatch:
109

1110
permissions:
1211
contents: read
1312

1413
jobs:
1514
build:
15+
name: Build
1616
runs-on: ubuntu-latest
1717
permissions:
18-
contents: write
18+
contents: write # needed for gh-pages deploy on main
19+
pull-requests: write # needed to post the preview comment on PRs
20+
1921
steps:
2022
- name: Harden the runner (Audit all outbound calls)
2123
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
2224
with:
2325
egress-policy: audit
2426

2527
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
fetch-depth: 1
2630

27-
- name: Install Clang and CMake
31+
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
32+
with:
33+
node-version: '20'
34+
35+
- name: Install Clang
2836
run: |
2937
sudo apt-get update -qq
30-
sudo apt-get install -y clang-18 libclang-18-dev cmake
38+
sudo apt-get install -y clang-18 libclang-18-dev
3139
32-
- name: Install MrDocs
33-
run: |
34-
curl -L \
35-
"https://github.com/cppalliance/mrdocs/releases/latest/download/MrDocs-amd64-linux-clang-Release.tar.gz" \
36-
| tar xz -C /usr/local --strip-components=1
40+
- name: Cache MrDocs
41+
uses: actions/cache@v4
42+
with:
43+
path: .tools/mrdocs
44+
key: mrdocs-${{ runner.os }}-${{ hashFiles('etc/install-mrdocs.sh') }}
3745

38-
- name: Set up Node.js
39-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
46+
- name: Cache node_modules
47+
uses: actions/cache@v4
4048
with:
41-
node-version: '20'
49+
path: node_modules
50+
key: npm-${{ hashFiles('package-lock.json') }}
51+
52+
- name: Build documentation
53+
run: make docs
54+
55+
- name: Locate output directory
56+
id: out
57+
run: echo "dir=$(make -s print-docs-out)" >> "$GITHUB_OUTPUT"
4258

43-
- name: Install npm dependencies
44-
run: npm ci
59+
- name: Upload docs artifact
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: docs-site
63+
path: ${{ steps.out.outputs.dir }}/
64+
retention-days: 14
65+
66+
# Posts a comment on the PR with a direct link to the workflow run
67+
# where the docs-site artifact can be downloaded and inspected.
68+
# Uses a hidden marker so the comment is updated (not duplicated) on
69+
# each push to the PR branch.
70+
# continue-on-error because fork PRs may lack write permission for
71+
# pull-requests; the build still passes even if the comment fails.
72+
- name: Post or update PR preview comment
73+
if: github.event_name == 'pull_request'
74+
continue-on-error: true
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
const MARKER = '<!-- docs-preview-comment -->'
79+
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
80+
const sha = context.payload.pull_request.head.sha.slice(0, 7)
81+
const body = [
82+
MARKER,
83+
`📚 **Documentation preview** for \`${sha}\` — [workflow run](${runUrl})`,
84+
'',
85+
'To review: open the **docs-site** artifact from that run,',
86+
'extract the zip, and open `index.html` in a browser.',
87+
].join('\n')
4588
46-
- name: Build documentation site
47-
run: npx antora antora-playbook.yml
89+
const { data: comments } = await github.rest.issues.listComments({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
issue_number: context.issue.number,
93+
})
94+
const existing = comments.find(c => c.body.includes(MARKER))
95+
if (existing) {
96+
await github.rest.issues.updateComment({
97+
owner: context.repo.owner,
98+
repo: context.repo.repo,
99+
comment_id: existing.id,
100+
body,
101+
})
102+
} else {
103+
await github.rest.issues.createComment({
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
issue_number: context.issue.number,
107+
body,
108+
})
109+
}
48110
49111
- name: Deploy to GitHub Pages
50-
if: github.ref == 'refs/heads/main'
112+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
51113
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d231e62369c1b9a4d # v4.0.0
52114
with:
53115
github_token: ${{ secrets.GITHUB_TOKEN }}
54-
publish_dir: ./build/site
116+
publish_dir: ${{ steps.out.outputs.dir }}
55117
publish_branch: gh-pages

0 commit comments

Comments
 (0)