nix-channels: Tolerate new release taglines

The release tagline format changed and now has timezone and Git commit
information. Try to be more tolerant to those.

Old .released-time files may have already been collected with incorrect
data. Handle those as well.

See https://github.com/NixOS/nixos-channel-scripts/pull/99
This commit is contained in:
dramforever 2025-11-27 15:03:10 +08:00
parent 98fa39a31b
commit be5f4cd19c

View File

@ -194,7 +194,11 @@ def clone_channels():
tagline = node('p').text()
tagline_res = re.match(r'^Released on (.+) from', tagline)
# Examples:
#
# Released on yyyy-mm-dd hh:mm UTC from Git commit ...
# Released on yyyy-mm-dd hh:mm from ...
tagline_res = re.match(r'^Released on (.+?) (?:UTC )?from', tagline)
if tagline_res is None:
logging.warning(f' - Invalid tagline: {tagline}')
@ -385,6 +389,9 @@ def garbage_collect():
channel = release.name.split('@')[0]
date_str = (release / '.released-time').read_text()
date_match = re.match(r'\d+-\d+-\d+ \d+:\d+', date_str)
assert date_match is not None, f'Release {release!r} has invalid time {date_str!r}'
date_str = date_match[0]
released_date = datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
if released_date >= time_threshold: