download: compute version from Github tags for gvisor

Gvisor is the only one of our deployed components which use tags instead
of proper releases. So the tags scraping support will, for now, cater to
gvisor particularities, notably in the tag name format and the fact that
some older releases don't have the same URL scheme.
This commit is contained in:
Max Gautier
2024-12-21 16:43:56 +01:00
parent 479fda6355
commit 6608efb2c4
2 changed files with 33 additions and 7 deletions

View File

@@ -7,7 +7,8 @@
import sys import sys
import os import os
from itertools import groupby from itertools import groupby, chain
from more_itertools import partition
from collections import defaultdict from collections import defaultdict
from functools import cache from functools import cache
import argparse import argparse
@@ -70,6 +71,18 @@ downloads = {
'url': "https://github.com/etcd-io/etcd/releases/download/v{version}/SHA256SUMS", 'url': "https://github.com/etcd-io/etcd/releases/download/v{version}/SHA256SUMS",
'graphql_id': "R_kgDOAKtHtg", 'graphql_id': "R_kgDOAKtHtg",
}, },
"gvisor_containerd_shim_binary": {
'url': "https://storage.googleapis.com/gvisor/releases/release/{version}/{alt_arch}/containerd-shim-runsc-v1.sha512",
'hashtype': "sha512",
'tags': True,
'graphql_id': "R_kgDOB9IlXg",
},
"gvisor_runsc_binary": {
'url': "https://storage.googleapis.com/gvisor/releases/release/{version}/{alt_arch}/runsc.sha512",
'hashtype': "sha512",
'tags': True,
'graphql_id': "R_kgDOB9IlXg",
},
"kata_containers_binary": { "kata_containers_binary": {
'url': "https://github.com/kata-containers/kata-containers/releases/download/{version}/kata-static-{version}-{arch}.tar.xz", 'url': "https://github.com/kata-containers/kata-containers/releases/download/{version}/kata-static-{version}-{arch}.tar.xz",
'binary': True, 'binary': True,
@@ -179,10 +192,14 @@ def download_hash(only_downloads: [str]) -> None:
hash_file.raise_for_status() hash_file.raise_for_status()
return download_hash_extract[download](hash_file.content.decode()) return download_hash_extract[download](hash_file.content.decode())
nodes_ids = [x['graphql_id'] for x in downloads.values()]
releases, tags = map(dict,
partition(lambda r: r[1].get('tags', False),
{k: downloads[k] for k in (downloads.keys() & only_downloads)}.items()
))
ql_params = { ql_params = {
'repoWithReleases': nodes_ids, 'repoWithReleases': [r['graphql_id'] for r in releases.values()],
'repoWithTags': [], 'repoWithTags': [t['graphql_id'] for t in tags.values()],
} }
with open("list_releases.graphql") as query: with open("list_releases.graphql") as query:
response = s.post("https://api.github.com/graphql", response = s.post("https://api.github.com/graphql",
@@ -197,15 +214,21 @@ def download_hash(only_downloads: [str]) -> None:
return Version(possible_version) return Version(possible_version)
except InvalidVersion: except InvalidVersion:
return None return None
rep = response.json()["data"]
github_versions = dict(zip(downloads.keys(), github_versions = dict(zip(chain(releases.keys(), tags.keys()),
[ [
{ {
v for r in repo["releases"]["nodes"] v for r in repo["releases"]["nodes"]
if not r["isPrerelease"] if not r["isPrerelease"]
and (v := valid_version(r["tagName"])) is not None and (v := valid_version(r["tagName"])) is not None
} }
for repo in response.json()["data"]["with_releases"] for repo in rep["with_releases"]
] +
[
{ v for t in repo["refs"]["nodes"]
if (v := valid_version(t["name"].removeprefix('release-'))) is not None
}
for repo in rep["with_tags"]
], ],
strict=True)) strict=True))

View File

@@ -45,4 +45,7 @@ gh api graphql -H "X-Github-Next-Global-ID: 1" -f query='{
crun: repository(owner: "containers", name: "crun") { crun: repository(owner: "containers", name: "crun") {
id id
} }
gvisor: repository(owner: "google", name: "gvisor") {
id
}
}' }'