34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Remove only coordinator-owned reused builds after matching published ISO bytes."""
|
|
import fcntl
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import sys
|
|
|
|
root = Path(sys.argv[1]).resolve() / 'build/release-cycle'
|
|
inputs = json.loads(sys.argv[2])
|
|
locks = []
|
|
paths = []
|
|
for item in inputs:
|
|
path = Path(item['path'])
|
|
if path.is_symlink() or not path.exists():
|
|
raise ValueError('Missing or linked reused build: ' + str(path))
|
|
relative = path.resolve().relative_to(root)
|
|
if len(relative.parts) != 3 or not re.fullmatch(r'[0-9]{8}T[0-9]{6}Z', relative.parts[0]) or relative.parts[1:] != (item['variant'], 'build'):
|
|
raise ValueError('Not a coordinator-owned build: ' + str(path))
|
|
lock = (path / 'build.lock').open('a')
|
|
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
locks.append(lock)
|
|
if item['variant'] not in ('core', 'gnome', 'kde'):
|
|
raise ValueError('Unknown build variant')
|
|
iso = path / 'output' / ('archipelago-core-latest.iso' if item['variant'] == 'core' else 'archipelago-' + item['variant'] + '-probe.iso')
|
|
with iso.open('rb') as stream:
|
|
if hashlib.file_digest(stream, 'sha256').hexdigest() != item['sha256']:
|
|
raise ValueError('Reused ISO differs from publication: ' + str(iso))
|
|
paths.append(path)
|
|
for path in paths:
|
|
shutil.rmtree(path)
|
|
print('Removed published reused build: ' + str(path), flush=True)
|