-
Notifications
You must be signed in to change notification settings - Fork 4
85 lines (76 loc) · 3.06 KB
/
docs.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
name: docs
on:
workflow_dispatch:
release:
types:
- published
push:
branches:
- main
paths:
- "docs/**"
- "**.md"
- .github/workflows/docs.yml
- mkdocs.yml
env:
actor: "41898282+github-actions[bot]"
GH_TOKEN: ${{ github.token }}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip
- run: pip install --upgrade pip -r docs/requirements.txt
- name: git config
run: |
git config --local user.email "${actor}@users.noreply.github.com"
git config --local user.name "$actor"
gh release list > releases.tsv
- name: get version tag & alias
shell: python {0}
run: |
import os
import re
import warnings
release_tag = ''
with open('releases.tsv', 'r') as infile:
for line in infile:
release_name, latest, tag, timestamp = line.strip().split('\t')
if latest == "Latest":
release_tag = tag.strip('v')
break
if not release_tag:
warnings.warn("No latest release found")
with open('VERSION', 'r') as infile:
current_version = infile.read().strip()
if current_version == release_tag:
docs_alias = 'latest'
# set version to just major and minor
semver_pattern = '(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?'
release_semver = re.match(semver_pattern, release_tag)
docs_version = f"{release_semver.group('major')}.{release_semver.group('minor')}"
else:
semver_pattern = '(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?'
release_semver = re.match(semver_pattern, release_tag)
current_semver = re.match(semver_pattern, current_version)
groups = ['major', 'minor', 'patch']
if current_semver.group('prerelease') and any([current_semver.group(grp) >= release_semver.group(grp) for grp in groups]):
docs_alias = ''
docs_version = 'dev'
else:
raise ValueError(f"current version {current_version} is not greater than latest release {release_tag}")
with open(os.getenv("GITHUB_ENV"), 'a') as out_env:
out_env.write(f"VERSION={docs_version}\n")
out_env.write(f"ALIAS={docs_alias}\n")
- name: deploy docs
run: |
mike deploy ${{ env.VERSION }} ${{ env.ALIAS }} \
--push \
--update-aliases \
--branch gh-pages