Skip to content

Commit 3f883fb

Browse files
committed
Make docs workflow dispatchable
1 parent 5b2b45a commit 3f883fb

File tree

3 files changed

+75
-88
lines changed

3 files changed

+75
-88
lines changed

.github/workflows/docs.yml

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,45 @@
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
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
2022
env:
2123
PYTHON_VERSION: "3.13"
2224

2325
jobs:
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 }}
@@ -35,9 +49,9 @@ jobs:
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
@@ -48,7 +62,7 @@ jobs:
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

.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)