#!/usr/bin/env bash # Snapshot current source into an isolated clean Git checkout; never commit root. set -euo pipefail repository=$(cd -- "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) cd "$repository" check=$(mktemp -d "$repository/.tools/clean-release.XXXXXX") printf '%s\n' "$check" > .tools/latest-clean-release-path mkdir "$check/source" git ls-files --cached --others --exclude-standard -z > "$check/files.list" tar --null -T "$check/files.list" -cf "$check/source.tar" tar --no-same-owner -xf "$check/source.tar" -C "$check/source" git -C "$check/source" init -q git -C "$check/source" add -A git -C "$check/source" -c user.name='Local release snapshot' -c user.email='release@localhost' commit -qm 'Local source snapshot for clean release' git clone -q "$check/source" "$check/clone" mkdir -p "$check/clone/node_modules" "$check/clone/.tools/packwiz" cp -a "$repository/node_modules/yaml" "$repository/node_modules/smol-toml" "$check/clone/node_modules/" cp "$repository/.tools/packwiz/packwiz" "$check/clone/.tools/packwiz/packwiz" cp "$repository/.tools/docker-compose" "$check/clone/.tools/docker-compose" cd "$check/clone" ./mcpack build --release node --input-type=module - "$repository" <<'JS' import fs from 'node:fs'; import path from 'node:path'; import {parse} from 'smol-toml'; import {verifyRelease} from './platform/runtime.mjs'; const repository=process.argv[2],pack=parse(fs.readFileSync('pack/pack.toml','utf8')); const name=pack.name+'-'+pack.version,source=path.resolve('dist',name); const release=verifyRelease(source),destination=path.join(repository,'dist',name); if(fs.existsSync(destination))throw new Error('Immutable release already exists: '+destination); const stage=fs.mkdtempSync(path.join(repository,'dist','.clean-release-')); try{ fs.cpSync(source,stage,{recursive:true}); if(verifyRelease(stage).identity!==release.identity)throw new Error('Copied release identity differs'); fs.renameSync(stage,destination); }catch(error){fs.rmSync(stage,{recursive:true,force:true});throw error;} console.log('Published clean release: '+destination); JS