Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#!/usr/bin/env nix-shell 2#!nix-shell --pure -i python3 -p "python3.withPackages (ps: with ps; [ requests ])" 3 4import json 5import re 6import requests 7import sys 8 9feature_versions = (8, 11, 17, 21) 10oses = ("mac", "linux") 11types = ("jre", "jdk") 12impls = ("openj9",) 13 14arch_to_nixos = { 15 "x64": ("x86_64",), 16 "aarch64": ("aarch64",), 17 "arm": ("armv6l", "armv7l"), 18} 19 20def get_sha256(url): 21 resp = requests.get(url) 22 if resp.status_code != 200: 23 print("error: could not fetch checksum from url {}: code {}".format(url, resp.status_code), file=sys.stderr) 24 sys.exit(1) 25 return resp.text.strip().split(" ")[0] 26 27def generate_sources(releases, feature_version, out): 28 latest_version = None 29 for release in releases: 30 if release["prerelease"]: continue 31 if not re.search("_openj9-", release["name"]): continue 32 33 for asset in release["assets"]: 34 match = re.match("ibm-semeru-open-(?P<image_type>[a-z]*)_(?P<architecture>[a-z0-9]*)_(?P<os>[a-z]*)_(?:(?P<major1>[0-9]*)u(?P<security1>[0-9]*)b(?P<build1>[0-9]*)|(?P<major2>[0-9]*)\\.(?P<minor2>[0-9]*)\\.(?P<security2>[0-9]*)_(?P<build2>[0-9]*))_(?P<jvm_impl>[a-z0-9]*)-[0-9]*\\.[0-9]*\\.[0-9]\\.tar\\.gz$", asset["name"]) 35 36 if not match: continue 37 if match["os"] not in oses: continue 38 if match["image_type"] not in types: continue 39 if match["jvm_impl"] not in impls: continue 40 if match["architecture"] not in arch_to_nixos: continue 41 42 version = ".".join([ 43 match["major1"] or match["major2"], 44 match["minor2"] or "0", 45 match["security1"] or match["security2"] 46 ]) 47 build = match["build1"] or match["build2"] 48 49 if latest_version and latest_version != (version, build): continue 50 latest_version = (version, build) 51 52 arch_map = ( 53 out 54 .setdefault(match["jvm_impl"], {}) 55 .setdefault(match["os"], {}) 56 .setdefault(match["image_type"], {}) 57 .setdefault(feature_version, { 58 "packageType": match["image_type"], 59 "vmType": match["jvm_impl"], 60 }) 61 ) 62 63 for nixos_arch in arch_to_nixos[match["architecture"]]: 64 arch_map[nixos_arch] = { 65 "url": asset["browser_download_url"], 66 "sha256": get_sha256(asset["browser_download_url"] + ".sha256.txt"), 67 "version": version, 68 "build": build, 69 } 70 71 return out 72 73 74out = {} 75for feature_version in feature_versions: 76 resp = requests.get(f"https://api.github.com/repos/ibmruntimes/semeru{feature_version}-binaries/releases") 77 78 if resp.status_code != 200: 79 print("error: could not fetch data for release {} (code {}) {}".format(feature_version, resp.status_code, resp.content), file=sys.stderr) 80 sys.exit(1) 81 generate_sources(resp.json(), f"openjdk{feature_version}", out) 82 83with open("sources.json", "w") as f: 84 json.dump(out, f, indent=2, sort_keys=True) 85 f.write('\n')