98 lines
2.6 KiB
Bash
Executable File
98 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
|
|
|
|
if [[ $# -lt 3 || $# -gt 4 ]]; then
|
|
echo "usage: $0 RELEASE_ROOT VERSION BUNDLE_ROOT [MANIFEST]" >&2
|
|
exit 2
|
|
fi
|
|
|
|
release_root=$(realpath -m -- "$1")
|
|
version=$2
|
|
bundle_root=$(realpath -e -- "$3")
|
|
manifest=${4:-"$release_root/pending-release.json"}
|
|
manifest=$(realpath -m -- "$manifest")
|
|
|
|
if [[ ! $version =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$ ]]; then
|
|
echo "invalid release version: $version" >&2
|
|
exit 2
|
|
fi
|
|
if [[ $bundle_root == "$release_root" ||
|
|
$bundle_root == "$release_root"/* ||
|
|
$release_root == "$bundle_root"/* ]]; then
|
|
echo "bundle root and release root must not overlap" >&2
|
|
exit 2
|
|
fi
|
|
if [[ $(dirname -- "$manifest") != "$release_root" ]]; then
|
|
echo "pending manifest must be written directly below the release root" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! -x $bundle_root/bin/echoiond ]]; then
|
|
echo "echoiond is missing or not executable: $bundle_root/bin/echoiond" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! -x $bundle_root/bin/echoion-updater ]]; then
|
|
echo "updater is missing or not executable: $bundle_root/bin/echoion-updater" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! -f $bundle_root/lib/Echoion.ts ]]; then
|
|
echo "Core library is missing: $bundle_root/lib/Echoion.ts" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! -f $bundle_root/manifest.json ]]; then
|
|
echo "v2 release manifest is missing: $bundle_root/manifest.json" >&2
|
|
exit 2
|
|
fi
|
|
|
|
mkdir -p -- "$release_root" "$(dirname -- "$manifest")"
|
|
staging="$release_root/.staging-$version-$$"
|
|
destination="$release_root/$version"
|
|
manifest_tmp="$(dirname -- "$manifest")/.$(basename -- "$manifest").tmp.$$"
|
|
version_lock="$release_root/.stage-$version.lock"
|
|
destination_created=0
|
|
manifest_published=0
|
|
lock_acquired=0
|
|
cleanup() {
|
|
rm -rf -- "$staging"
|
|
rm -f -- "$manifest_tmp"
|
|
if ((destination_created && !manifest_published)); then
|
|
rm -rf -- "$destination"
|
|
fi
|
|
if ((lock_acquired)); then
|
|
rmdir -- "$version_lock" 2>/dev/null || true
|
|
fi
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
if ! mkdir -- "$version_lock"; then
|
|
echo "release staging is already active for version $version" >&2
|
|
exit 2
|
|
fi
|
|
lock_acquired=1
|
|
|
|
if [[ -e $destination ]]; then
|
|
echo "release already exists: $destination" >&2
|
|
exit 2
|
|
fi
|
|
|
|
mkdir -m 0755 -- "$staging"
|
|
cp -a -- "$bundle_root/." "$staging/"
|
|
|
|
python3 "$script_dir/validate-release-manifest.py" \
|
|
--root "$staging" \
|
|
--version "$version" \
|
|
--pending-output "$manifest_tmp"
|
|
|
|
mv -T -- "$staging" "$destination"
|
|
destination_created=1
|
|
mv -f -- "$manifest_tmp" "$manifest"
|
|
manifest_published=1
|
|
rmdir -- "$version_lock"
|
|
lock_acquired=0
|
|
trap - EXIT
|
|
|
|
echo "staged release $version"
|
|
echo "payload: $destination"
|
|
echo "manifest: $manifest"
|