1- name : Build Mkdocs Site
1+ name : Build and Deploy MkDocs
22on :
33 push :
44 branches :
55 - dev
66 - main
77
8+ permissions :
9+ contents : write
10+
811jobs :
9- docker :
10- name : Build Mkdocs site
12+ deploy :
1113 runs-on : ubuntu-latest
1214 steps :
13- - name : Checkout code
15+ - name : Checkout Code
1416 uses : actions/checkout@v4
1517 with :
16- fetch-depth : 0
17-
18- - name : Set up Docker Buildx
19- uses : docker/setup-buildx-action@v3
18+ fetch-depth : 0
2019
21- - name : Build local docker image
22- uses : docker/build-push-action@v2
20+ - name : Setup Python
21+ uses : actions/setup-python@v5
2322 with :
24- context : .
25- load : true
26- tags : app:latest
23+ python-version : ' 3.10'
24+ cache : ' pip'
2725
28- - name : Run mkdocs build via docker
29- uses : addnab/docker-run-action@v3
30- with :
31- image : app:latest
32- options : --rm -v ${{ github.workspace }}:/docs
33- run : |
34- git config --global --add safe.directory /docs
35- mkdocs build
36-
37- - name : Deploy to site/staging (from dev)
38- if : endsWith(github.ref, '/dev')
26+ - name : Install dependencies
3927 run : |
40- git config user.name "Github Actions Bot"
41- git config user.email "<>"
42- sudo chown -R $USER:$USER site
43- git fetch origin site/staging
44- git switch site/staging
45- rm -rf ./*
46- cp -r site/* .
47- rm -rf site
48- git add .
49- git commit -m "Deploy dev build to staging"
50- git push origin site/staging
28+ python -m pip install --upgrade pip
29+ pip install mkdocs mkdocs-material
30+ pip install -r requirements.txt
5131
52- - name : Deploy to site/production (from main)
53- if : endsWith(github.ref, '/main')
54- run : |
55- git config user.name "Github Actions Bot"
56- git config user.email "<>"
57- sudo chown -R $USER:$USER site
58- git fetch origin site/production
59- git switch site/production
60- rm -rf ./*
61- cp -r site/* .
62- rm -rf site
63- git add .
64- git commit -m "Deploy main build to production"
65- git push origin site/production
32+ - name : Build MkDocs
33+ run : mkdocs build
34+
35+ - name : Deploy to Staging (from dev)
36+ if : github.ref == 'refs/heads/dev'
37+ uses : peaceiris/actions-gh-pages@v4
38+ with :
39+ github_token : ${{ secrets.GITHUB_TOKEN }}
40+ publish_dir : ./site
41+ publish_branch : site/staging
42+ commit_message : " Deploy dev build to staging"
43+
44+ - name : Deploy to Production (from main)
45+ if : github.ref == 'refs/heads/main'
46+ uses : peaceiris/actions-gh-pages@v4
47+ with :
48+ github_token : ${{ secrets.GITHUB_TOKEN }}
49+ publish_dir : ./site
50+ publish_branch : site/production
51+ commit_message : " Deploy main build to production"
0 commit comments