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
5+ workflow_dispatch :
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+ default : " latest"
15+ type : choice
16+ options :
17+ - " latest"
18+ - " release"
19+ - " preview"
20+ - " build-only" # no publish, doesn't require secrets / write access
1921
2022env :
2123 PYTHON_VERSION : " 3.13"
2426 mkdocs :
2527 runs-on : ubuntu-latest
2628 steps :
29+ - name : Validate version input
30+ if : inputs.release_type == 'release' && inputs.version == ''
31+ run : |
32+ echo "ERROR: version must be set for release builds"
33+ exit 1
34+
2735 - name : Generate token
2836 id : app-token
29- if : github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push '
37+ if : inputs.release_type != 'build-only '
3038 uses : actions/create-github-app-token@v2
3139 with :
3240 app-id : ${{ secrets.PYMINE_BOT_APP_ID }}
3543 - name : Checkout repository
3644 uses : actions/checkout@v4
3745 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 .
46+ # Clone with the token generated above, as it will allow push access to the repo
47+ # If the above step was skipped , the token string will be empty, this is fine,
48+ # it will just perform an unauthenticated anonymous public clone .
4149 token : " ${{ steps.app-token.outputs.token }}"
4250 # Fetch the entire git history (all branches + tags)
4351 # We do this because the docs use git describe, which requires having all
4856 # Make the github application be the committer
4957 # (see: https://stackoverflow.com/a/74071223 on how to obtain the committer email)
5058 - name : Setup git config
51- if : github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push '
59+ if : inputs.release_type != 'build-only '
5260 run : |
5361 git config --global user.name "py-mine-ci-bot"
5462 git config --global user.email "121461646+py-mine-ci-bot[bot]@users.noreply.github.com"
@@ -63,32 +71,33 @@ jobs:
6371 cache-suffix : " docs"
6472
6573 - name : Install dependencies
66- run : |
67- uv sync --no-default-groups --group docs
74+ run : uv sync --no-default-groups --group docs
6875
69- # PRs (both 1st and 3rd party)
7076 - name : Build the documentation (mkdocs)
71- if : github.event_name == 'pull_request'
77+ # Only build with mkdocs if we won't be using mike to deploy
78+ # (since mike also performs building - it adjust the build to add versions)
79+ if : inputs.release_type == 'build-only' || inputs.release_type == 'preview'
7280 run : mkdocs build
7381
74- # 1st party PRs
82+ - name : Build & Publish release docs (mike)
83+ if : inputs.release_type == 'release'
84+ env :
85+ version : ${{ inputs.version }}
86+ run : mike deploy --update-aliases "$version" release
87+
88+ - name : Build & Publish latest docs (mike)
89+ if : inputs.release_type == 'latest'
90+ run : mike deploy latest
91+
7592 - name : Deploy docs - PR preview
76- if : >
77- github.event_name == 'pull_request' &&
78- github.event.pull_request.head.repo.full_name == github.repository
93+ if : inputs.release_type == 'preview'
7994 uses : rossjrw/pr-preview-action@v1
8095 with :
8196 source-dir : ./site
8297 preview-branch : gh-pages
8398 umbrella-dir : pr-preview
8499 token : ${{ steps.app-token.outputs.token }}
85100
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'
101+ - name : Push Documentation
102+ if : inputs.release_type == 'latest' || inputs.release_type == 'release'
94103 run : git push origin gh-pages
0 commit comments