diff --git a/.forgejo/workflows/arrakis-raw-spice.yml b/.forgejo/workflows/arrakis-raw-spice.yml index a708e40a..991da2ed 100644 --- a/.forgejo/workflows/arrakis-raw-spice.yml +++ b/.forgejo/workflows/arrakis-raw-spice.yml @@ -30,9 +30,9 @@ jobs: set -euo pipefail gradle --no-daemon -p JarvisConnector test jar python3 tools/test_plugin_fleet_install.py -v + python3 tools/plugin_arrakis_raw_spice.py JarvisConnector/build/libs/jarvistranslator.jar mkdir raw-spice-artifacts - curl --fail --location --retry 2 https://www.dunerealms.com/git/api/v1/repos/unimatrix/plugins/actions/artifacts/8602/zip -o retained-navigator.zip - python3 tools/plugin_arrakis_raw_spice.py retained-navigator.zip JarvisConnector/build/libs/jarvistranslator.jar raw-spice-artifacts/jarvistranslator.jar + cp JarvisConnector/build/libs/jarvistranslator.jar raw-spice-artifacts/ printf '%s\n' "$(git rev-parse HEAD)" > raw-spice-artifacts/SOURCE_COMMIT python3 tools/write-plugin-manifest.py raw-spice-artifacts "$GITHUB_SHA" cp tools/{install-plugin-fleet,plugin_arrakis_raw_spice,plugin_menu_pack,plugin_backend_abi,plugin_fleet_rollback,plugin_pack_properties,plugin_pillager_abi,reset-arrakis-terrain}.py raw-spice-artifacts/ diff --git a/tools/plugin_arrakis_raw_spice.py b/tools/plugin_arrakis_raw_spice.py index 4ea987d7..5d8f6e77 100644 --- a/tools/plugin_arrakis_raw_spice.py +++ b/tools/plugin_arrakis_raw_spice.py @@ -1,15 +1,16 @@ from pathlib import Path import hashlib -import io import zipfile BASELINE_SHA256 = 'ebe8d2edc9f3300a039de1f76b81a2435895569704b2087e0625db699effe5d7' OVERLAY = 'com/dunerealms/jarvis/ItemMetadataOverlay.class' -RETAINED_TREE = '80df0c65f8d85bcac8dd52c620197f4013a7f17e48a422ef8da1d451674c2' +RETAINED_TREE = '80df0c65f8d85bcac8dd52c620197f4013a7f17e48a422ef8da1d451674c2be5' DESCRIPTOR_SHA256 = '5d953df8bfa49bc5e57a698c018ea24bba3253a53d291ac6e48dd03d7e162a5a' def verify_jar(path): + if any(len(pin) != 64 for pin in (BASELINE_SHA256, RETAINED_TREE, DESCRIPTOR_SHA256)): + raise ValueError('Expected complete SHA-256 pins') with zipfile.ZipFile(path) as jar: names = [name for name in jar.namelist() if not name.endswith('/')] if len(set(names)) != len(names): @@ -24,30 +25,6 @@ def verify_jar(path): raise ValueError('JARVIS changed outside the reviewed raw spice overlay and version') -def assemble(baseline_artifact, compiled, output): - with zipfile.ZipFile(baseline_artifact) as wrapper: - names = wrapper.namelist() - if len(names) == 1 and names[0].endswith('.zip'): - with zipfile.ZipFile(io.BytesIO(wrapper.read(names[0]))) as release: - baseline = release.read('jarvistranslator.jar') - else: - baseline = wrapper.read('jarvistranslator.jar') - if hashlib.sha256(baseline).hexdigest() != BASELINE_SHA256: - raise ValueError('Retained Jarvis baseline differs from deployed Arrakis runtime') - with zipfile.ZipFile(io.BytesIO(baseline)) as original, zipfile.ZipFile(compiled) as build: - replacements = {entry: build.read(entry) for entry in (OVERLAY, 'plugin.yml')} - with zipfile.ZipFile(output, 'x') as result: - for info in original.infolist(): - data = replacements[info.filename] if info.filename in replacements else original.read(info) - result.writestr(info, data) - verify_jar(output) - - if __name__ == '__main__': import sys - if len(sys.argv) == 4: - assemble(*map(Path, sys.argv[1:])) - elif len(sys.argv) == 2: - verify_jar(Path(sys.argv[1])) - else: - raise SystemExit('Specify a JAR to verify, or baseline artifact, built JAR and output JAR') + verify_jar(Path(sys.argv[1]))