forked from Eatham532/Software-Engineering-HSC-Textbook
-
Notifications
You must be signed in to change notification settings - Fork 0
434 lines (389 loc) Β· 15.2 KB
/
deploy.yml
File metadata and controls
434 lines (389 loc) Β· 15.2 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
name: Deploy Docs
on:
# push:
# branches:
# - master
# - main
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type (manual only)'
required: false
default: 'patch'
type: choice
options:
- patch
- minor
- major
- none
skip_deploy:
description: 'Skip deployment (manual only)'
required: false
default: false
type: boolean
skip_indexnow:
description: 'Skip IndexNow notification (manual only)'
required: false
default: false
type: boolean
skip_release:
description: 'Skip creating release (manual only)'
required: false
default: false
type: boolean
custom_version:
description: 'Custom version (if bump=none, manual only)'
required: false
type: string
# Cancel in-progress runs when new commit is pushed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
deploy:
name: π Deploy to GitHub Pages
runs-on: ubuntu-latest
container:
image: python:3.13
if: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.skip_deploy != 'true') || (github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip deploy]')) }}
services:
kroki:
image: yuzutech/kroki
env:
KROKI_MERMAID_HOST: mermaid
KROKI_BPMN_HOST: bpmn
KROKI_EXCALIDRAW_HOST: excalidraw
ports:
- 8000:8000
mermaid:
image: yuzutech/kroki-mermaid
bpmn:
image: yuzutech/kroki-bpmn
excalidraw:
image: yuzutech/kroki-excalidraw
steps:
- name: π₯ Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for git-revision-date plugin
token: ${{ secrets.GITHUB_TOKEN }}
sparse-checkout: |
docs
includes
overrides
scripts
extensions
macros
pyproject.toml
mkdocs.yml
- name: π Mark repository safe for git
shell: bash
run: |
# Allow git operations inside the runner workspace
git config --global --add safe.directory "${{ github.workspace }}"
git config --global --add safe.directory "$(pwd)"
echo "β
Git safe directories configured"
- name: π€ Configure git user
shell: bash
run: |
git config --global user.email "78714349+Eatham532@users.noreply.github.com"
git config --global user.name "Eatham532"
echo "β
Git user configured as Eatham532"
- name: π§ Setup Python environment
shell: bash
run: |
set -euo pipefail
python --version
python -m pip install --upgrade pip setuptools wheel build
- name: π¦ Install dependencies
shell: bash
run: |
set -euo pipefail
python -m pip install -e . || python -m pip install .
- name: π οΈ Install zip utility
shell: bash
run: |
apt-get update && apt-get install -y zip
- name: π¦ Build site for release
env:
KROKI_SERVER_URL: http://kroki:8000
shell: bash
run: |
set -euo pipefail
if ! command -v mkdocs >/dev/null 2>&1; then
echo "β ERROR: mkdocs not found on PATH"
exit 1
fi
echo "π¦ Building site..."
mkdocs build --clean
echo "β
Build complete!"
- name: π¦ Create site archive
shell: bash
run: |
cd site
zip -r ../site-build.zip .
cd ..
echo "β
Site archive created"
- name: π€ Upload site artifact
uses: actions/upload-artifact@v4
with:
name: site-build
path: site-build.zip
retention-days: 1
- name: π Deploy to GitHub Pages
env:
KROKI_SERVER_URL: http://kroki:8000
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
echo "π Deploying to GitHub Pages..."
mkdocs gh-deploy --force --clean --remote-name origin
echo "β
Deployment complete!"
notify-indexnow:
name: π Notify Search Engines
runs-on: ubuntu-latest
needs: [deploy, create-release] # Only run after deployment and release creation succeed
if: success() && ((github.event_name == 'workflow_dispatch' && github.event.inputs.skip_indexnow != 'true') || (github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip indexnow]')))
steps:
- name: π₯ Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history to compare with gh-pages branch
ref: ${{ github.ref }} # Checkout the branch that triggered the workflow
- name: π§ Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: π¦ Install requests library
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install requests
- name: π Notify IndexNow of changes
shell: bash
run: |
echo "π Notifying search engines of changed pages..."
python scripts/indexnow_notify.py
continue-on-error: true # Don't fail workflow if IndexNow has issues
create-release:
name: π¦ Create GitHub Release
runs-on: ubuntu-latest
needs: deploy # Run after deployment succeeds
if: success() && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip deploy]')))
permissions:
contents: write
steps:
- name: π₯ Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for release notes
token: ${{ secrets.GITHUB_TOKEN }}
- name: π§ Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: π Get current version
if: github.event_name == 'push' || github.event.inputs.skip_release != 'true'
id: get_version
shell: bash
run: |
current_version=$(python scripts/bump_version.py show)
echo "current_version=${current_version}" >> $GITHUB_OUTPUT
echo "π Current version: ${current_version}"
- name: πΌ Determine new version
if: github.event_name == 'push' || github.event.inputs.skip_release != 'true'
id: bump_version
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Manual trigger - use configured options
bump_type="${{ github.event.inputs.version_bump }}"
if [ "$bump_type" = "none" ]; then
if [ -n "${{ github.event.inputs.custom_version }}" ]; then
# Custom version - set it
version_change=$(python scripts/bump_version.py set "${{ github.event.inputs.custom_version }}")
new_version=$(echo "$version_change" | cut -d' ' -f3)
echo "π Set custom version: ${version_change}"
else
# No bump, no custom - use current version, don't update file
new_version="${{ steps.get_version.outputs.current_version }}"
echo "π Using current version (no file update): ${new_version}"
fi
else
# Bump the version
version_change=$(python scripts/bump_version.py "$bump_type")
new_version=$(echo "$version_change" | cut -d' ' -f3)
echo "β
Version bumped: ${version_change}"
fi
else
# Push trigger - auto bump patch
version_change=$(python scripts/bump_version.py patch)
new_version=$(echo "$version_change" | cut -d' ' -f3)
echo "β
Auto-bumped patch version: ${version_change}"
fi
echo "new_version=${new_version}" >> $GITHUB_OUTPUT
echo "should_commit=${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && (github.event.inputs.version_bump != 'none' || github.event.inputs.custom_version != '')) }}" >> $GITHUB_OUTPUT
- name: πΎ Commit version bump
if: steps.bump_version.outputs.should_commit == 'true' && (github.event_name == 'push' || github.event.inputs.skip_release != 'true')
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore: bump version to ${{ steps.bump_version.outputs.new_version }}"
git push origin main
echo "β
Version committed and pushed"
- name: π₯ Download site artifact
if: github.event_name == 'push' || github.event.inputs.skip_release != 'true'
uses: actions/download-artifact@v4
with:
name: site-build
- name: π Generate release notes
if: github.event_name == 'push' || github.event.inputs.skip_release != 'true'
id: release_notes
shell: bash
run: |
# Get the previous tag (if exists)
previous_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$previous_tag" ]; then
echo "π First release - including all commits"
commit_range="HEAD"
else
echo "π Generating release notes since ${previous_tag}"
commit_range="${previous_tag}..HEAD"
fi
# Get all commits (exclude version bumps and skip deploy)
commits=$(git log ${commit_range} --pretty=format:"%s|||%h" --no-merges | grep -v "\[skip deploy\]" | grep -v "^chore: bump version to" || true)
# Initialize category arrays
declare -a features=()
declare -a fixes=()
declare -a refactors=()
declare -a docs=()
declare -a styles=()
declare -a tests=()
declare -a chores=()
declare -a other=()
# Categorize commits based on conventional commit format
while IFS='|||' read -r message hash; do
# Extract type from conventional commit format (type: message or type(scope): message)
if [[ "$message" =~ ^([a-z]+)(\([^)]+\))?: ]]; then
type="${BASH_REMATCH[1]}"
case "$type" in
feat|feature)
features+=("- $message ($hash)")
;;
fix|bugfix)
fixes+=("- $message ($hash)")
;;
refactor|refact)
refactors+=("- $message ($hash)")
;;
docs|doc)
docs+=("- $message ($hash)")
;;
style|styles)
styles+=("- $message ($hash)")
;;
test|tests)
tests+=("- $message ($hash)")
;;
chore|build|ci)
chores+=("- $message ($hash)")
;;
*)
other+=("- $message ($hash)")
;;
esac
else
# No conventional commit format - categorize as other
other+=("- $message ($hash)")
fi
done <<< "$commits"
# Generate release notes with categories
echo "## π Changes" > release_notes.md
echo "" >> release_notes.md
# Add features
if [[ "${#features[@]}" -gt 0 ]]; then
echo "### β¨ Features" >> release_notes.md
echo "" >> release_notes.md
printf '%s\n' "${features[@]}" >> release_notes.md
echo "" >> release_notes.md
fi
# Add fixes
if [[ "${#fixes[@]}" -gt 0 ]]; then
echo "### π Bug Fixes" >> release_notes.md
echo "" >> release_notes.md
printf '%s\n' "${fixes[@]}" >> release_notes.md
echo "" >> release_notes.md
fi
# Add refactors
if [[ "${#refactors[@]}" -gt 0 ]]; then
echo "### β»οΈ Refactors" >> release_notes.md
echo "" >> release_notes.md
printf '%s\n' "${refactors[@]}" >> release_notes.md
echo "" >> release_notes.md
fi
# Add documentation
if [[ "${#docs[@]}" -gt 0 ]]; then
echo "### π Documentation" >> release_notes.md
echo "" >> release_notes.md
printf '%s\n' "${docs[@]}" >> release_notes.md
echo "" >> release_notes.md
fi
# Add styles
if [[ "${#styles[@]}" -gt 0 ]]; then
echo "### π Styles" >> release_notes.md
echo "" >> release_notes.md
printf '%s\n' "${styles[@]}" >> release_notes.md
echo "" >> release_notes.md
fi
# Add tests
if [[ "${#tests[@]}" -gt 0 ]]; then
echo "### π§ͺ Tests" >> release_notes.md
echo "" >> release_notes.md
printf '%s\n' "${tests[@]}" >> release_notes.md
echo "" >> release_notes.md
fi
# Add chores
if [[ "${#chores[@]}" -gt 0 ]]; then
echo "### π§ Chores" >> release_notes.md
echo "" >> release_notes.md
printf '%s\n' "${chores[@]}" >> release_notes.md
echo "" >> release_notes.md
fi
# Add other/uncategorized
if [[ "${#other[@]}" -gt 0 ]]; then
echo "### π¦ Other Changes" >> release_notes.md
echo "" >> release_notes.md
printf '%s\n' "${other[@]}" >> release_notes.md
echo "" >> release_notes.md
fi
# Get contributors since last tag
if [ -n "$previous_tag" ]; then
contributors=$(git log ${commit_range} --format='%an' | grep -v "github-actions\[bot\]" | sort -u)
if [ -n "$contributors" ]; then
echo "## π₯ Contributors" >> release_notes.md
echo "" >> release_notes.md
echo "$contributors" | while read contributor; do
echo "- $contributor" >> release_notes.md
done
fi
fi
echo "β
Release notes generated"
cat release_notes.md
- name: π·οΈ Create Release
if: github.event_name == 'push' || github.event.inputs.skip_release != 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.bump_version.outputs.new_version }}
name: Release v${{ steps.bump_version.outputs.new_version }}
body_path: release_notes.md
files: |
site-build.zip
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}