Skip to content

Commit c46cf4e

Browse files
authored
Add developer guide documentation build workflow (#3997)
1 parent cbc49ad commit c46cf4e

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Build Developer Guide Docs
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'docs/developer-guide/**'
7+
- '.github/workflows/developer-guide-docs.yml'
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
issues: write
18+
pull-requests: write
19+
actions: read
20+
steps:
21+
- name: Check out repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Ruby
25+
uses: ruby/setup-ruby@v1
26+
with:
27+
ruby-version: '3.1'
28+
29+
- name: Install Asciidoctor tooling
30+
run: |
31+
gem install --no-document asciidoctor asciidoctor-pdf
32+
33+
- name: Build Developer Guide HTML and PDF
34+
run: |
35+
set -euo pipefail
36+
OUTPUT_ROOT="build/developer-guide"
37+
HTML_BUILD_DIR="${OUTPUT_ROOT}/html"
38+
PDF_BUILD_DIR="${OUTPUT_ROOT}/pdf"
39+
PACKAGE_DIR="${OUTPUT_ROOT}/html-package"
40+
mkdir -p "$HTML_BUILD_DIR" "$PDF_BUILD_DIR"
41+
asciidoctor -D "$HTML_BUILD_DIR" -o developer-guide.html docs/developer-guide/developer-guide.asciidoc
42+
asciidoctor-pdf -D "$PDF_BUILD_DIR" -o developer-guide.pdf docs/developer-guide/developer-guide.asciidoc
43+
rm -rf "$PACKAGE_DIR"
44+
mkdir -p "$PACKAGE_DIR"
45+
cp "$HTML_BUILD_DIR/developer-guide.html" "$PACKAGE_DIR/"
46+
for asset_dir in docs/developer-guide/*; do
47+
base_name="$(basename "$asset_dir")"
48+
if [ -d "$asset_dir" ] && [ "$base_name" != "sketch" ]; then
49+
cp -R "$asset_dir" "$PACKAGE_DIR/"
50+
fi
51+
done
52+
(cd "$PACKAGE_DIR" && zip -r "../developer-guide-html.zip" .)
53+
54+
- name: Upload HTML artifact
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: developer-guide-html
58+
path: build/developer-guide/developer-guide-html.zip
59+
if-no-files-found: error
60+
61+
- name: Upload PDF artifact
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: developer-guide-pdf
65+
path: build/developer-guide/pdf/developer-guide.pdf
66+
if-no-files-found: error
67+
68+
- name: Comment with artifact download links
69+
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork }}
70+
uses: actions/github-script@v7
71+
with:
72+
github-token: ${{ secrets.GITHUB_TOKEN }}
73+
script: |
74+
const marker = '<!-- developer-guide-artifacts -->';
75+
const { owner, repo } = context.repo;
76+
const runId = context.runId;
77+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
78+
owner,
79+
repo,
80+
run_id: runId,
81+
per_page: 100
82+
});
83+
84+
const links = [];
85+
for (const artifact of artifacts.data.artifacts) {
86+
if (artifact.name === 'developer-guide-html') {
87+
links.push(`- [Developer Guide HTML package](https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${artifact.id})`);
88+
}
89+
if (artifact.name === 'developer-guide-pdf') {
90+
links.push(`- [Developer Guide PDF](https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${artifact.id})`);
91+
}
92+
}
93+
94+
if (!links.length) {
95+
console.log('No artifacts found to report.');
96+
return;
97+
}
98+
99+
const body = `${marker}\nDeveloper Guide build artifacts are available for download from this workflow run:\n\n${links.join('\n')}\n`;
100+
const comments = await github.rest.issues.listComments({
101+
owner,
102+
repo,
103+
issue_number: context.issue.number,
104+
per_page: 100
105+
});
106+
107+
const existing = comments.data.find(comment => comment.body && comment.body.includes(marker));
108+
109+
if (existing) {
110+
await github.rest.issues.updateComment({
111+
owner,
112+
repo,
113+
comment_id: existing.id,
114+
body
115+
});
116+
} else {
117+
await github.rest.issues.createComment({
118+
owner,
119+
repo,
120+
issue_number: context.issue.number,
121+
body
122+
});
123+
}
124+
125+
- name: Log skipped PR comment
126+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork }}
127+
run: echo "Skipping PR comment because the workflow run does not have permission to post on forked pull requests."
128+
129+
- name: Attach artifacts to release
130+
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
131+
uses: softprops/action-gh-release@v1
132+
with:
133+
files: |
134+
build/developer-guide/developer-guide-html.zip
135+
build/developer-guide/pdf/developer-guide.pdf

.github/workflows/pr.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ on:
88
- 'scripts/**'
99
- 'docs/**'
1010
- '**/*.md'
11+
- '.github/workflows/developer-guide-docs.yml'
1112
push:
1213
branches:
1314
- master
1415
paths-ignore:
1516
- 'scripts/**'
17+
- 'docs/**'
1618
- '**/*.md'
19+
- '.github/workflows/developer-guide-docs.yml'
1720

1821
permissions:
1922
contents: write

0 commit comments

Comments
 (0)