22name : MkDocs
33
44on :
5- push :
6- branches :
7- - main
8- pull_request :
9-
10- concurrency :
11- group : ${{ github.workflow }}-${{ github.ref }}
12- cancel-in-progress : true
13-
14- permissions :
15- # The requested write permissions will only be followed on 1st party triggers
16- # on 3rd party PRs (from forks), github will drop these permissions to read.
17- contents : write
18- pull-requests : write
19-
5+ workflow_call :
6+ inputs :
7+ version :
8+ description : " Project version (for releases)"
9+ required : false
10+ type : string
11+ release_type :
12+ description : " Type of release"
13+ required : true
14+ type : string
15+ default : " latest"
16+ # The choice type isn't available for workflow_call, but we
17+ # generally expect the following values here:
18+ # - "latest"
19+ # - "release"
20+ # - "preview"
21+ # - "build-only" # no publish, doesn't require secrets / write access
2022env :
2123 PYTHON_VERSION : " 3.13"
2224
2325jobs :
2426 mkdocs :
2527 runs-on : ubuntu-latest
2628 steps :
29+ - name : Validate relese type input
30+ if : inputs.release_type != 'latest' && inputs.release_type != 'release' && inputs.release_type != 'preview' && inputs.release_type != 'build-only'
31+ run : |
32+ echo "ERROR: release_type must be one of: 'latest', 'release', 'preview' or 'build-only'"
33+ exit 1
34+
35+ - name : Validate version input
36+ if : inputs.release_type == 'release' && inputs.version == ''
37+ run : |
38+ echo "ERROR: version must be set for release builds"
39+ exit 1
40+
2741 - name : Generate token
2842 id : app-token
29- if : github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push '
43+ if : inputs.release_type != 'build-only '
3044 uses : actions/create-github-app-token@v2
3145 with :
3246 app-id : ${{ secrets.PYMINE_BOT_APP_ID }}
3549 - name : Checkout repository
3650 uses : actions/checkout@v4
3751 with :
38- # We should get a token that allows us to push to the repo when the workflow ran
39- # as 1st party (not from a forked PR). From 3rd parties , the token will be an
40- # empty string (as the token generation step was skipped), so pushing won't work .
52+ # Clone with the token generated above, as it will allow push access to the repo
53+ # If the above step was skipped , the token string will be empty, this is fine,
54+ # it will just perform an unauthenticated anonymous public clone .
4155 token : " ${{ steps.app-token.outputs.token }}"
4256 # Fetch the entire git history (all branches + tags)
4357 # We do this because the docs use git describe, which requires having all
4862 # Make the github application be the committer
4963 # (see: https://stackoverflow.com/a/74071223 on how to obtain the committer email)
5064 - name : Setup git config
51- if : github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push '
65+ if : inputs.release_type != 'build-only '
5266 run : |
5367 git config --global user.name "py-mine-ci-bot"
5468 git config --global user.email "121461646+py-mine-ci-bot[bot]@users.noreply.github.com"
@@ -63,32 +77,33 @@ jobs:
6377 cache-suffix : " docs"
6478
6579 - name : Install dependencies
66- run : |
67- uv sync --no-default-groups --group docs
80+ run : uv sync --no-default-groups --group docs
6881
69- # PRs (both 1st and 3rd party)
7082 - name : Build the documentation (mkdocs)
71- if : github.event_name == 'pull_request'
83+ # Only build with mkdocs if we won't be using mike to deploy
84+ # (since mike also performs building - it adjust the build to add versions)
85+ if : inputs.release_type == 'build-only' || inputs.release_type == 'preview'
7286 run : mkdocs build
7387
74- # 1st party PRs
88+ - name : Build & Publish release docs (mike)
89+ if : inputs.release_type == 'release'
90+ env :
91+ version : ${{ inputs.version }}
92+ run : mike deploy --update-aliases "$version" release
93+
94+ - name : Build & Publish latest docs (mike)
95+ if : inputs.release_type == 'latest'
96+ run : mike deploy latest
97+
7598 - name : Deploy docs - PR preview
76- if : >
77- github.event_name == 'pull_request' &&
78- github.event.pull_request.head.repo.full_name == github.repository
99+ if : inputs.release_type == 'preview'
79100 uses : rossjrw/pr-preview-action@v1
80101 with :
81102 source-dir : ./site
82103 preview-branch : gh-pages
83104 umbrella-dir : pr-preview
84105 token : ${{ steps.app-token.outputs.token }}
85106
86- # Push to main (1st party)
87- - name : Build the documentation (mike)
88- if : github.event_name == 'push'
89- run : mike deploy latest
90-
91- # Push to main (1st party)
92- - name : Deploy docs - latest
93- if : github.event_name == 'push'
107+ - name : Push Documentation
108+ if : inputs.release_type == 'latest' || inputs.release_type == 'release'
94109 run : git push origin gh-pages
0 commit comments