-
Notifications
You must be signed in to change notification settings - Fork 41
188 lines (152 loc) · 5.68 KB
/
docs.yaml
File metadata and controls
188 lines (152 loc) · 5.68 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
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
name: Docs
on:
push:
branches: [develop]
pull_request:
branches: [main, develop]
workflow_call:
workflow_dispatch:
inputs:
tag:
description: The version's tag of the docs to build
required: true
type: string
env:
WORKFLOW_DISPATCH_TAG: ${{ github.event.inputs.tag }}
permissions:
contents: read
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref }}
# NOTE: Fake ternary operator, see https://github.com/actions/runner/issues/409
fetch-depth: 0 # Fetch all commits and tags, needed for intermediate versions
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
cache-dependency-path: |
docs/requirements.txt
pyproject.toml
- name: Upgrade pip
run: python3 -m pip install --upgrade pip
- name: Install the documentation dependencies
run: python3 -m pip install -r docs/requirements.txt
- name: Install the `galois` package
run: python3 -m pip install .
- name: Run Sphinx to build docs
run: sphinx-build -b dirhtml -v docs/ docs/build/
# Tarring is needed because upload-artifact does not preserve case sensitivity
- name: Tar files
run: tar -czvf docs.tar.gz -C docs/build/ .
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: docs
path: docs.tar.gz
retention-days: 30
publish:
name: Publish
needs: build
# Only publish new docs to GitHub pages if on a pre-release branch or tagged released version
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_call' || github.event_name == 'workflow_dispatch'}}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: docs
path: .
- name: Determine folder name
id: folder
shell: python
run: |
import os
import re
github_ref = os.environ.get('GITHUB_REF')
print("github_ref:", github_ref)
github_event_name = os.environ.get("GITHUB_EVENT_NAME")
print("github_event_name:", github_event_name)
workflow_dispatch_tag = os.environ.get("WORKFLOW_DISPATCH_TAG")
print("workflow_dispatch_tag:", workflow_dispatch_tag)
if github_event_name == "push" and github_ref == "refs/heads/develop":
name = "dev"
elif github_event_name == "push" and github_ref.startswith("refs/tags/"):
name = github_ref.split("refs/tags/")[1]
elif github_event_name == "workflow_dispatch":
name = workflow_dispatch_tag
else:
raise RuntimeError
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"name={name}")
- name: Clear old version folder
run: |
rm -rf ${{ steps.folder.outputs.name }}
mkdir ${{ steps.folder.outputs.name }}
# Un-tarring is needed because upload-artifact does not preserve case sensitivity
- name: Untar files
run: tar -xzvf docs.tar.gz -C ${{ steps.folder.outputs.name }}
- name: Remove artifacts
run: rm docs.tar.gz
- name: Update versions.json file
shell: python
run: |
import json
import os
import pathlib
import re
from packaging.version import Version, InvalidVersion
cwd = pathlib.Path.cwd()
# Gather top-level folders (ignore dotfolders)
folders = [p.name for p in cwd.iterdir() if p.is_dir() and not p.name.startswith(".")]
print("folders:", folders)
# Remove "latest" symlink if present (we will recreate it)
if "latest" in folders:
folders.remove("latest")
os.system("rm -f latest")
# Identify release folders like v0.4.9, v1.2.3, v0.5.0rc1, etc.
# Keep it simple: must start with 'v' and be parseable by packaging.version
releases = []
others = []
for name in folders:
if name.startswith("v"):
try:
Version(name[1:]) # strip leading 'v'
releases.append(name)
except InvalidVersion:
others.append(name)
else:
others.append(name)
# Sort releases newest -> oldest
releases.sort(key=lambda s: Version(s[1:]), reverse=True)
# Build versions.json entries
list_of_dicts = []
# Optionally include "dev" first (if present)
if "dev" in others:
list_of_dicts.append({"version": "dev", "title": "dev", "aliases": []})
latest = None
for v in releases:
aliases = []
if latest is None:
latest = v
aliases = ["latest"]
os.system(f"ln -s {v} latest")
list_of_dicts.append({"version": v, "title": v, "aliases": aliases})
print("versions.json:", list_of_dicts)
with (cwd / "versions.json").open("w") as f:
json.dump(list_of_dicts, f, indent=4)
- run: git status
- run: git diff --stat
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Deploy ${{ github.sha }}