-
Notifications
You must be signed in to change notification settings - Fork 2
149 lines (127 loc) · 4.52 KB
/
Copy pathdocs-pages.yml
File metadata and controls
149 lines (127 loc) · 4.52 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
145
146
147
148
149
name: Docs (GitHub Pages) CI
on:
push:
branches: [documentation, dev, main]
tags: ['v*']
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: docs-pages-${{ github.ref }}
cancel-in-progress: true
jobs:
# Gate: for tag pushes, skip the whole pipeline if the commit is not on main.
# Branch pushes always pass through.
gate:
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.check.outputs.should_build }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check whether docs should build
id: check
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
git fetch origin main
TAG_COMMIT="$(git rev-list -n 1 "${{ github.ref }}")"
IS_ON_MAIN=$(git merge-base --is-ancestor "${TAG_COMMIT}" origin/main \
&& echo "true" || echo "false")
echo "should_build=${IS_ON_MAIN}" >> $GITHUB_OUTPUT
echo "Tag on main: ${IS_ON_MAIN}"
else
echo "should_build=true" >> $GITHUB_OUTPUT
fi
build:
needs: gate
if: ${{ needs.gate.outputs.should_build == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install docs dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r docs/requirements.txt
python -m pip install numpy pandas tqdm PyYAML
- name: Build Sphinx multiversion docs
run: sphinx-multiversion docs docs/_build/html
- name: Prepare latest alias and versions manifest
shell: bash
run: |
python - <<'PY'
import json
import re
import shutil
from pathlib import Path
root = Path("docs/_build/html")
main_dir = root / "main"
latest_dir = root / "latest"
if main_dir.exists():
shutil.copytree(main_dir, latest_dir, dirs_exist_ok=True)
versions = []
semver = re.compile(r"^v(\d+)\.(\d+)\.(\d+)$")
for d in root.iterdir():
if not d.is_dir() or not (d / "index.html").exists():
continue
name = d.name
if name not in {"latest", "documentation", "dev"} and not semver.match(name):
continue
if name == "latest":
rank = (0, 0, 0, 0)
label = "latest"
elif name == "dev":
rank = (1, 0, 0, 0)
label = "dev"
elif name == "documentation":
rank = (2, 0, 0, 0)
label = "documentation"
else:
m = semver.match(name)
rank = (3, -int(m.group(1)), -int(m.group(2)), -int(m.group(3)))
label = name
versions.append({"name": name, "label": label, "rank": rank})
versions.sort(key=lambda v: v["rank"])
payload = [{"name": v["name"], "label": v["label"]} for v in versions]
(root / "versions.json").write_text(json.dumps(payload, indent=2), encoding="utf-8")
for v in payload:
(root / v["name"] / "versions.json").write_text(json.dumps(payload, indent=2), encoding="utf-8")
if payload:
default_name = payload[0]["name"]
redirect = f"""<!doctype html>
<html><head>
<meta charset=\"utf-8\" />
<meta http-equiv=\"refresh\" content=\"0; url=./{default_name}/index.html\" />
<title>WeightsLab Docs</title>
</head><body>
Redirecting to <a href=\"./{default_name}/index.html\">{default_name}</a>.
</body></html>
"""
(root / "index.html").write_text(redirect, encoding="utf-8")
PY
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/_build/html
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: [gate, build]
if: ${{ needs.gate.outputs.should_build == 'true' }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4