john-slop/scripts/package-release.sh

64 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
set -eu
repository_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$repository_dir"
manifest_version=$(sed -n 's/^version = "\([^"]*\)"/\1/p' Cargo.toml | head -n 1)
release_version=${1:-$manifest_version}
if [ "$release_version" != "$manifest_version" ]; then
echo "release version $release_version does not match Cargo.toml $manifest_version" >&2
exit 2
fi
target_triple=$(rustc -vV | sed -n 's/^host: //p')
source_date_epoch=$(git log -1 --format=%ct)
export SOURCE_DATE_EPOCH="$source_date_epoch"
bundle_name="john_slop-${release_version}-${target_triple}"
bundle_dir="dist/${bundle_name}"
archive_path="dist/${bundle_name}.tar.gz"
if [ -e "$bundle_dir" ] || [ -e "$archive_path" ]; then
echo "release output already exists for $bundle_name; move it aside first" >&2
exit 2
fi
mkdir -p "$bundle_dir"
cargo build --locked --release --all-features
for binary in john-slop john-slop-fmt john-slop-lsp; do
cp "target/release/$binary" "$bundle_dir/$binary"
done
cp README.md CHANGELOG.md LICENSE "$bundle_dir/"
commit=$(git rev-parse HEAD)
rust_version=$(rustc --version)
cargo_version=$(cargo --version)
{
echo "version=$release_version"
echo "commit=$commit"
echo "target=$target_triple"
echo "source_date_epoch=$source_date_epoch"
echo "rustc=$rust_version"
echo "cargo=$cargo_version"
} >"$bundle_dir/BUILD-INFO"
(
cd "$bundle_dir"
sha256sum john-slop john-slop-fmt john-slop-lsp >SHA256SUMS
)
tar \
--sort=name \
--mtime="@$source_date_epoch" \
--owner=0 \
--group=0 \
--numeric-owner \
-cf - \
-C dist \
"$bundle_name" | gzip -n >"$archive_path"
sha256sum "$archive_path" >"${archive_path}.sha256"
echo "$archive_path"