Files
sized/scripts/package-source.sh
T
gamertan 9f36122e37
Sized Linux checks / Linux AMD64 / Rust 1.88.0 (pull_request) Successful in 5m2s
Sized Linux checks / Linux AMD64 / Rust 1.88.0 (push) Successful in 4m54s
Keep source and binary archives free of macOS metadata
2026-10-10 13:14:43 -04:00

43 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_root=$(cd "$(dirname "$0")/.." && pwd)
cd "$repo_root"
[[ $# == 1 && $1 == /* ]] || { echo 'Usage: scripts/package-source.sh ABSOLUTE_NEW_DIRECTORY' >&2; exit 2; }
destination=$1
[[ ! -e $destination && ! -L $destination ]] || { echo 'Refusing existing source output.' >&2; exit 1; }
git diff --quiet HEAD -- || { echo 'Commit tracked changes before packaging.' >&2; exit 1; }
revision=$(git rev-parse HEAD)
mkdir -p "$destination"
source_dir="$destination/sized-source"
mkdir "$source_dir"
git archive "$revision" | tar -x -C "$source_dir"
mkdir -p "$source_dir/.cargo"
cargo vendor --locked --versioned-dirs --manifest-path "$source_dir/Cargo.toml" "$source_dir/vendor" > "$destination/vendor-config"
sed 's|directory = ".*"|directory = "vendor"|' "$destination/vendor-config" > "$source_dir/.cargo/config.toml"
printf '%s\n' "$revision" > "$source_dir/SOURCE-REVISION.txt"
cat > "$source_dir/BUILD-OFFLINE.txt" <<BUILD
Sized 2.0.0 source checkpoint: $revision
Requires Rust 1.88 or newer and the target platform's C linker/toolchain.
From this directory: cargo build --locked --offline --release
Test: cargo test --locked --offline --workspace (run as an ordinary user)
Verify included core: python3 scripts/check-core.py
Make an unsigned host archive: SIZED_SOURCE_REVISION=$revision scripts/release.sh
Developer ID signing/notarization requires your own identity and is separate.
BUILD
(cd "$source_dir" && CARGO_HOME="$destination/empty-cargo-home" CARGO_TARGET_DIR="$destination/check-target" cargo check --locked --offline --workspace --all-targets)
(cd "$source_dir" && python3 scripts/check-core.py)
COPYFILE_DISABLE=1 tar --no-xattrs -czf "$destination/sized-v2.0.0-source.tar.gz" -C "$destination" sized-source
# Reject platform metadata sidecars before any publication or Linux rebuild.
python3 - "$destination/sized-v2.0.0-source.tar.gz" <<'PY_CHECK'
import sys, tarfile
from pathlib import PurePosixPath
with tarfile.open(sys.argv[1]) as archive:
for entry in archive:
if any(part.startswith('._') for part in PurePosixPath(entry.name).parts):
raise SystemExit(f'Unexpected AppleDouble metadata: {entry.name}')
if any('xattr' in key.lower() for key in entry.pax_headers):
raise SystemExit(f'Unexpected extended attributes: {entry.name}')
PY_CHECK
printf '%s\n' "$revision" > "$destination/SOURCE-REVISION.txt"
echo "Verified offline source: $destination/sized-v2.0.0-source.tar.gz"