diff options
author | Daniil Baturin <daniil@baturin.org> | 2023-08-22 16:04:50 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2023-08-22 16:04:50 +0100 |
commit | 36617f4fbaae28438509310273ca58c1a83f4ee1 (patch) | |
tree | b280118dc98faaaee88a3a9ca99a9af579d0da9e /scripts | |
parent | 7e03a9985b10e75355a6eda9da2bdf5b0935b3dc (diff) | |
download | community.vyos.net-36617f4fbaae28438509310273ca58c1a83f4ee1.tar.gz community.vyos.net-36617f4fbaae28438509310273ca58c1a83f4ee1.zip |
Retrieve nightly build links from the new GitHub release storage
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/list-nightly-builds.py | 86 |
1 files changed, 31 insertions, 55 deletions
diff --git a/scripts/list-nightly-builds.py b/scripts/list-nightly-builds.py index 3b4d10c..7cde6ae 100755 --- a/scripts/list-nightly-builds.py +++ b/scripts/list-nightly-builds.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Builds a list of nightly builds from S3 +# Builds a list of nightly builds from GitHub releases # # Requires the following environment variables: # SNAPSHOTS_BUCKET @@ -12,73 +12,49 @@ import re import sys import json -import boto3 - +import github import jinja2 -from functools import cmp_to_key - -def make_link(prefix, file): - f = re.sub(r'\s+', '+', file) - return "https://s3-us.vyos.io/{0}/{1}".format(prefix, file) - -def compare(l, r): - try: - regex = r'\-(\d+)\-' - l_date = int(re.search(regex, l).group(1)) - r_date = int(re.search(regex, r).group(1)) - if l_date == r_date: - return 0 - elif l_date > r_date: - return 1 - else: - return -1 - except: - return(-1) - +REPO = 'vyos/vyos-rolling-nightly-builds' -def list_image_files(bucket, prefix): - s3 = boto3.client('s3') - object_listing = s3.list_objects_v2(Bucket=bucket, Prefix=prefix) - data = object_listing['Contents'] +def list_images(repo): + images = [] - files = [] - for f in data: - files.append(f['Key']) + # GitHub returns releases sorted by date from newest to oldest, + # so we don't need to sort them + releases = repo.get_releases() + for r in releases: + iso = r.assets[0] + sig = r.assets[1] - return files + # Nightly build releases have two assets: + # an ISO and a Minisign signature file + # The signature is always the second asset in the list + image = {} + image["iso_url"] = iso.browser_download_url + image["sig_url"] = sig.browser_download_url + image["title"] = r.title -def render_image_list(bucket, prefix, files): - regex = prefix + r'/(.*?)' - file_names = list(set(map(lambda s: re.sub(regex, r'\1', s), files))) - file_names.sort(reverse=True, key=cmp_to_key(compare)) + images.append(image) - builds = [] - - for name in file_names: - build = {} - build['file'] = name - build['link'] = make_link(prefix, name) - - builds.append(build) + return images +def render_image_list(images): tmpl = jinja2.Template(""" <ul> - {% for b in builds %} - <li><a href="{{b.link}}">{{b.file}}</a></li> + {% for i in images %} + <li><a href="{{i.iso_url}}">{{i.title}}</a> (<a href="{{i.sig_url}}">Minisign signature</a>)</li> {% endfor %} </ul> """) - print(tmpl.render(builds=builds)) -if __name__ == '__main__': - bucket = os.getenv("SNAPSHOTS_BUCKET") + return tmpl.render(images=images) - try: - prefix = sys.argv[1] - except: - print("Please specify directory prefix!", file=sys.stderr) - sys.exit(1) +if __name__ == '__main__': + gh_token_string = os.getenv('GITHUB_ACCESS_TOKEN') + gh_auth = github.Auth.Token(gh_token_string) + gh = github.Github(auth=gh_auth) + repo = gh.get_repo(REPO) - files = list_image_files(bucket, prefix) - render_image_list(bucket, prefix, files) + images = list_images(repo) + print(render_image_list(images)) |