Skip to content

Commit db02e5c

Browse files
bakerboy448claude
andauthored
ci: DRY build into reusable workflow, drop double-run triggers, simplify pre-commit (#58)
- Extract shared MkDocs build steps into _build.yml (workflow_call) with optional upload-site input; build.yml and deploy.yml call it - Remove push: trigger from build.yml and precommit.yml to prevent duplicate CI runs when a branch PR is opened - Refactor deploy.yml into build + deploy jobs so the site artifact is built once and passed to the peaceiris publish step - Drop redundant `if: github.ref == 'refs/heads/main'` guard in deploy job - Simplify precommit.yml: drop fetch-depth, Resolve-change-range step, and --from-ref/--to-ref extra_args; run --all-files now that the backlog is clean - Fix SC2086 (unquoted $GITHUB_OUTPUT) caught by actionlint/shellcheck Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8b02f09 commit db02e5c

4 files changed

Lines changed: 61 additions & 83 deletions

File tree

.github/workflows/_build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Reusable MkDocs build — called by build.yml (PR validation) and deploy.yml (Pages publish)
2+
name: Build (reusable)
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
upload-site:
8+
description: "Upload built ./site as the 'site' artifact"
9+
type: boolean
10+
default: false
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v7
20+
- uses: actions/setup-python@v7
21+
with:
22+
python-version: "3.14"
23+
- run: python3 -m pip install --upgrade pip
24+
- id: pip-cache
25+
run: echo "dir=$(pip cache dir)" >> "$GITHUB_OUTPUT"
26+
- uses: actions/cache@v6
27+
with:
28+
path: ${{ steps.pip-cache.outputs.dir }}
29+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
30+
restore-keys: |
31+
${{ runner.os }}-pip-
32+
- run: |
33+
python3 -m pip install -r requirements.txt
34+
mkdocs build --strict
35+
- uses: actions/upload-artifact@v4
36+
if: ${{ inputs.upload-site }}
37+
with:
38+
name: site
39+
path: ./site

.github/workflows/build.yml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
1+
# Validate MkDocs builds cleanly on every PR to main
12
name: Build
23

34
on:
4-
push:
5-
branches-ignore:
6-
- main
75
pull_request:
86
branches:
97
- main
108

119
permissions:
1210
contents: read
1311

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1416
jobs:
1517
build:
16-
runs-on: ubuntu-latest
17-
concurrency:
18-
group: ${{ github.workflow }}-${{ github.ref }}
19-
cancel-in-progress: true
20-
steps:
21-
- uses: actions/checkout@v7
22-
- uses: actions/setup-python@v7
23-
with:
24-
python-version: "3.14"
25-
- run: python3 -m pip install --upgrade pip
26-
- id: pip-cache
27-
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
28-
- uses: actions/cache@v6
29-
with:
30-
path: ${{ steps.pip-cache.outputs.dir }}
31-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
32-
restore-keys: |
33-
${{ runner.os }}-pip-
34-
- run: |
35-
python3 -m pip install -r requirements.txt
36-
mkdocs build --strict
18+
uses: ./.github/workflows/_build.yml

.github/workflows/deploy.yml

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,38 @@
1+
# Build and publish MkDocs site to GitHub Pages on every push to main
12
name: GitHub Pages
23

34
on:
45
push:
56
branches:
67
- main
78

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
813
jobs:
14+
build:
15+
uses: ./.github/workflows/_build.yml
16+
with:
17+
upload-site: true
18+
919
deploy:
20+
needs: build
1021
runs-on: ubuntu-latest
1122
permissions:
1223
contents: write
13-
concurrency:
14-
group: ${{ github.workflow }}-${{ github.ref }}
15-
cancel-in-progress: true
1624
steps:
1725
- name: Clone repository
1826
uses: actions/checkout@v7
1927

20-
- name: Setup Python environment
21-
uses: actions/setup-python@v7
22-
with:
23-
python-version: "3.14"
24-
25-
- name: Upgrade pip
26-
run: python3 -m pip install --upgrade pip
27-
28-
- name: Get pip cache directory
29-
id: pip-cache
30-
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
31-
32-
- name: Cache dependencies
33-
uses: actions/cache@v6
28+
- name: Download built site
29+
uses: actions/download-artifact@v4
3430
with:
35-
path: ${{ steps.pip-cache.outputs.dir }}
36-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
37-
restore-keys: |
38-
${{ runner.os }}-pip-
39-
40-
- name: Install dependencies
41-
run: python3 -m pip install -r ./requirements.txt
42-
43-
- name: Build Docs
44-
run: mkdocs build --strict
31+
name: site
32+
path: ./site
4533

4634
- name: Deploy
4735
uses: peaceiris/actions-gh-pages@v4
48-
if: github.ref == 'refs/heads/main'
4936
with:
5037
github_token: ${{ secrets.GITHUB_TOKEN }}
5138
publish_dir: ./site

.github/workflows/precommit.yml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
# Lint all files with pre-commit on every PR to main
12
name: Pre-commit
23

34
on:
45
pull_request:
56
branches:
67
- main
7-
push:
8-
branches-ignore:
9-
- main
108

119
permissions:
1210
contents: read
@@ -20,38 +18,10 @@ jobs:
2018
runs-on: ubuntu-latest
2119
steps:
2220
- uses: actions/checkout@v7
23-
with:
24-
# Need full history so pre-commit can diff against the PR base.
25-
fetch-depth: 0
2621
- uses: actions/setup-python@v7
2722
with:
2823
python-version: "3.14"
2924
- uses: actions/setup-node@v7
3025
with:
3126
node-version: "24"
32-
# Only check files changed in the PR / push. Adding pre-commit to a
33-
# repo with existing content shouldn't fail on legacy violations —
34-
# only new/modified files get linted. Maintainers can clean up the
35-
# backlog with `pre-commit run --all-files` in follow-up sweeps.
36-
- name: Resolve change range
37-
id: range
38-
run: |
39-
if [ "${{ github.event_name }}" = "pull_request" ]; then
40-
echo "from=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
41-
echo "to=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
42-
else
43-
from="${{ github.event.before }}"
44-
# First push of a new branch reports before=0000... — fall back to HEAD~1
45-
if [ "$from" = "0000000000000000000000000000000000000000" ] || [ -z "$from" ]; then
46-
from=$(git rev-parse HEAD~1 2>/dev/null || echo "")
47-
fi
48-
# If branch has only one commit, lint just the HEAD commit
49-
if [ -z "$from" ]; then
50-
from="${{ github.sha }}"
51-
fi
52-
echo "from=$from" >> "$GITHUB_OUTPUT"
53-
echo "to=${{ github.sha }}" >> "$GITHUB_OUTPUT"
54-
fi
5527
- uses: pre-commit/action@v3.0.1
56-
with:
57-
extra_args: --from-ref ${{ steps.range.outputs.from }} --to-ref ${{ steps.range.outputs.to }}

0 commit comments

Comments
 (0)