# Signs $release (a store path) as a binary cache and writes, into --out: # router-update-.bundle one file to upload in the web UI # latest, cache/ the same, laid out for `router pulls from a URL` # # Run in a git checkout it also tags the commit that was released (vX.Y.Z, the # tags routers that update from the repository look for). The tag is local: it # has to be pushed with the branch. It is made last, so a release that fails # leaves no tag. # usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none] [--no-tag] key="" out=dist compression=zstd tag=1 while [ $# -gt 0 ]; do case $1 in --key) key=$2; shift ;; --out) out=$2; shift ;; --compression) compression=$2; shift ;; --no-tag) tag=0 ;; *) echo "usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none] [--no-tag]" >&2; exit 2 ;; esac shift done [ -n "$key" ] && [ -r "$key" ] || { echo "router-release: --key needs the secret key file (nix key generate-secret)" >&2; exit 1; } mkdir -p "$out" out=$(realpath "$out") version=$(cat "$release/version") rm -rf "$out/cache" "$out/latest" nix --extra-experimental-features nix-command copy --to "file://$out/cache?secret-key=$(realpath "$key")&compression=$compression" "$release" jq -n --arg release "$release" --arg version "$version" \ --argjson serial "$(cat "$release/serial")" --argjson schema "$(cat "$release/schema")" \ '{release: $release, version: $version, serial: $serial, schema: $schema}' > "$out/latest" tar -C "$out" -cf "$out/router-update-$version.bundle" latest cache echo "release $version ($(du -h "$out/router-update-$version.bundle" | cut -f1)):" echo " upload $out/router-update-$version.bundle in the router's web UI (Update)" echo " or serve $out over HTTP(S) and give the router that URL" if [ "$tag" -eq 1 ]; then if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then echo " tag none: not in a git repository" else head_version=$(git show HEAD:VERSION 2>/dev/null | tr -d '\n' || true) if [ "$head_version" != "$version" ]; then echo "router-release: the commit at HEAD is version '$head_version', not $version: not tagged" >&2 echo " (commit the version, then: git tag -a v$version -m 'Release $version')" >&2 exit 1 fi head=$(git rev-parse HEAD) if git rev-parse -q --verify "refs/tags/v$version" >/dev/null; then if [ "$(git rev-parse "v$version^{commit}")" != "$head" ]; then echo "router-release: v$version is already a tag of another commit" >&2 exit 1 fi echo " tag v$version exists" else git tag -a "v$version" -m "Release $version" echo " tag v$version on ${head:0:7}: push it with the branch (git push origin v$version)" fi if [ "$(cat "$release/rev")" != "$head" ]; then echo " note the release was built from a tree that differs from HEAD (uncommitted changes)" fi fi fi