Skip to content

Commit d759ba2

Browse files
committed
Harden developer guide workflow for forks
1 parent e026ab7 commit d759ba2

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

.github/workflows/developer-guide-docs.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,40 @@ jobs:
3232
3333
- name: Build Developer Guide HTML and PDF
3434
run: |
35-
OUTPUT_DIR="build/developer-guide"
36-
mkdir -p "$OUTPUT_DIR"
37-
asciidoctor -D "$OUTPUT_DIR" -o developer-guide.html docs/developer-guide/developer-guide.asciidoc
38-
asciidoctor-pdf -D "$OUTPUT_DIR" -o developer-guide.pdf docs/developer-guide/developer-guide.asciidoc
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 img sketch; do
47+
if [ -d "docs/developer-guide/${asset_dir}" ]; then
48+
cp -R "docs/developer-guide/${asset_dir}" "$PACKAGE_DIR/"
49+
fi
50+
done
51+
(cd "$PACKAGE_DIR" && zip -r "../developer-guide-html.zip" .)
3952
4053
- name: Upload HTML artifact
4154
uses: actions/upload-artifact@v4
4255
with:
4356
name: developer-guide-html
44-
path: build/developer-guide/developer-guide.html
57+
path: build/developer-guide/developer-guide-html.zip
4558
if-no-files-found: error
4659

4760
- name: Upload PDF artifact
4861
uses: actions/upload-artifact@v4
4962
with:
5063
name: developer-guide-pdf
51-
path: build/developer-guide/developer-guide.pdf
64+
path: build/developer-guide/pdf/developer-guide.pdf
5265
if-no-files-found: error
5366

5467
- name: Comment with artifact download links
55-
if: ${{ github.event_name == 'pull_request' }}
68+
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork }}
5669
uses: actions/github-script@v7
5770
with:
5871
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -70,7 +83,7 @@ jobs:
7083
const links = [];
7184
for (const artifact of artifacts.data.artifacts) {
7285
if (artifact.name === 'developer-guide-html') {
73-
links.push(`- [Developer Guide HTML](https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${artifact.id})`);
86+
links.push(`- [Developer Guide HTML package](https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${artifact.id})`);
7487
}
7588
if (artifact.name === 'developer-guide-pdf') {
7689
links.push(`- [Developer Guide PDF](https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${artifact.id})`);
@@ -108,10 +121,14 @@ jobs:
108121
});
109122
}
110123
124+
- name: Log skipped PR comment
125+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork }}
126+
run: echo "Skipping PR comment because the workflow run does not have permission to post on forked pull requests."
127+
111128
- name: Attach artifacts to release
112129
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
113130
uses: softprops/action-gh-release@v1
114131
with:
115132
files: |
116-
build/developer-guide/developer-guide.html
117-
build/developer-guide/developer-guide.pdf
133+
build/developer-guide/developer-guide-html.zip
134+
build/developer-guide/pdf/developer-guide.pdf

.github/workflows/pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ 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/**'
1617
- '**/*.md'
18+
- '.github/workflows/developer-guide-docs.yml'
1719

1820
permissions:
1921
contents: write

0 commit comments

Comments
 (0)