diff --git a/.github/workflows/scripts/update-ios-releases.py b/.github/workflows/scripts/update-ios-releases.py new file mode 100644 index 0000000..6dc0f57 --- /dev/null +++ b/.github/workflows/scripts/update-ios-releases.py @@ -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[\d\.]+) (?Pbeta )?(\S*)?\((?P.*)\)", 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() diff --git a/.github/workflows/update-ios-data.yml b/.github/workflows/update-ios-data.yml new file mode 100644 index 0000000..d3c411a --- /dev/null +++ b/.github/workflows/update-ios-data.yml @@ -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 \ No newline at end of file