-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (155 loc) · 5.54 KB
/
Copy pathdocs.yml
File metadata and controls
190 lines (155 loc) · 5.54 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
189
190
name: Docs
on:
push:
branches:
- develop
paths:
- 'docs/**'
- 'mkdocs.yml'
- '.github/workflows/docs.yml'
release:
types:
- published
workflow_dispatch:
inputs:
docs_version:
description: 'Docs version to publish, e.g. 1.1.0. Leave blank to publish develop.'
required: false
type: string
source_ref:
description: 'Git ref to build from. Defaults to docs_version prefixed with v when available.'
required: false
type: string
update_latest:
description: 'Also move latest alias/default redirect to this version. Ignored when docs_version is blank.'
required: false
default: false
type: boolean
permissions:
contents: read
concurrency:
group: docs-gh-pages
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Resolve docs metadata
id: docs
shell: bash
env:
INPUT_DOCS_VERSION: ${{ github.event.inputs.docs_version }}
INPUT_SOURCE_REF: ${{ github.event.inputs.source_ref }}
INPUT_UPDATE_LATEST: ${{ github.event.inputs.update_latest }}
RELEASE_PRERELEASE: ${{ github.event.release.prerelease }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
set -euo pipefail
validate_docs_version() {
local version="$1"
if [[ ! "$version" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]]; then
echo "::error::docs_version may only contain letters, numbers, dots, underscores, and hyphens."
exit 1
fi
}
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
echo "checkout_ref=$GITHUB_SHA" >> "$GITHUB_OUTPUT"
echo "docs_version=develop" >> "$GITHUB_OUTPUT"
echo "update_latest=auto" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ "$GITHUB_EVENT_NAME" == "release" ]]; then
docs_version="${RELEASE_TAG#v}"
if [[ -z "$docs_version" ]]; then
echo "::error::Release tag must contain a version, e.g. v1.1.0."
exit 1
fi
validate_docs_version "$docs_version"
echo "checkout_ref=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
echo "docs_version=$docs_version" >> "$GITHUB_OUTPUT"
if [[ "$RELEASE_PRERELEASE" == "true" ]]; then
echo "update_latest=false" >> "$GITHUB_OUTPUT"
else
echo "update_latest=true" >> "$GITHUB_OUTPUT"
fi
exit 0
fi
if [[ -z "$INPUT_DOCS_VERSION" ]]; then
source_ref="$INPUT_SOURCE_REF"
if [[ -z "$source_ref" ]]; then
source_ref="develop"
fi
echo "checkout_ref=$source_ref" >> "$GITHUB_OUTPUT"
echo "docs_version=develop" >> "$GITHUB_OUTPUT"
echo "update_latest=auto" >> "$GITHUB_OUTPUT"
exit 0
fi
docs_version="${INPUT_DOCS_VERSION#v}"
validate_docs_version "$docs_version"
source_ref="$INPUT_SOURCE_REF"
if [[ -z "$source_ref" ]]; then
source_ref="v$docs_version"
fi
echo "checkout_ref=$source_ref" >> "$GITHUB_OUTPUT"
echo "docs_version=$docs_version" >> "$GITHUB_OUTPUT"
if [[ "$INPUT_UPDATE_LATEST" == "true" ]]; then
echo "update_latest=true" >> "$GITHUB_OUTPUT"
else
echo "update_latest=false" >> "$GITHUB_OUTPUT"
fi
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ steps.docs.outputs.checkout_ref }}
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.x'
- name: Install docs dependencies
run: pip install -r docs/requirements.txt
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Build docs
run: mkdocs build --strict
- name: Fetch Pages branch
run: git fetch origin gh-pages --depth=1 || true
- name: Deploy versioned docs
env:
DOCS_VERSION: ${{ steps.docs.outputs.docs_version }}
UPDATE_LATEST: ${{ steps.docs.outputs.update_latest }}
shell: bash
run: |
set -euo pipefail
should_update_latest="$UPDATE_LATEST"
if [[ "$should_update_latest" == "auto" ]]; then
versions_file="$RUNNER_TEMP/docs-versions.json"
if git show origin/gh-pages:versions.json > "$versions_file" 2>/dev/null \
&& python3 - "$versions_file" <<'PY'
import json
import re
import sys
with open(sys.argv[1], encoding='utf-8') as handle:
versions = json.load(handle)
stable_version = re.compile(r'^[0-9]+\.[0-9]+\.[0-9]+$')
for item in versions:
if stable_version.fullmatch(str(item.get('version', ''))):
sys.exit(0)
sys.exit(1)
PY
then
should_update_latest=false
else
should_update_latest=true
fi
fi
if [[ "$should_update_latest" == "true" ]]; then
mike deploy --push --update-aliases "$DOCS_VERSION" latest
mike set-default --push latest
else
mike deploy --push "$DOCS_VERSION"
fi