Skip to content

Commit

Permalink
Merge pull request #50 from sopel-irc/independent-latest.json
Browse files Browse the repository at this point in the history
Independent generation of `latest.json` file
  • Loading branch information
dgw committed Jun 30, 2024
2 parents d6c3c3f + 81876cf commit cf6d998
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
9 changes: 0 additions & 9 deletions document_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,6 @@ def main(argv=None):

print("Done! {} versions documented.".format(len(versions.keys())))

latest = list(versions.keys())[0]
with open('latest.json', 'w') as f:
f.write("{{\n" # double braces so Python doesn't get confused
" \"version\": \"{version}\",\n"
" \"unstable\": \"{version}\",\n"
" \"release_notes\": \"https://sopel.chat/changelog/{version}/\"\n"
"}}".format(version=latest))

print("Generated latest.json file pointing to version {}.".format(latest))

if __name__ == '__main__':
main()
50 changes: 50 additions & 0 deletions generate_latest_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""
Sopel update-check JSON generation utility
This script creates a `latest.json` file representing the most recent stable and
unstable `sopel` releases published to PyPI, using PyPI's own JSON API.
Copyright 2024 dgw, technobabbl.es
Licensed under the Eiffel Forum License 2.
https://sopel.chat
"""
import json
import sys

from packaging.version import parse as parse_version
import requests


def main(argv=None):
response = requests.get('https://pypi.org/pypi/sopel/json')
response.raise_for_status()
data = response.json()
releases = sorted(parse_version(v) for v in data['releases'].keys())

latest = releases[-1]
stable = latest
if latest.is_prerelease:
stable_releases_rev = (ver for ver in reversed(releases[:-1]) if not ver.is_prerelease)
try:
stable = next(stable_releases_rev)
except StopIteration:
print("ERROR: Latest version is a prerelease, but no earlier stable version found!")
sys.exit(1)

with open('latest.json', 'w') as f:
sopel_version_info = {
"version": str(stable),
"unstable": str(latest),
"release_notes": f"https://sopel.chat/changelog/{stable}/",
"unstable_notes": f"https://github.com/sopel-irc/sopel/releases/v{latest}",
}
json.dump(sopel_version_info, f, indent=4)

print("Generated latest.json file pointing to {} (stable) + {} (unstable)."
.format(stable, latest))


if __name__ == '__main__':
main()
5 changes: 4 additions & 1 deletion netlify-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ set -e

echo "Starting custom build script..."

echo "Generating changelogs & latest.json file"
echo "Generating changelogs"
python3 document_versions.py --news=_sopel/NEWS

echo "Installing Sopel globally for plugin autodoc script"
pip3 install ./_sopel

echo "Generating latest.json file"
python3 generate_latest_json.py

echo "Generating plugin command/config pages"
python3 document_sopel_plugins.py --sopel=_sopel

Expand Down

0 comments on commit cf6d998

Please sign in to comment.