Deploy v1.6 to GitHub Pages #44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $GITHUB_ACTOR@users.noreply.github.com | |
git add latest versions.json | |
git commit -am "Update version listing and latest link" || true | |
git push |