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, 23, 24) 10oses = ("mac", "linux", "alpine-linux") 11types = ("jre", "jdk") 12impls = ("hotspot",) 13 14arch_to_nixos = { 15 "x64": ("x86_64",), 16 "aarch64": ("aarch64",), 17 "arm": ("armv6l", "armv7l"), 18 "ppc64le": ("powerpc64le",), 19 "riscv64": ("riscv64",), 20} 21 22def generate_sources(assets, feature_version, out): 23 for asset in assets: 24 binary = asset["binary"] 25 if binary["os"] not in oses: continue 26 if binary["image_type"] not in types: continue 27 if binary["jvm_impl"] not in impls: continue 28 if binary["heap_size"] != "normal": continue 29 if binary["architecture"] not in arch_to_nixos: continue 30 31 version = ".".join(str(v) for v in [ 32 asset["version"]["major"], 33 asset["version"]["minor"], 34 asset["version"]["security"] 35 ]) 36 build = str(asset["version"]["build"]) 37 38 arch_map = ( 39 out 40 .setdefault(binary["jvm_impl"], {}) 41 .setdefault(binary["os"], {}) 42 .setdefault(binary["image_type"], {}) 43 .setdefault(feature_version, { 44 "packageType": binary["image_type"], 45 "vmType": binary["jvm_impl"], 46 }) 47 ) 48 49 for nixos_arch in arch_to_nixos[binary["architecture"]]: 50 arch_map[nixos_arch] = { 51 "url": binary["package"]["link"], 52 "sha256": binary["package"]["checksum"], 53 "version": version, 54 "build": build, 55 } 56 57 return out 58 59 60out = {} 61for feature_version in feature_versions: 62 # Default user-agenet is blocked by Azure WAF. 63 headers = {'user-agent': 'nixpkgs-temurin-generate-sources/1.0.0'} 64 resp = requests.get(f"https://api.adoptium.net/v3/assets/latest/{feature_version}/hotspot", headers=headers) 65 66 if resp.status_code != 200: 67 print("error: could not fetch data for release {} (code {}) {}".format(feature_version, resp.status_code, resp.content), file=sys.stderr) 68 sys.exit(1) 69 generate_sources(resp.json(), f"openjdk{feature_version}", out) 70 71with open("sources.json", "w") as f: 72 json.dump(out, f, indent=2, sort_keys=True) 73 f.write('\n')