From 4578693b639cbdb6c533e900769f501cc153f824 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 3 Sep 2024 15:55:14 +0200 Subject: [PATCH] Auto-generate SVG badges (#9) Signed-off-by: Oliver Tale-Yazdi --- .github/workflows/update-files.yml | 18 ++++----- Justfile | 5 ++- README.md | 3 +- badges/polkadot-sdk-latest.svg | 2 +- releases-v1.json | 2 +- requirements.txt | 5 +++ update-badges.py | 64 ++++++++++++++++++++++++++++++ 7 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 update-badges.py diff --git a/.github/workflows/update-files.yml b/.github/workflows/update-files.yml index 3bac59f..27892e7 100644 --- a/.github/workflows/update-files.yml +++ b/.github/workflows/update-files.yml @@ -25,21 +25,17 @@ jobs: with: python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - - name: README - run: python update-readme.py - - - name: Calendar - run: python update-calendar.py + - uses: extractions/setup-just@v1 + with: + just-version: 1.35.0 + + - name: All files + run: just - name: Check for changes id: git-check run: | - git diff --exit-code . || echo "changes=true" >> $GITHUB_OUTPUT + git diff --exit-code --name-only . || echo "changes=true" >> $GITHUB_OUTPUT - name: Commit and push changes if manually triggered if: github.event_name == 'workflow_dispatch' && steps.git-check.outputs.changes == 'true' diff --git a/Justfile b/Justfile index 825932e..c383b43 100644 --- a/Justfile +++ b/Justfile @@ -1,6 +1,9 @@ +set quiet + default: venv venv/bin/python3 update-readme.py venv/bin/python3 update-calendar.py + venv/bin/python3 update-badges.py venv: #!/bin/bash @@ -9,5 +12,5 @@ venv: if [ ! -d "venv" ]; then # Create virtual environment python3 -m venv venv - venv/bin/pip install icalendar + venv/bin/pip install -r requirements.txt fi diff --git a/README.md b/README.md index c75eb19..1c2861c 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,6 @@ Subscribe to the calendar by adding this iCal link to your Google or Apple calen Google has an "From URL" and Apple "New Calendar Subscription" option for this: - - Google | Apple :-------------------------:|:-------------------------: ![](.assets/screenshot-google-cal.png) | ![](.assets/screenshot-apple-cal.png) @@ -107,6 +105,7 @@ Two scripts are currently in place to: - [manage.py](./manage.py) - manage the releases json file (plan, cutoff, publish, etc) - [update-readme.py](./update-readme.py) - updates the README.md file with the data from the releases.json file - [update-calendar.py](./update-calendar.py) - generates an iCal file from the releases.json file +- [update-badges.py](./update-badges.py) - re-generate the badges in the `badges` folder for downstream use. ## Roadmap diff --git a/badges/polkadot-sdk-latest.svg b/badges/polkadot-sdk-latest.svg index 696d22d..c4ea567 100644 --- a/badges/polkadot-sdk-latest.svg +++ b/badges/polkadot-sdk-latest.svg @@ -1 +1 @@ -Current Stable Release: polkadot 2407 1Current Stable Releasepolkadot 2407 1 \ No newline at end of file +Current Stable Release: polkadot 2407 2Current Stable Releasepolkadot 2407 2 \ No newline at end of file diff --git a/releases-v1.json b/releases-v1.json index b134831..25646d5 100644 --- a/releases-v1.json +++ b/releases-v1.json @@ -2,7 +2,7 @@ "Polkadot SDK": { "recommended": { "release": "stable2407", - "patch": "1" + "patch": "2" }, "releases": [ { diff --git a/requirements.txt b/requirements.txt index e650896..6331647 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,9 @@ +certifi==2024.8.30 +charset-normalizer==3.3.2 icalendar==5.0.13 +idna==3.8 python-dateutil==2.9.0.post0 pytz==2024.1 +requests==2.32.3 six==1.16.0 +urllib3==2.2.2 diff --git a/update-badges.py b/update-badges.py new file mode 100644 index 0000000..df5cfdd --- /dev/null +++ b/update-badges.py @@ -0,0 +1,64 @@ +import json +import os +import requests +from datetime import datetime + +releases = json.load(open("releases-v1.json")) + +def download(url, filename): + response = requests.get(url) + print(f"Downloading SVG from {url}") + + if response.status_code == 200: + with open(filename, 'wb') as file: + file.write(response.content) + else: + raise Exception(f"Failed to download SVG. Status code: {response.status_code}") + +def update_latest(): + recommended = releases["Polkadot SDK"]["recommended"] + + latest = recommended['release'].replace('stable', '') + if 'patch' in recommended: + latest += f"_{recommended['patch']}" + + latest_url = f"https://img.shields.io/badge/Current%20Stable%20Release-polkadot_{latest}-green" + latest_name = "badges/polkadot-sdk-latest.svg" + download(latest_url, latest_name) + +def find_next_unreleased_release(releases): + for release in releases: + if release['state'] in ['planned', 'staging']: + return release + return None + +def format_date(date_str): + date_obj = datetime.strptime(date_str, "%Y-%m-%d") + return date_obj.strftime("%Y/%m/%d") + +def update_next(): + releases = json.load(open("releases-v1.json")) + sdk_releases = releases["Polkadot SDK"]["releases"] + + next_release = find_next_unreleased_release(sdk_releases) + + if next_release: + next_version = next_release['name'].replace('stable', '') + publish_date = next_release['publish'] + + if isinstance(publish_date, dict) and 'estimated' in publish_date: + formatted_date = format_date(publish_date['estimated']) + elif isinstance(publish_date, dict) and 'when' in publish_date: + formatted_date = format_date(publish_date['when']) + else: + formatted_date = "Unknown" + + next_url = f"https://img.shields.io/badge/Next%20Stable%20Release%20%28polkadot_{next_version}%29-{formatted_date}-orange" + next_name = "badges/polkadot-sdk-next.svg" + download(next_url, next_name) + else: + print("No upcoming unreleased version found.") + +if __name__ == "__main__": + update_latest() + update_next()