plugins/tools/write-plugin-manifest.py

31 lines
1.1 KiB
Python

"""Record versions and hashes from the actual built plugin JARs."""
import hashlib
import json
from pathlib import Path
import re
import sys
import zipfile
def manifest(folder, commit):
plugins = []
for path in sorted(Path(folder).glob('*.jar')):
with zipfile.ZipFile(path) as jar:
description = jar.read('plugin.yml').decode()
fields = {}
for key in ('name', 'version', 'main'):
match = re.search(r'^' + key + r':\s*(.+?)\s*$', description, re.M)
if not match:
raise ValueError(f'Missing {key} in {path.name}')
fields[key] = match.group(1).strip('"\'')
plugins.append({**fields, 'filename': path.name,
'sha256': hashlib.sha256(path.read_bytes()).hexdigest()})
if not plugins:
raise ValueError('No plugin artifacts')
result = {'sourceCommit': commit, 'plugins': plugins}
(Path(folder) / 'release-manifest.json').write_text(json.dumps(result, indent=2) + '\n')
return result
if __name__ == '__main__':
print(json.dumps(manifest(sys.argv[1], sys.argv[2]), indent=2))