Add script and worker to auto-update build and version info

This commit is contained in:
Donncha Ó Cearbhaill 2023-05-21 16:09:50 +01:00
parent fafbac3545
commit 27c5c76dc2
2 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,84 @@
import os
import re
import json
import urllib.request
import datetime
import operator
from xml.dom.minidom import parse, parseString
from packaging import version
"""
Python script to download the Apple RSS feed and parse it.
"""
def download_apple_rss(feed_url):
url = "https://developer.apple.com/news/releases/rss/releases.rss"
file_name = "releases.rss"
with urllib.request.urlopen(feed_url) as f:
rss_feed = f.read().decode('utf-8')
print("Downloaded RSS feed from Apple.")
return rss_feed
def parse_latest_ios_versions(rss_feed_text):
latest_ios_versions = []
parsed_feed = parseString(rss_feed_text)
for item in parsed_feed.getElementsByTagName("item"):
title = item.getElementsByTagName("title")[0].firstChild.data
if not title.startswith("iOS"):
continue
import re
build_match = re.match(r"iOS (?P<version>[\d\.]+) (?P<beta>beta )?(\S*)?\((?P<build>.*)\)", title)
if not build_match:
print("Could not parse iOS build:", title)
continue
release_info = build_match.groupdict()
if release_info["beta"]:
print("Skipping beta release:", title)
continue
latest_ios_versions.append(release_info)
return latest_ios_versions
def update_mvt(mvt_checkout_path, latest_ios_versions):
version_path = os.path.join(mvt_checkout_path, "mvt/ios/data/ios_versions.json")
with open(version_path, "r") as version_file:
current_versions = json.load(version_file)
new_entry_count = 0
for new_version in latest_ios_versions:
for current_version in current_versions:
if new_version["build"] == current_version["build"]:
break
else:
# New version that does not exist in current data
current_versions.append(new_version)
new_entry_count += 1
if not new_entry_count:
print("No new iOS versions found.")
else:
print("Found {} new iOS versions.".format(new_entry_count))
new_version_list = sorted(current_versions, key=lambda x: version.Version(x["version"]))
with open(version_path, "w") as version_file:
json.dump(new_version_list, version_file, indent=4)
def main():
print("Downloading RSS feed...")
mvt_checkout_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../"))
rss_feed = download_apple_rss("https://developer.apple.com/news/releases/rss/releases.rss")
latest_ios_version = parse_latest_ios_versions(rss_feed)
update_mvt(mvt_checkout_path, latest_ios_version)
if __name__ == "__main__":
main()

25
.github/workflows/update-ios-data.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: update-ios-releases
run-name: ${{ github.actor }} is finding the latest iOS release version and build numbers
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 */6 * * *'
jobs:
update-ios-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Run script to fetch latest iOS releases from Apple RSS feed.
run: python3 mvt/.github/workflows/scripts/update-ios-releases.py
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
title: '[auto] Update MVT with latest iOS releases and versions'
commit-message: Add new iOS versions and build numbers
add-paths: |
*.json
labels: |
automated pr