-
Notifications
You must be signed in to change notification settings - Fork 12
238 lines (214 loc) · 7.8 KB
/
sphinx.yml
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
name: sphinx
# **How it works**
# ================
#
# After each __commit__ on the `main` branch, the documentation is built and deployed on the `S3:dev/` directory.
# After each __release__, the documentation is built and deployed to the `S3:version/` directory, the version being
# a subpart of the tag `MAJOR.MINOR.BUGFIX`: `MAJOR.MINOR`.
#
# For instance, with the following timeline:
#
# dev/ dev/ dev/ dev/ dev/
# 0.1/ 0.2/
# main -- x -- x -- x -- x -- x -- >
# | |
# tag 0.1 0.2
#
# The S3 bucket looks like:
# .
# ├── 0.1/
# ├── 0.2/
# ├── dev/
# ├── index.html
# └── versions.json
#
# **Q&A**
# =======
#
# ### `dev/`, why?
# It contains the most up-to-date documentation, i.e. the documentation of code that is not released but committed on the main branch.
#
# ### Version the documentation on `MAJOR.MINOR, why not on `MAJOR`?
# Currently, we add new features at a minor level. This way, we can separate documentation between two features.
#
# ### Only on release (not on release-candidate), why?
# The release-candidates are documented in the `dev/` directory. We don't want to create noise with explicit directory for such tags.
#
# ### How to change an old version of the documentation?
# You can create tags wherever you want, i.e. on separate branches.
# For example, you can create a branch from an old tag (`0.1.5`), modify the documentation and create a new tag (`0.1.6`).
# The corresponding documentation will be automatically updated (`0.1`).
#
# **Side-notes**
# ==============
#
# Only the 10 latest versions are listed in sphinx version-switcher to avoid overloading, but the bucket remains unchanged.
on:
pull_request:
paths:
- '.github/actions/sphinx/**'
- '.github/workflows/sphinx.yml'
- 'examples/**'
- 'sphinx/**'
- 'skore/**'
push:
branches:
- main
paths:
- '.github/actions/sphinx/**'
- '.github/workflows/sphinx.yml'
- 'examples/**'
- 'sphinx/**'
- 'skore/**'
release:
types: [released]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
sphinx-version:
runs-on: ubuntu-latest
outputs:
SPHINX_VERSION: ${{ steps.sphinx-version.outputs.SPHINX_VERSION }}
SPHINX_RELEASE: ${{ steps.sphinx-version.outputs.SPHINX_RELEASE }}
steps:
- shell: bash
id: sphinx-version
run: |
set -u
if [[ "${GITHUB_EVENT_NAME}" != "release" ]]; then
echo "SPHINX_VERSION=dev" >> "${GITHUB_OUTPUT}"
echo "SPHINX_RELEASE=0.0.0+dev" >> "${GITHUB_OUTPUT}"
exit 0
fi
set -e
if [[ "${GITHUB_REF_NAME}" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)?$ ]]; then
echo "SPHINX_VERSION=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}" >> "${GITHUB_OUTPUT}"
echo "SPHINX_RELEASE=${GITHUB_REF_NAME}" >> "${GITHUB_OUTPUT}"
fi
sphinx-build:
runs-on: ubuntu-latest
needs: sphinx-version
steps:
- uses: actions/checkout@v4
with:
lfs: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- shell: bash
run: wget -qO- "${SKRUB_DATA_URL}" | tar -zxvf - -C "${HOME}"
env:
SKRUB_DATA_URL: https://skore.probabl.ai/f355443be646d49eab1aa76e29dfd0a8/skrub-data.tar.gz
HOME: ${{ github.workspace }}
- uses: ./.github/actions/sphinx/build
timeout-minutes: 10
with:
SPHINX_VERSION: ${{ needs.sphinx-version.outputs.SPHINX_VERSION }}
SPHINX_RELEASE: ${{ needs.sphinx-version.outputs.SPHINX_RELEASE }}
SPHINX_DOMAIN: ${{ vars.DOCUMENTATION_DOMAIN }}
env:
HOME: ${{ github.workspace }}
- uses: actions/upload-artifact@v4
with:
name: sphinx-html-artifact
path: sphinx/build/html/
sphinx-deploy-html:
if: ${{ (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
runs-on: ubuntu-latest
needs: [sphinx-version, sphinx-build]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download HTML artifacts
uses: actions/download-artifact@v4
with:
name: sphinx-html-artifact
path: html/
- name: Deploy HTML artifacts
uses: ./.github/actions/sphinx/deploy
with:
CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }}
BUCKET: ${{ vars.DOCUMENTATION_BUCKET }}
SOURCE: html/
DESTINATION: ${{ needs.sphinx-version.outputs.SPHINX_VERSION }}/
- name: Purge CDN cache
shell: bash
run: |
curl --fail-with-body \
-X POST \
-H "X-Auth-Token: ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"pipeline_id\":\"${PIPELINE_ID}\",\"all\":true}" \
"https://api.scaleway.com/edge-services/v1alpha1/purge-requests"
env:
TOKEN: ${{ secrets.SCW_SECRET_KEY }}
PIPELINE_ID: ${{ vars.DOCUMENTATION_EDGE_SERVICES_PIPELINE_ID }}
sphinx-deploy-root-files:
if: ${{ github.event_name == 'release' }}
runs-on: ubuntu-latest
needs: [sphinx-version, sphinx-build, sphinx-deploy-html]
steps:
- uses: actions/checkout@v4
- shell: python
run: |
import os
import requests
import operator
import json
version = os.environ["SPHINX_VERSION"]
release = os.environ["SPHINX_RELEASE"]
url = os.environ["SPHINX_URL"]
# Retrieve history
response = requests.get(f"{url}/versions.json")
response.raise_for_status()
history = {version["name"]: version["version"] for version in response.json()}
# Add new version to history
history[version] = release
# Sort history, and always keep "dev" at the beginning
history = sorted(
history.items(),
key=lambda item: float(item[0]) if item[0] != "dev" else float('inf'),
reverse=True
)
# Rewrite the history with "dev" and the 10 latest versions
new = [
{
"name": version,
"version": release,
"url": f"{url}/{version}/",
"preferred": i == 1,
}
for i, (version, release) in enumerate(history[:11])
]
os.mkdir("artifacts")
with open("artifacts/versions.json", "w", encoding="utf-8") as file:
json.dump(new, file, ensure_ascii=False, indent=4)
with open("artifacts/index.html", "w", encoding="utf-8") as file:
file.write(
f"""
<head>
<meta http-equiv=\"refresh\" content=\"0; url={new[1]["url"]}\"/>
</head>
"""
)
env:
SPHINX_VERSION: ${{ needs.sphinx-version.outputs.SPHINX_VERSION }}
SPHINX_RELEASE: ${{ needs.sphinx-version.outputs.SPHINX_RELEASE }}
SPHINX_URL: https://${{ vars.DOCUMENTATION_DOMAIN }}
- uses: ./.github/actions/sphinx/deploy
with:
CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }}
BUCKET: ${{ vars.DOCUMENTATION_BUCKET }}
ACTION: copy
SOURCE: artifacts/
DESTINATION:
sphinx-clean-artifacts:
runs-on: ubuntu-latest
if: ${{ always() && (github.event_name != 'pull_request') }}
needs: [sphinx-version, sphinx-build, sphinx-deploy-html, sphinx-deploy-root-files]
steps:
- uses: geekyeggo/delete-artifact@v5
with:
name: sphinx-html-artifact