Files
call-recorder/scripts/build-release.sh
T
2026-11-06 11:50:43 +01:00

197 lines
8.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds a signed release of Gesprächsrekorder into dist-release/<version>/:
# the Windows NSIS installer (cross-built via build-windows.sh), the Linux
# deb and AppImage, their updater signatures (.sig) and latest.json.
# Sets <version> in tauri.conf.json, src-tauri/Cargo.toml and
# ui/package.json and leaves those changes for you to commit. Never tags or
# publishes anything; see RELEASING.md.
#
# Usage: scripts/build-release.sh <version> (e.g. 0.1.1)
#
# The updater private key comes from TAURI_SIGNING_PRIVATE_KEY_PATH (a file)
# or TAURI_SIGNING_PRIVATE_KEY (the key or a file), its password from
# TAURI_SIGNING_PRIVATE_KEY_PASSWORD (asked for when unset).
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)"
REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd -P)"
export PATH="${HOME}/.cargo/bin:${PATH}"
CONF="${REPO_ROOT}/src-tauri/tauri.conf.json"
CARGO_TOML="${REPO_ROOT}/src-tauri/Cargo.toml"
PACKAGE_JSON="${REPO_ROOT}/ui/package.json"
WINDOWS_BUNDLE="${REPO_ROOT}/target/x86_64-pc-windows-msvc/release/bundle/nsis"
LINUX_BUNDLE="${REPO_ROOT}/target/release/bundle"
die() {
echo "build-release: $*" >&2
exit 1
}
[ "$#" -eq 1 ] || die "usage: scripts/build-release.sh <version> (e.g. 0.1.1)"
VERSION="${1#v}"
SEMVER='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$'
[[ "${VERSION}" =~ ${SEMVER} ]] || die "'$1' is not a semantic version (e.g. 0.1.1)"
command -v jq >/dev/null 2>&1 || die "jq not found on PATH"
# shellcheck source=release.env
source "${SCRIPT_DIR}/release.env"
# --- Safety checks ----------------------------------------------------------
# The release must be built from committed sources, and the version bump this
# script makes must be the only change to commit afterwards. Untracked files
# are ignored.
if [ -n "$(git -C "${REPO_ROOT}" status --porcelain --untracked-files=no)" ]; then
if [ "${RELEASE_ALLOW_DIRTY:-}" = "1" ]; then
echo "WARNING: building from uncommitted changes (RELEASE_ALLOW_DIRTY=1)." >&2
else
die "uncommitted changes to tracked files; commit them first (or reset a version bump left by a failed build):
$(git -C "${REPO_ROOT}" status --short --untracked-files=no)"
fi
fi
# Whether semantic version $1 is greater than $2 (build metadata ignored).
version_gt() {
local a="${1%%+*}" b="${2%%+*}"
local a_pre="" b_pre="" i
[[ "${a}" == *-* ]] && a_pre="${a#*-}"
[[ "${b}" == *-* ]] && b_pre="${b#*-}"
local -a a_core b_core
IFS=. read -ra a_core <<<"${a%%-*}"
IFS=. read -ra b_core <<<"${b%%-*}"
for i in 0 1 2; do
((10#${a_core[i]} > 10#${b_core[i]})) && return 0
((10#${a_core[i]} < 10#${b_core[i]})) && return 1
done
# Same core: a release is greater than its pre-releases.
[ -z "${a_pre}" ] && [ -n "${b_pre}" ] && return 0
[ -z "${a_pre}" ] || [ -z "${b_pre}" ] && return 1
[ "${a_pre}" != "${b_pre}" ] &&
[ "$(printf '%s\n%s\n' "${a_pre}" "${b_pre}" | sort -V | tail -n 1)" = "${a_pre}" ]
}
# Installed apps only update to a greater version. The committed version may
# be built again as long as it has not been released (no tag v<version>),
# e.g. for the first release.
CURRENT="$(git -C "${REPO_ROOT}" show HEAD:src-tauri/tauri.conf.json | jq -r .version)"
if ! version_gt "${VERSION}" "${CURRENT}" &&
! { [ "${VERSION}" = "${CURRENT}" ] && [ -z "$(git -C "${REPO_ROOT}" tag -l "v${CURRENT}")" ]; }; then
if [ "${RELEASE_ALLOW_NOT_NEWER:-}" = "1" ]; then
echo "WARNING: ${VERSION} is not greater than the current version ${CURRENT} (RELEASE_ALLOW_NOT_NEWER=1); installed apps will not update to it." >&2
else
die "${VERSION} is not greater than the current version ${CURRENT}"
fi
fi
# --- Updater signing key ---------------------------------------------------
# `cargo tauri build` reads only TAURI_SIGNING_PRIVATE_KEY (key or path).
if [ -n "${TAURI_SIGNING_PRIVATE_KEY_PATH:-}" ]; then
[ -f "${TAURI_SIGNING_PRIVATE_KEY_PATH}" ] ||
die "TAURI_SIGNING_PRIVATE_KEY_PATH points to no file: ${TAURI_SIGNING_PRIVATE_KEY_PATH}"
export TAURI_SIGNING_PRIVATE_KEY="${TAURI_SIGNING_PRIVATE_KEY_PATH}"
elif [ -z "${TAURI_SIGNING_PRIVATE_KEY:-}" ]; then
die "no updater signing key. Set TAURI_SIGNING_PRIVATE_KEY_PATH=~/.tauri/call-recorder.key
(or TAURI_SIGNING_PRIVATE_KEY) and, if the key has one, TAURI_SIGNING_PRIVATE_KEY_PASSWORD.
See RELEASING.md."
fi
if [ -z "${TAURI_SIGNING_PRIVATE_KEY_PASSWORD+set}" ]; then
if [ -t 0 ]; then
read -rsp "Password of the updater signing key (empty if none): " TAURI_SIGNING_PRIVATE_KEY_PASSWORD
echo
else
TAURI_SIGNING_PRIVATE_KEY_PASSWORD=""
fi
fi
export TAURI_SIGNING_PRIVATE_KEY_PASSWORD
WORK_DIR="$(mktemp -d)"
trap 'rm -rf "${WORK_DIR}"' EXIT
# Key id of a minisign public key or signature (base64 of the minisign text;
# its second line holds the algorithm, then the 8-byte little-endian key id),
# as minisign prints it.
keynum() {
base64 -d | sed -n 2p | base64 -d | od -An -tx8 -j2 -N8 | tr -d ' \n' | tr a-f A-F
}
# Sign a probe file before the long build: a wrong key or password fails
# here, and a key that does not belong to plugins.updater.pubkey would make
# every installed app reject the update.
echo "probe" >"${WORK_DIR}/probe"
if [ -f "${TAURI_SIGNING_PRIVATE_KEY}" ]; then
probe_env=(env -u TAURI_SIGNING_PRIVATE_KEY TAURI_SIGNING_PRIVATE_KEY_PATH="${TAURI_SIGNING_PRIVATE_KEY}")
else
probe_env=(env -u TAURI_SIGNING_PRIVATE_KEY_PATH)
fi
"${probe_env[@]}" cargo tauri signer sign "${WORK_DIR}/probe" >/dev/null ||
die "signing with the updater key failed (wrong key or password?)"
key_of_signature="$(keynum <"${WORK_DIR}/probe.sig")"
key_of_config="$(jq -r '.plugins.updater.pubkey' "${CONF}" | keynum)"
if [ "${key_of_signature}" != "${key_of_config}" ]; then
if [ "${RELEASE_ALLOW_KEY_MISMATCH:-}" = "1" ]; then
echo "WARNING: the signing key does not match plugins.updater.pubkey; installed apps will reject this release (RELEASE_ALLOW_KEY_MISMATCH=1, test builds only)." >&2
else
die "the signing key (key id ${key_of_signature}) does not match plugins.updater.pubkey in tauri.conf.json (key id ${key_of_config})"
fi
fi
# --- Version and update feed ------------------------------------------------
[ "${#UPDATE_JSON_URLS[@]}" -gt 0 ] || die "UPDATE_JSON_URLS in release.env is empty"
echo "Setting version ${VERSION} and update feeds ${UPDATE_JSON_URLS[*]}"
# Rewrites a JSON file in place (read from stdin, so `--args` can come
# last), keeping its permissions.
jq_in_place() {
local file="$1"
shift
jq "$@" <"${file}" >"${WORK_DIR}/edit.json"
cat "${WORK_DIR}/edit.json" >"${file}"
}
jq_in_place "${CONF}" --arg version "${VERSION}" \
'.version = $version | .plugins.updater.endpoints = $ARGS.positional' \
--args "${UPDATE_JSON_URLS[@]}"
jq_in_place "${PACKAGE_JSON}" --arg version "${VERSION}" '.version = $version'
# The first `version = …` line is the one of [package].
sed -i -E "0,/^version = \"[^\"]*\"/s//version = \"${VERSION}\"/" "${CARGO_TOML}"
grep -qx "version = \"${VERSION}\"" "${CARGO_TOML}" || die "could not set the version in ${CARGO_TOML}"
# --- Build ------------------------------------------------------------------
"${SCRIPT_DIR}/build-windows.sh"
(cd "${REPO_ROOT}" && cargo tauri build --bundles deb appimage)
# --- Collect ----------------------------------------------------------------
OUT="${REPO_ROOT}/dist-release/${VERSION}"
rm -rf "${OUT}"
mkdir -p "${OUT}"
# Copies the one artifact matching the glob $2 in $1 and its .sig into OUT,
# under an ASCII name (the product name has an umlaut; download URLs and
# release assets stay plain).
collect() {
local matches=()
local file
for file in "$1"/$2; do
[ -f "${file}" ] && matches+=("${file}")
done
[ "${#matches[@]}" -eq 1 ] || die "expected exactly one $2 in $1, found ${#matches[@]}"
[ -s "${matches[0]}.sig" ] || die "missing updater signature ${matches[0]}.sig"
local name
name="$(basename "${matches[0]}" | sed 's/ä/ae/g; s/ö/oe/g; s/ü/ue/g; s/Ä/Ae/g; s/Ö/Oe/g; s/Ü/Ue/g; s/ß/ss/g')"
[[ "${name}" =~ ^[A-Za-z0-9._+-]+$ ]] || die "unexpected characters in artifact name: ${name}"
cp "${matches[0]}" "${OUT}/${name}"
cp "${matches[0]}.sig" "${OUT}/${name}.sig"
}
collect "${WINDOWS_BUNDLE}" "*_${VERSION}_x64-setup.exe"
collect "${LINUX_BUNDLE}/deb" "*_${VERSION}_amd64.deb"
collect "${LINUX_BUNDLE}/appimage" "*_${VERSION}_amd64.AppImage"
"${SCRIPT_DIR}/make-latest-json.sh" "${VERSION}" "${OUT}"
jq -e . "${OUT}/latest.json" >/dev/null || die "latest.json is not valid JSON"
echo
echo "Release ${VERSION} built in ${OUT}:"
ls -1 "${OUT}"
echo
echo "Next (see RELEASING.md): commit the version bump, tag v${VERSION},"
echo "create the Gitea release v${VERSION} and upload every file above."