Skip to content

Commit 9131d23

Browse files
Refactor GitHub Actions workflow for MkDocs deployment
1 parent 9ca0d2e commit 9131d23

1 file changed

Lines changed: 48 additions & 5 deletions

File tree

.github/workflows/deploy_mkdocs.yml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
name: Publish docs via GitHub Pages
2-
1+
name: Deploy MkDocs
32
on:
43
push:
54
branches:
@@ -12,6 +11,11 @@ on:
1211
- 'docs/**'
1312
- '.github/workflows/deploy_mkdocs.yml'
1413

14+
permissions:
15+
contents: write
16+
pages: write
17+
id-token: write
18+
1519
jobs:
1620
build:
1721
name: Deploy docs
@@ -28,8 +32,47 @@ jobs:
2832
- name: Install dependencies
2933
run: |
3034
python -m pip install --upgrade pip
31-
python -m pip install .["docs"]
35+
pip install -e .[docs]
36+
37+
- name: Configure Git
38+
run: |
39+
git config --global user.name "GitHub Actions"
40+
git config --global user.email "github-actions@users.noreply.github.com"
41+
42+
- name: Checkout gh-pages branch
43+
run: |
44+
git fetch origin gh-pages:gh-pages || git checkout --orphan gh-pages
45+
git checkout gh-pages
46+
git reset --hard # Clean working directory
3247
48+
- name: Save existing content
49+
run: |
50+
mkdir -p temp
51+
# Save important files/directories that should be preserved
52+
# Copy all the vx.x.x folders to preserve them
53+
for dir in $(find . -maxdepth 1 -type d -name 'vx.*'); do
54+
if [ -d "$dir" ]; then
55+
cp -r "$dir" temp/
56+
fi
57+
done
3358
34-
- name: Deploy docs
35-
run: mkdocs gh-deploy --force -f mkdocs.yml
59+
- name: Build documentation
60+
run: |
61+
git checkout main
62+
mkdocs build
63+
64+
- name: Deploy documentation
65+
run: |
66+
git checkout gh-pages
67+
# Remove all content except .git and temp directory
68+
find . -mindepth 1 -maxdepth 1 ! -name '.git' ! -name 'temp' -exec rm -rf {} +
69+
# Copy MkDocs output
70+
cp -r site/* .
71+
# Restore preserved content
72+
cp -r temp/* .
73+
# Clean up
74+
rm -rf site temp
75+
# Commit and push
76+
git add -A
77+
git commit -m "Deploy documentation updates" || echo "No changes to commit"
78+
git push origin gh-pages --force

0 commit comments

Comments
 (0)