-
Notifications
You must be signed in to change notification settings - Fork 5
165 lines (137 loc) · 5.1 KB
/
docs.yaml
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
name: Docs
on:
push:
branches:
- 'release/*'
pull_request:
branches:
- main
- 'release/*'
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 }}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
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.11
uses: actions/setup-python@v4
with:
python-version: 3.11
- 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 `sdr` 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@v3
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
steps:
- uses: actions/checkout@v3
with:
ref: gh-pages
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: docs
- 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.startswith("refs/heads/release/"):
name = "v" + github_ref.split("refs/heads/release/")[1]
print("name 1:", name)
elif github_event_name == "push" and github_ref.startswith("refs/tags/"):
name = github_ref.split("refs/tags/")[1]
print("name 2:", name)
elif github_event_name == "workflow_dispatch":
name = workflow_dispatch_tag
print("name 3:", name)
else:
print("name 4:")
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: |
from distutils.version import StrictVersion
import json
import pathlib
import os
# Determine the version folders
cwd = pathlib.Path.cwd()
versions = sorted((item.name for item in cwd.iterdir() if item.is_dir() and not item.name.startswith(".")), reverse=True)
print(versions)
# Remove "latest" from list of versions
versions.remove("latest")
os.system("rm latest")
# Sort versions, ignoring the initial 'v'
def sort_version(version):
if "x" in version:
version = version.replace("x", "1000")
return StrictVersion(version[1:])
versions = sorted(versions, key=sort_version, reverse=True)
list_of_dicts = []
latest = None
for version in versions:
title = version
aliases = []
if "x" in version:
title += " (pre-release)"
elif latest is None:
latest = version
aliases = ["latest"]
os.system(f"ln -s {version} latest")
list_of_dicts.append({"version": version, "title": title, "aliases": aliases})
print(list_of_dicts)
with (cwd / "versions.json").open("w") as f:
json.dump(list_of_dicts, f, indent=4)
- run: git status
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Deploy ${{ github.sha }}