Fix packaging script for the repo format's peculiarities

This commit is contained in:
jaseg 2023-10-24 17:03:58 +02:00
parent f5c40093ff
commit 35c4ef587c
6 changed files with 81 additions and 6 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
de.jaseg.kimesh.footprints/footprints
de.jaseg.kimesh.footprints/metadata.json
de.jaseg.kimesh.plugin/metadata.json
__pycache__

View file

@ -0,0 +1,31 @@
{
"$schema": "https://go.kicad.org/pcm/schemas/v1",
"name": "KiMesh",
"description": "A security mesh generator for KiCad",
"description_full": "This is the footprint package for the KiMesh security mesh generator.",
"identifier": "de.jaseg.kimesh.footprints",
"type": "library",
"author": {
"name": "jaseg",
"contact": {
"web": "https://jaseg.de/"
}
},
"license": "CERN-OHL",
"resources": {
"homepage": "https://jaseg.de/projects/kimesh",
"git": "https://git.jaseg.de/kimesh.git",
"issues": "https://github.com/jaseg/kimesh/issues"
},
"versions": [
{
"version": "1.0.0",
"status": "stable",
"kicad_version": "7.99",
"download_sha256": "e0c1a2752090def465afa6f6c38baeb74a6544e79e87de3019087c41a3f2790e",
"download_size": 822342,
"download_url": "https://git.jaseg.de/kimesh.git/plain/de.jaseg.kimesh.footprints-v1.0.0.zip?h=v1.0.0",
"install_size": 4803868
}
]
}

View file

@ -0,0 +1,31 @@
{
"$schema": "https://go.kicad.org/pcm/schemas/v1",
"name": "KiMesh",
"description": "A security mesh generator for KiCad",
"description_full": "KiMesh automatically generates security meshes for you. A security mesh is a set of PCB traces that cover an area to detect physical tampering. KiMesh can cover arbitrary areas with two or more traces. Note: The KiMesh footprints Add-On must be installed alongside KiMesh. For detailed usage instructions, please have a look at the KiMesh website linked in the add-on information.",
"identifier": "de.jaseg.kimesh.plugin",
"type": "plugin",
"author": {
"name": "jaseg",
"contact": {
"web": "https://jaseg.de/"
}
},
"license": "GPL-3.0",
"resources": {
"homepage": "https://jaseg.de/projects/kimesh",
"git": "https://git.jaseg.de/kimesh.git",
"issues": "https://github.com/jaseg/kimesh/issues"
},
"versions": [
{
"version": "1.0.0",
"status": "stable",
"kicad_version": "7.99",
"download_sha256": "59da3a8a13be001fb6f5eee9e1d346f4beee6c0d736856b2da205db290ad21a6",
"download_size": 12895,
"download_url": "https://git.jaseg.de/kimesh.git/plain/de.jaseg.kimesh.plugin-v1.0.0.zip?h=v1.0.0",
"install_size": 45166
}
]
}

Binary file not shown.

View file

@ -53,33 +53,44 @@ def do_release(version, increment):
for path in res.stdout.splitlines():
if re.fullmatch(r'de\.jaseg\.kimesh\.[^/]*-v[.0-9]*\.zip', path.strip()):
print(f'Removing old release zip {path} from git index.')
subprocess.run(['git', 'rm', '--cached', path], check=True, capture_output=True)
subprocess.run(['git', 'rm', path], check=True, capture_output=True)
for pkg_dir in Path('de.jaseg.kimesh.plugin'), Path('de.jaseg.kimesh.footprints'):
meta_path = pkg_dir / 'metadata.json'
# NOTE: metadata.json appears twice. In what I believe is a sub-optimal design choice, the variant in the
# archive is only allowed to contain the current version in its version list without its zip file metadata,
# while the variant in the repository index is supposed to contain all past versions including their zip file
# metadata. AFAICT they are the same otherwise.
meta_path = Path(f'{pkg_dir}-repo-metadata.json')
print(f'Updating metadata file {meta_path}')
meta_file = json.loads(meta_path.read_text())
subprocess.run(['git', 'add', str(meta_path)], check=True, capture_output=True)
ver_dict = {
'version': version,
'status': 'stable',
'kicad_version': '7.99',
}
meta_file['versions'].append(ver_dict)
meta_path.write_text(json.dumps(meta_file, indent=4))
# Include just the version metadata in the metadata for the archive
meta_file = json.loads(meta_path.read_text())
meta_file['versions'] = [ver_dict]
(pkg_dir / 'metadata.json').write_text(json.dumps(meta_file, indent=4))
zip_fn = Path(shutil.make_archive(f'{pkg_dir.name}-v{version}', 'zip', pkg_dir, '.'))
print(f'Adding new release zip {zip_fn} to git index.')
subprocess.run(['git', 'add', str(zip_fn)], check=True, capture_output=True)
# Add the zip's metadata to the metadata for the repository
ver_dict['download_sha256'] = hashlib.sha256(zip_fn.read_bytes()).hexdigest()
ver_dict['download_size'] = zip_fn.stat().st_size
ver_dict['download_url'] = f'https://git.jaseg.de/kimesh.git/plain/{zip_fn.name}?h=v{version}'
ver_dict['install_size'] = tree_size(pkg_dir)
meta_file = json.loads(meta_path.read_text())
meta_file['versions'].append(ver_dict)
meta_path.write_text(json.dumps(meta_file, indent=4))
print(f'Adding updated metadata file {meta_path} to git index')
subprocess.run(['git', 'add', str(meta_path)], check=True, capture_output=True)
print('Create git commit')
subprocess.run(['git', 'commit', '-m', f'Version {version}', '--no-edit'], check=True, capture_output=True)
res = subprocess.run('git rev-parse --short HEAD'.split(), check=True, capture_output=True, text=True)