Skip to content

Commit 3229128

Browse files
committed
ci: Add GitHub Workflow to build and publish documentation
1 parent 7714c1a commit 3229128

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: Build and Publish
2+
3+
on:
4+
# Allows running this workflow manually from the Actions tab
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: "Version of Slicer documentation to build and publish"
9+
required: true
10+
11+
permissions:
12+
# Needed in the publish step to update gh-pages branch
13+
contents: write
14+
15+
jobs:
16+
build-and-publish:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Collect Inputs
20+
id: collect_inputs
21+
run: |
22+
echo "EVENT_NAME [$EVENT_NAME]"
23+
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
24+
version=${{ github.event.inputs.version }}
25+
else
26+
echo "::error ::Unsupported EVENT_NAME [$EVENT_NAME]"
27+
exit 1
28+
fi
29+
echo "version=$version" >> $GITHUB_OUTPUT
30+
env:
31+
EVENT_NAME: ${{ github.event_name }}
32+
33+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34+
with:
35+
ref: gh-pages
36+
path: gh-pages
37+
38+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
39+
with:
40+
repository: Slicer/Slicer
41+
path: Slicer
42+
ref: ${{ steps.collect_inputs.outputs.version }}
43+
44+
- uses: ssciwr/doxygen-install@527824132256e685f03ec80c0851fe79937eb1d6 # v1.6.3
45+
with:
46+
version: "1.10.0"
47+
48+
# The "dot" binary is provided by Graphviz
49+
- uses: ts-graphviz/setup-graphviz@b1de5da23ed0a6d14e0aeee8ed52fdd87af2363c # v2.0.2
50+
51+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
52+
with:
53+
repository: Slicer/slicer-apidocs-builder
54+
path: slicer-apidocs-builder
55+
ref: 1744509e91fa66186d34e4c6968ee684131c51d1
56+
57+
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
58+
with:
59+
python-version: '3.13'
60+
cache: 'pip'
61+
62+
- name: Install slicer-apidocs-builder
63+
run: |
64+
pip install ./slicer-apidocs-builder
65+
66+
- name: Generate Documentation
67+
id: generate
68+
run: |
69+
WARNING_LOG_FILE=/tmp/Slicer-Slicer-$SLICER_REPO_BRANCH-build/Utilities/Doxygen/UserDoxygenWarnings.txt
70+
slicer-apidocs-builder \
71+
--skip-publish \
72+
--slicer-repo-dir $(pwd)/Slicer \
73+
--slicer-repo-branch "$SLICER_REPO_BRANCH" \
74+
--slicer-repo-tag "${SLICER_REPO_TAG}" 2> >(tee $WARNING_LOG_FILE >&2)
75+
76+
echo "warning_log_file=$WARNING_LOG_FILE" >> $GITHUB_OUTPUT
77+
env:
78+
SLICER_REPO_BRANCH: ${{ steps.collect_inputs.outputs.version }}
79+
SLICER_REPO_TAG: ""
80+
81+
- name: Parse and annotate Doxygen warnings
82+
run: |
83+
echo "WARNING_LOG_FILE [$WARNING_LOG_FILE]"
84+
if [[ -f $WARNING_LOG_FILE ]]; then
85+
buffer=""
86+
while IFS= read -r line || [[ -n "$line" ]]; do
87+
# If a buffer exists, prepend the buffered line to this line
88+
if [[ -n "$buffer" ]]; then
89+
line="$buffer$line"
90+
buffer=""
91+
fi
92+
93+
# Extract file, line number, and warning message
94+
FILE=$(echo "$line" | grep -oP "^[^:]+" || true)
95+
LINE=$(echo "$line" | grep -oP ":(\d+):" | tr -d ":" || true)
96+
MESSAGE=$(echo "$line" | grep -oP "warning:.*" || true)
97+
98+
# If MESSAGE is found, process further
99+
if [[ -n "$MESSAGE" ]]; then
100+
MESSAGE=${MESSAGE#warning: } # Strip "warning: " prefix
101+
102+
# Aggregate all subsequent lines starting with at least a space
103+
while IFS= read -r continuation || [[ -n "$continuation" ]]; do
104+
if [[ "$continuation" =~ ^[[:space:]] ]]; then
105+
MESSAGE="${MESSAGE}%0A${continuation}"
106+
else
107+
# Buffer the line to be processed in the main loop
108+
buffer="$continuation"
109+
break
110+
fi
111+
done
112+
fi
113+
114+
# Annotate in GitHub Actions
115+
if [[ -n "$FILE" && -n "$LINE" && -n "$MESSAGE" ]]; then
116+
echo "::warning file=$FILE,line=$LINE::$MESSAGE"
117+
elif [[ -n "$MESSAGE" ]]; then
118+
echo "::warning ::$MESSAGE"
119+
else
120+
echo "Skipped unmatched line: $line"
121+
fi
122+
123+
done < "$WARNING_LOG_FILE"
124+
else
125+
echo "No Doxygen warnings log found."
126+
fi
127+
env:
128+
WARNING_LOG_FILE: ${{ steps.generate.outputs.warning_log_file }}
129+
130+
- uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
131+
id: app-token
132+
with:
133+
app-id: ${{ vars.SLICER_APP_ID }}
134+
private-key: ${{ secrets.SLICER_APP_PRIVATE_KEY }}
135+
136+
- name: Publish documentation
137+
run: |
138+
slicer-apidocs-builder \
139+
--skip-build \
140+
--slicer-repo-name ${SLICER_REPO_NAME} \
141+
--slicer-repo-branch "${SLICER_REPO_BRANCH}" \
142+
--slicer-repo-tag "${SLICER_REPO_TAG}" \
143+
--publish-github-repo-name "Slicer/${PUBLISH_GITHUB_PROJECT_NAME}" \
144+
--publish-github-repo-branch gh-pages
145+
env:
146+
PUBLISH_GITHUB_PROJECT_NAME: apidocs.slicer.org
147+
PUBLISH_GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
148+
SLICER_REPO_NAME: Slicer/Slicer
149+
SLICER_REPO_BRANCH: ${{ steps.collect_inputs.outputs.version }}
150+
SLICER_REPO_TAG: ""
151+

0 commit comments

Comments
 (0)