-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (124 loc) · 5.15 KB
/
Copy pathdocs.yml
File metadata and controls
144 lines (124 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Documentation
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
pull-requests: write
# Prevent concurrent deploys from corrupting gh-pages
concurrency:
group: docs-deploy
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
enable-cache: true
- name: Setup Python
run: uv python install 3.12
- name: Cache apt packages
uses: awalsh128/cache-apt-pkgs-action@553a35bb8ebd9fcabcb1c9451aa4c98e1b4ca8a9 # v1.6.3
with:
packages: libvtk9-dev qtbase5-dev qt5-qmake libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev
version: 1.0
- name: Install dependencies
run: uv sync --group docs
- name: Configure Git for mike
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# One-time migration: wipe legacy gh-pages from mkdocs gh-deploy
# so mike starts with a clean branch (safe no-op once versions.json exists)
- name: Clean up legacy gh-pages
if: github.event_name == 'push'
run: |
git fetch origin gh-pages:refs/remotes/origin/gh-pages 2>/dev/null || true
if git show origin/gh-pages:versions.json &>/dev/null 2>&1; then
echo "mike already initialized, skipping cleanup"
else
echo "First mike deploy — wiping legacy gh-pages for clean start"
git push origin --delete gh-pages 2>/dev/null || true
fi
# Deploy PR preview (not shown in version selector)
- name: Deploy PR preview
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
run: uv run mike deploy "pr-${{ github.event.pull_request.number }}" --push
# Tokens for pull requests from forks are read-only. Build the docs without
# publishing a preview so external contributions are still validated.
- name: Build fork PR documentation
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name != github.repository
run: uv run mkdocs build
- name: Comment PR preview link
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v9
with:
script: |
const previewUrl = `https://kmarchais.github.io/mmgpy/pr-${{ github.event.pull_request.number }}/`;
const marker = '<!-- docs-preview -->';
const body = `${marker}\n:book: **Docs preview**: ${previewUrl}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c =>
c.user.type === 'Bot' && c.body.includes(marker)
);
if (!existing) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
# Clean up previews for closed/merged PRs
- name: Clean up stale PR previews
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git fetch origin gh-pages:refs/remotes/origin/gh-pages 2>/dev/null || true
VERSIONS=$(git show origin/gh-pages:versions.json 2>/dev/null || echo "[]")
echo "$VERSIONS" | python3 -c "
import json, subprocess, sys
versions = json.load(sys.stdin)
for v in versions:
name = v['version']
if not name.startswith('pr-'):
continue
pr_num = name[3:]
result = subprocess.run(
['gh', 'pr', 'view', pr_num, '--json', 'state', '--jq', '.state'],
capture_output=True, text=True,
)
state = result.stdout.strip()
if state in ('CLOSED', 'MERGED'):
print(f'Deleting preview for {name} (PR is {state})')
subprocess.run(['uv', 'run', 'mike', 'delete', name, '--push'])
else:
print(f'Keeping {name} (PR is {state})')
"
# "dev" always reflects the current main branch.
# Versioned release deploys live in build-wheels.yml so they're gated on
# a successful PyPI upload (we never publish docs for a release whose
# wheel never shipped).
- name: Deploy dev docs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: uv run mike deploy dev --push