-
Notifications
You must be signed in to change notification settings - Fork 0
205 lines (179 loc) Β· 8.06 KB
/
Copy pathdocs.yml
File metadata and controls
205 lines (179 loc) Β· 8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: π Documentation
on:
push:
branches:
- main
- develop
paths:
- 'docs/**'
- 'policy_inspector/**'
- 'pyproject.toml'
- '.github/workflows/docs.yml'
pull_request:
branches:
- main
paths:
- 'docs/**'
- 'policy_inspector/**'
- 'pyproject.toml'
workflow_dispatch: # Allow manual triggering
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build documentation
build:
runs-on: ubuntu-latest
outputs:
build_status: ${{ steps.build-docs.outputs.build_status }}
html_files: ${{ steps.build-docs.outputs.html_files }}
asset_files: ${{ steps.build-docs.outputs.asset_files }}
image_files: ${{ steps.build-docs.outputs.image_files }}
warning_count: ${{ steps.build-docs.outputs.warning_count }}
steps:
- name: π Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for version info
- name: π Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: π¦ Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: π Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: π Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --with docs
- name: π§ Configure Sphinx
run: |
echo "Building documentation for commit: ${{ github.sha }}"
echo "Branch: ${{ github.ref_name }}"
echo "## π Documentation Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "π **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "πΏ **Branch**: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "π **Python Version**: $(python --version)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: ποΈ Build documentation
id: build-docs
run: |
cd docs
# Start build section in summary
echo "## π Documentation Build" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Build with detailed output and capture both stdout and stderr
if poetry run sphinx-build -b html source build/html 2>&1 | tee build.log; then
echo "β
**Build Status**: Success" >> $GITHUB_STEP_SUMMARY
echo "build_status=success" >> $GITHUB_OUTPUT
else
echo "β **Build Status**: Failed" >> $GITHUB_STEP_SUMMARY
echo "build_status=failed" >> $GITHUB_OUTPUT
# Add error details to summary
echo "" >> $GITHUB_STEP_SUMMARY
echo "### β Build Errors" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
tail -20 build.log >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
fi
# Add .nojekyll file to prevent GitHub Pages from processing with Jekyll
touch build/html/.nojekyll
# Generate build statistics
file_count=$(find build/html -name "*.html" | wc -l)
asset_count=$(find build/html -name "*.css" -o -name "*.js" | wc -l)
image_count=$(find build/html -name "*.png" -o -name "*.jpg" -o -name "*.svg" | wc -l)
total_size=$(du -sh build/html | cut -f1)
echo "" >> $GITHUB_STEP_SUMMARY
echo "### π Build Statistics" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY
echo "|--------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| π HTML files | $file_count |" >> $GITHUB_STEP_SUMMARY
echo "| π¨ CSS/JS assets | $asset_count |" >> $GITHUB_STEP_SUMMARY
echo "| πΌοΈ Images | $image_count |" >> $GITHUB_STEP_SUMMARY
echo "| π¦ Total size | $total_size |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Save statistics as outputs
echo "html_files=$file_count" >> $GITHUB_OUTPUT
echo "asset_files=$asset_count" >> $GITHUB_OUTPUT
echo "image_files=$image_count" >> $GITHUB_OUTPUT
# Check for warnings (but don't fail on them)
if grep -i "warning" build.log > /dev/null; then
warning_count=$(grep -c -i "warning" build.log)
echo "β οΈ **Warnings**: $warning_count found" >> $GITHUB_STEP_SUMMARY
echo "warning_count=$warning_count" >> $GITHUB_OUTPUT
else
echo "β
**Warnings**: None" >> $GITHUB_STEP_SUMMARY
echo "warning_count=0" >> $GITHUB_OUTPUT
fi
- name: οΏ½ Setup Pages
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: actions/configure-pages@v4
- name: π€ Upload documentation artifact
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: actions/upload-pages-artifact@v3
with:
path: docs/build/html
- name: π Upload build artifacts for review
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: documentation-preview
path: docs/build/html
retention-days: 7
- name: π Generate final summary
run: |
echo "" >> $GITHUB_STEP_SUMMARY
echo "## π― Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Summary table
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| ποΈ Build | ${{ steps.build-docs.outputs.build_status == 'success' && 'β
Success' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.ref }}" == "refs/heads/main" ] && [ "${{ github.event_name }}" == "push" ]; then
echo "π **Next Step**: Documentation will be deployed to GitHub Pages" >> $GITHUB_STEP_SUMMARY
elif [ "${{ github.event_name }}" == "pull_request" ]; then
echo "π **Next Step**: Download preview artifact to review changes" >> $GITHUB_STEP_SUMMARY
fi
# Deploy to GitHub Pages
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: π Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: π’ Deployment summary
run: |
echo "## π Deployment Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "β
**Deployment Status**: Success" >> $GITHUB_STEP_SUMMARY
echo "π **Live URL**: ${{ steps.deployment.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### π Build Results" >> $GITHUB_STEP_SUMMARY
echo "- π HTML files generated: ${{ needs.build.outputs.html_files }}" >> $GITHUB_STEP_SUMMARY
echo "- π¨ Assets: ${{ needs.build.outputs.asset_files }}" >> $GITHUB_STEP_SUMMARY
echo "- πΌοΈ Images: ${{ needs.build.outputs.image_files }}" >> $GITHUB_STEP_SUMMARY
echo "- β οΈ Warnings: ${{ needs.build.outputs.warning_count }}" >> $GITHUB_STEP_SUMMARY