Skip to content

Commit 2d364cc

Browse files
committed
Make docs workflow dispatchable
1 parent 5b2b45a commit 2d364cc

File tree

3 files changed

+68
-87
lines changed

3 files changed

+68
-87
lines changed

.github/workflows/docs.yml

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
name: MkDocs
33

44
on:
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

2022
env:
2123
PYTHON_VERSION: "3.13"
@@ -24,9 +26,15 @@ jobs:
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 }}
@@ -35,9 +43,9 @@ jobs:
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
@@ -48,7 +56,7 @@ jobs:
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

.github/workflows/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ jobs:
2020
unit-tests:
2121
uses: ./.github/workflows/unit-tests.yml
2222

23+
mkdocs:
24+
uses: ./.github/workflows/docs.yml
25+
with:
26+
# On a push to main: "latest"
27+
# On a 1st party (non-fork) PR: "preview" (needs secrets access)
28+
# On a 3rd party (fork) PR: "build-only"
29+
# On a manual dispatch on main branch ref: "latest"
30+
# On a manual dispatch on another ref: "build-only"
31+
release_type: ${{
32+
github.event_name == 'push' && github.ref_name == 'main' && 'latest' ||
33+
github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name == github.repository && 'preview' || 'build-only') ||
34+
github.event_name == 'workflow_dispatch' && (github.ref_name == 'main' && 'latest' || 'build-only') ||
35+
'build-only'
36+
}}
37+
secrets: inherit
38+
2339
# Produce a pull request payload artifact with various data about the
2440
# pull-request event (such as the PR number, title, author, ...).
2541
# This data is then be picked up by status-embed.yml action.

.github/workflows/publish.yml

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -206,55 +206,11 @@ jobs:
206206
publish-docs:
207207
name: "Publish release docs"
208208
if: needs.build.outputs.tagged_release == 'true' # only publish release docs on tagged releases
209-
needs: build
210-
runs-on: ubuntu-latest
211-
environment: release # requires approval
212-
permissions:
213-
contents: write
214-
215-
steps:
216-
- name: Generate token
217-
id: app-token
218-
uses: actions/create-github-app-token@v2
219-
with:
220-
app-id: ${{ secrets.PYMINE_BOT_APP_ID }}
221-
private-key: ${{ secrets.PYMINE_BOT_PRIVATE_KEY }}
222-
223-
- name: Checkout repository
224-
uses: actions/checkout@v4
225-
with:
226-
token: "${{ steps.app-token.outputs.token }}"
227-
# Fetch the entire git history (all branches + tags)
228-
# We do this because the docs use git describe, which requires having all
229-
# the commits up to the latest version tag.
230-
# We also need the gh-pages branch to push the docs to.
231-
fetch-depth: 0
232-
233-
# Make the github application be the committer
234-
# (see: https://stackoverflow.com/a/74071223 on how to obtain the committer email)
235-
- name: Setup git config
236-
run: |
237-
git config --global user.name "py-mine-ci-bot"
238-
git config --global user.email "121461646+py-mine-ci-bot[bot]@users.noreply.github.com"
239-
240-
- name: Setup uv
241-
uses: astral-sh/setup-uv@v6
242-
with:
243-
version: "latest"
244-
python-version: ${{ env.PYTHON_VERSION }}
245-
activate-environment: true
246-
enable-cache: true
247-
cache-suffix: "docs" # matches mkdocs.yml suffix
248-
249-
- name: Install dependencies
250-
run: |
251-
uv sync --no-default-groups --group docs
252-
253-
- name: Build the documentation (mike)
254-
env:
255-
version: ${{ needs.build.outputs.version }}
256-
run: |
257-
mike deploy --update-aliases "$version" release
258-
259-
- name: Deploy docs - release
260-
run: git push origin gh-pages
209+
# To prevent unapproved runs (outside of the release github environment), this job depends
210+
# on the publish-pypi job succeeding. This works around not being able to specify environment: release
211+
# for this job (since it's a dispatch job)
212+
needs: publish-pypi
213+
uses: ./.github/workflows/mkdocs.yml
214+
with:
215+
release_type: release
216+
version: ${{ needs.build.outputs.version }}

0 commit comments

Comments
 (0)