-
Notifications
You must be signed in to change notification settings - Fork 415
76 lines (60 loc) · 2.31 KB
/
doc-versions.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
name: Manage doc versions
on:
push:
branches:
- gh-pages
paths-ignore:
- 'dev/**'
permissions:
contents: write
jobs:
doc-versions:
name: Update Doc Versions
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Install packaging
run: python -m pip install packaging
- name: Update listing of versions
run: |
python << EOF
import json
from pathlib import Path
from packaging import version
# Get all paths that are versions
vers = sorted(version.parse(str(p)) for p in Path().glob('v[0-9]*'))
# Set up our version dictionary
versions = dict(versions=['latest', 'dev'],
latest=f'v{vers[-1].major}.{vers[-1].minor}', prereleases=[])
versions['versions'].extend(f'v{v.major}.{v.minor}' for v in vers[-4:])
# Write to JSON file
with open('versions.json', 'wt') as verfile:
json.dump(versions, verfile)
# Set up newer version json for python-sphinx-theme with latest
base_url = 'https://unidata.github.io/MetPy/{}/'
pst_versions = [{'version': 'latest', 'url': base_url.format('latest'), 'is_latest': True}]
# Now handle our collection of versions
pst_versions.extend({'name': f'v{v.major}.{v.minor}', 'version': f'{v.major}.{v.minor}',
'url': base_url.format(f'v{v.major}.{v.minor}')}
for v in reversed(vers[-4:]))
pst_versions[1]['is_latest'] = True
# Add dev
pst_versions.append({'version': 'dev', 'url': base_url.format('dev')})
# Write to another JSON file
with open('pst-versions.json', 'wt') as verfile:
json.dump(pst_versions, verfile)
# Update the 'latest' symlink
latest = Path('latest')
latest.unlink(missing_ok=True)
latest.symlink_to(versions['latest'], target_is_directory=True)
EOF
- name: Commit changes
run: |
git config user.name $GITHUB_ACTOR
git config user.email [email protected]
git add latest versions.json
git commit -am "Update version listing and latest link" || true
git push