From 47994d143991d63205e9ec1c70acd7f4f721d7f7 Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 30 May 2024 04:54:06 -0400 Subject: [PATCH] scripts: prepare for nightly and beta cut-off To prevent unbounded size growth, we want to delete older nightly and beta manifests from master branch regularly. Users of old nightly and beta toolchains can still access from the `before/` tags, but these tags will not receive patch updates anymore. Currently cut-off can only be deployed manually. Stable versions are not affected and are all kept currently. --- scripts/cut_off_nightly_beta.py | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 scripts/cut_off_nightly_beta.py diff --git a/scripts/cut_off_nightly_beta.py b/scripts/cut_off_nightly_beta.py new file mode 100755 index 00000000..50c72ee0 --- /dev/null +++ b/scripts/cut_off_nightly_beta.py @@ -0,0 +1,45 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i python3 -p "python3.withPackages (ps: with ps; [ toml requests ])" +from typing import Callable +from fetch import update_nightly_index, update_beta_index +from pathlib import Path +import re +import sys + +CHANNELS: list[tuple[Path, Callable[[], None]]] = [ + (Path('manifests/nightly'), update_nightly_index), + (Path('manifests/beta'), update_beta_index), +] +RE_LATEST_DATE = re.compile('latest = "(.*?)"') + +def main(): + args = sys.argv[1:] + if len(args) != 1: + print(''' +Usage: + {0} + Delete all nightly and beta manifests before (excluding) . +''') + exit(1) + + cut_year = int(args[0]) + for (channel_root, update_index) in CHANNELS: + for year_dir in channel_root.iterdir(): + if year_dir.is_dir() and int(year_dir.name) < cut_year: + print(f'deleting {year_dir}') + for ver in year_dir.iterdir(): + ver.unlink() + year_dir.rmdir() + def latest_ver(): + src = (channel_root / 'default.nix').read_text() + m = RE_LATEST_DATE.search(src) + assert m is not None, f'No latest version:\n{src}' + return m[1] + before_latest = latest_ver() + update_index() + after_latest = latest_ver() + assert before_latest == after_latest, \ + f'Latest version must not be affected: {before_latest} -> {after_latest}' + +if __name__ == '__main__': + main()