Files
Echoion/scripts/release.sh
T
faumaray 5547621cfa
Container CI / release-build (push) Failing after 25s
Release: resolve containerized runner workspace
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-26 02:38:31 +03:00

640 lines
20 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
usage: scripts/release.sh --version VERSION [options]
Options:
--build-dir DIR Clean build directory (default: build-release)
--dist-dir DIR Release output directory (default: dist)
--jobs N Parallel build jobs
--skip-tests Skip CTest and frontend tests
--no-clean Reuse the configured build directory
--update-url URL Emit an unsigned runtime feed payload for this artifact
--update-channel NAME
Feed channel (default: stable)
--update-feed-id NAME
Feed identifier (default: echoion-runtime)
--update-sequence N
Monotonic feed sequence (default: SOURCE_DATE_EPOCH)
--update-valid-days N
Feed lifetime in days (default: 30)
--official-update-feed-url URL
HTTPS aggregate feed embedded as the official default
--void-source DIR Use an explicit VoidLibrary source tree
--void-teamspeak-source DIR
Use an explicit VoidTeamspeak source tree
--container Build with containers/release.Dockerfile (the default)
--host Explicitly build directly on this host
-h, --help Show this help
The release process never starts echoiond. Runtime validation uses readelf.
EOF
}
die() {
echo "release: $*" >&2
exit 2
}
canonical_release_version() {
local value=$1
local prerelease identifier
if [[ ! $value =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$ ]]; then
return 1
fi
prerelease=${BASH_REMATCH[5]:-}
while [[ -n $prerelease ]]; do
if [[ $prerelease == *.* ]]; then
identifier=${prerelease%%.*}
prerelease=${prerelease#*.}
else
identifier=$prerelease
prerelease=
fi
[[ ! $identifier =~ ^0[0-9]+$ ]] || return 1
done
return 0
}
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
source_dir=$(cd -- "$script_dir/.." && pwd -P)
version=
build_dir="$source_dir/build-release"
dist_dir="$source_dir/dist"
jobs=
run_tests=1
clean_build=1
use_container=1
update_url=
update_channel=stable
update_feed_id=echoion-runtime
update_sequence=
update_valid_days=30
official_update_feed_url=
void_source=
void_teamspeak_source=
while (($#)); do
case $1 in
--version)
(($# >= 2)) || die "--version requires a value"
version=$2
shift 2
;;
--build-dir)
(($# >= 2)) || die "--build-dir requires a value"
build_dir=$2
shift 2
;;
--dist-dir)
(($# >= 2)) || die "--dist-dir requires a value"
dist_dir=$2
shift 2
;;
--jobs)
(($# >= 2)) || die "--jobs requires a value"
jobs=$2
shift 2
;;
--skip-tests)
run_tests=0
shift
;;
--no-clean)
clean_build=0
shift
;;
--update-url)
(($# >= 2)) || die "--update-url requires a value"
update_url=$2
shift 2
;;
--update-channel)
(($# >= 2)) || die "--update-channel requires a value"
update_channel=$2
shift 2
;;
--update-feed-id)
(($# >= 2)) || die "--update-feed-id requires a value"
update_feed_id=$2
shift 2
;;
--update-sequence)
(($# >= 2)) || die "--update-sequence requires a value"
update_sequence=$2
shift 2
;;
--update-valid-days)
(($# >= 2)) || die "--update-valid-days requires a value"
update_valid_days=$2
shift 2
;;
--official-update-feed-url)
(($# >= 2)) || die "--official-update-feed-url requires a value"
official_update_feed_url=$2
shift 2
;;
--void-source)
(($# >= 2)) || die "--void-source requires a value"
void_source=$2
shift 2
;;
--void-teamspeak-source)
(($# >= 2)) || die "--void-teamspeak-source requires a value"
void_teamspeak_source=$2
shift 2
;;
--container)
use_container=1
shift
;;
--host)
use_container=0
shift
;;
-h|--help)
usage
exit 0
;;
*)
die "unknown argument: $1"
;;
esac
done
[[ $version =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$ ]] ||
die "--version must contain only letters, digits, dot, underscore, or dash"
canonical_release_version "$version" ||
die "--version must be canonical Semantic Versioning 2.0.0"
if [[ -n $jobs && ! $jobs =~ ^[1-9][0-9]*$ ]]; then
die "--jobs must be a positive integer"
fi
[[ $update_channel =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,255}$ ]] ||
die "--update-channel contains unsupported characters"
[[ $update_feed_id =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,255}$ ]] ||
die "--update-feed-id contains unsupported characters"
[[ -z $update_sequence || $update_sequence =~ ^[0-9]+$ ]] ||
die "--update-sequence must be a non-negative integer"
[[ $update_valid_days =~ ^[1-9][0-9]*$ && $update_valid_days -le 365 ]] ||
die "--update-valid-days must be between 1 and 365"
[[ -z $official_update_feed_url ||
$official_update_feed_url == https://* ]] ||
die "--official-update-feed-url must use HTTPS"
build_dir=$(realpath -m -- "$build_dir")
dist_dir=$(realpath -m -- "$dist_dir")
if [[ -n $void_source ]]; then
void_source=$(realpath -e -- "$void_source")
[[ -d $void_source && -f $void_source/CMakeLists.txt ]] ||
die "--void-source must name a VoidLibrary source directory"
fi
if [[ -n $void_teamspeak_source ]]; then
void_teamspeak_source=$(realpath -e -- "$void_teamspeak_source")
[[ -d $void_teamspeak_source && -f $void_teamspeak_source/CMakeLists.txt ]] ||
die "--void-teamspeak-source must name a VoidTeamspeak source directory"
fi
container_path() {
local path=$1
case $path in
"$source_dir") echo /workspace ;;
"$source_dir"/*) echo "/workspace/${path#"$source_dir"/}" ;;
*) die "container build and dist directories must be inside $source_dir" ;;
esac
}
docker_daemon_path() {
local path=$1
local container_reference=${ECHOION_DOCKER_CONTAINER_ID:-}
local mount_data=
local mount_source mount_destination
local best_source='' best_destination=''
if [[ -z $container_reference ]]; then
container_reference=${JOB_CONTAINER_NAME:-${HOSTNAME:-}}
fi
# A containerized CI job talks to the host Docker daemon through its
# socket. Bind-mount source paths are therefore interpreted in the daemon
# host namespace, not in this job container. Resolve the longest matching
# mount from the current container so nested release containers see the
# checked-out workspace instead of an empty host directory.
if [[ -n ${ECHOION_DOCKER_CONTAINER_ID:-} ||
-f /.dockerenv || -f /run/.containerenv ]]; then
if [[ -n $container_reference ]]; then
mount_data=$(
docker inspect \
--format '{{range .Mounts}}{{printf "%s\t%s\n" .Source .Destination}}{{end}}' \
"$container_reference" 2>/dev/null || true
)
fi
fi
while IFS=$'\t' read -r mount_source mount_destination; do
[[ -n $mount_source && -n $mount_destination ]] || continue
case $path in
"$mount_destination"|"$mount_destination"/*)
if ((${#mount_destination} > ${#best_destination})); then
best_source=$mount_source
best_destination=$mount_destination
fi
;;
*)
if [[ $mount_destination == / && $path == /* ]]; then
best_source=$mount_source
best_destination=$mount_destination
fi
;;
esac
done <<<"$mount_data"
if [[ -z $best_destination ]]; then
printf '%s\n' "$path"
elif [[ $path == "$best_destination" ]]; then
printf '%s\n' "$best_source"
elif [[ $best_destination == / ]]; then
printf '%s/%s\n' "${best_source%/}" "${path#/}"
else
printf '%s/%s\n' \
"${best_source%/}" "${path#"$best_destination"/}"
fi
}
if ((use_container)); then
command -v docker >/dev/null || die "docker is required for --container"
container_build_dir=$(container_path "$build_dir")
container_dist_dir=$(container_path "$dist_dir")
docker_source_dir=$(docker_daemon_path "$source_dir")
image="echoion-release-builder:gcc-16.1.0"
proxy_build_args=()
proxy_run_args=()
for proxy_name in HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy; do
if [[ -n ${!proxy_name:-} ]]; then
# Docker treats these predefined build arguments specially: their
# values are inherited without being recorded in the image history.
proxy_build_args+=(--build-arg "$proxy_name")
proxy_run_args+=(--env "$proxy_name")
fi
done
docker build \
"${proxy_build_args[@]}" \
--platform linux/amd64 \
--file "$source_dir/containers/release.Dockerfile" \
--tag "$image" \
"$source_dir"
container_args=(
--rm
--user "$(id -u):$(id -g)"
--volume "$docker_source_dir:/workspace"
--workdir /workspace
--env HOME=/tmp/echoion-release-home
--env npm_config_cache=/tmp/echoion-npm-cache
)
container_args+=("${proxy_run_args[@]}")
if [[ -n $void_source ]]; then
docker_void_source=$(docker_daemon_path "$void_source")
container_args+=(
--volume "$docker_void_source:/workspace-deps/VoidLibrary:ro"
)
fi
if [[ -n $void_teamspeak_source ]]; then
docker_void_teamspeak_source=$(docker_daemon_path "$void_teamspeak_source")
container_args+=(
--volume "$docker_void_teamspeak_source:/workspace-deps/VoidTeamspeak:ro"
)
fi
if [[ -n ${SOURCE_DATE_EPOCH:-} ]]; then
container_args+=(--env "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH")
fi
release_args=(
--host
--version "$version"
--build-dir "$container_build_dir"
--dist-dir "$container_dist_dir"
)
[[ -n $jobs ]] && release_args+=(--jobs "$jobs")
((run_tests)) || release_args+=(--skip-tests)
((clean_build)) || release_args+=(--no-clean)
[[ -z $void_source ]] ||
release_args+=(--void-source /workspace-deps/VoidLibrary)
[[ -z $void_teamspeak_source ]] ||
release_args+=(--void-teamspeak-source /workspace-deps/VoidTeamspeak)
if [[ -n $update_url ]]; then
release_args+=(
--update-url "$update_url"
--update-channel "$update_channel"
--update-feed-id "$update_feed_id"
--update-valid-days "$update_valid_days"
)
[[ -z $update_sequence ]] ||
release_args+=(--update-sequence "$update_sequence")
fi
[[ -z $official_update_feed_url ]] ||
release_args+=(
--official-update-feed-url "$official_update_feed_url"
)
if [[ $docker_source_dir != "$source_dir" ]]; then
echo "release: mapped container workspace through the Docker daemon mount table"
fi
docker run --rm --platform linux/amd64 \
--volume "$docker_source_dir:/workspace:ro" \
"$image" \
test -x /workspace/scripts/release.sh ||
die "Docker daemon cannot access the checked-out source tree"
docker run --platform linux/amd64 "${container_args[@]}" "$image" \
bash scripts/release.sh "${release_args[@]}"
exit
fi
case "$(uname -s)/$(uname -m)" in
Linux/x86_64|Linux/amd64) ;;
*) die "host release builds require Linux x86_64; use the amd64 container builder" ;;
esac
required_commands=(
cmake ninja npm python3 patchelf readelf tar zstd gzip sha256sum openssl
dpkg-query ldconfig
)
for command_name in "${required_commands[@]}"; do
command -v "$command_name" >/dev/null || die "required command not found: $command_name"
done
python3 "$source_dir/scripts/validate-semver.py" "$version" ||
die "--version must be canonical Semantic Versioning 2.0.0"
[[ -x $source_dir/packaging/install.sh ]] ||
die "installer source is missing: packaging/install.sh"
[[ -x $source_dir/packaging/uninstall.sh ]] ||
die "uninstaller source is missing: packaging/uninstall.sh"
[[ -f $source_dir/packaging/service/echoion.service.in ]] ||
die "service template is missing: packaging/service/echoion.service.in"
if [[ -z ${SOURCE_DATE_EPOCH:-} ]]; then
SOURCE_DATE_EPOCH=$(git -C "$source_dir" log -1 --format=%ct 2>/dev/null || true)
[[ $SOURCE_DATE_EPOCH =~ ^[0-9]+$ ]] || SOURCE_DATE_EPOCH=0
fi
export SOURCE_DATE_EPOCH
safe_remove_tree() {
local path=$1
case $path in
"$source_dir"/build*|/tmp/*) ;;
*) die "refusing to clean non-build path outside source build*/ or /tmp: $path" ;;
esac
rm -rf -- "$path"
}
if ((clean_build)); then
safe_remove_tree "$build_dir"
fi
mkdir -p "$build_dir"
configure_args=(
--preset linux-release
-B "$build_dir"
-DBUILD_SHARED_LIBS=ON
-DECHOION_STATIC_LINK=OFF
-DECHOION_REPRODUCIBLE_BUILD=ON
"-DECHOION_RUNTIME_VERSION=$version"
)
official_update_keys="$source_dir/.gitea/release-keys/official-update-keys.json"
[[ -f $official_update_keys ]] ||
die "official update trust store is missing: $official_update_keys"
official_update_keys_json=$(
python3 -c \
'import json,sys; print(json.dumps(json.load(open(sys.argv[1], encoding="utf-8")), separators=(",", ":")))' \
"$official_update_keys"
) || die "official update trust store is invalid"
configure_args+=(
"-DECHOION_UPDATE_PUBLIC_KEYS_JSON=$official_update_keys_json"
"-DECHOION_UPDATE_FEED_URL=$official_update_feed_url"
)
[[ -z $void_source ]] ||
configure_args+=("-DCPM_Void_SOURCE=$void_source")
[[ -z $void_teamspeak_source ]] ||
configure_args+=("-DCPM_VoidTeamspeak_SOURCE=$void_teamspeak_source")
npm --prefix "$source_dir/EchoionWeb/frontend" ci --no-audit --no-fund
cmake -E rm -rf "$source_dir/EchoionWeb/frontend/web-dist"
(
cd "$source_dir"
cmake "${configure_args[@]}"
)
build_args=(--build "$build_dir" --config Release)
[[ -n $jobs ]] && build_args+=(--parallel "$jobs")
cmake "${build_args[@]}"
if ((run_tests)); then
ctest --test-dir "$build_dir" --build-config Release --output-on-failure
npm --prefix "$source_dir/EchoionWeb/frontend" test
npm --prefix "$source_dir/EchoionWeb/frontend" run i18n:check
fi
stage="$build_dir/runtime-stage"
safe_remove_tree "$stage"
cmake --install "$build_dir" \
--config Release \
--component Runtime \
--prefix "$stage"
mapfile -t library_directories < <(
find "$build_dir" -type f \( -name '*.so' -o -name '*.so.*' -o -name '*.ts' \) \
-printf '%h\n' | LC_ALL=C sort -u
)
library_directories+=("$stage/lib")
cxx_compiler=$("$source_dir/scripts/configured-cxx-compiler.sh" "$build_dir")
compiler_runtime_files=()
for runtime_name in libstdc++.so.6 libgcc_s.so.1; do
runtime_path=$(
"$cxx_compiler" -print-file-name="$runtime_name"
) || die "cannot locate $runtime_name with $cxx_compiler"
[[ $runtime_path == /* && -f $runtime_path ]] ||
die "$cxx_compiler did not return an existing absolute path for $runtime_name"
compiler_runtime_files+=("$runtime_path")
library_directories+=("$(dirname -- "$runtime_path")")
done
search_directories=$(IFS=';'; echo "${library_directories[*]}")
compiler_runtimes=$(IFS=';'; echo "${compiler_runtime_files[*]}")
resolver_libraries=("$build_dir/lib/Echoion.ts")
if [[ -d $stage/share/echoion/bootstrap-plugins ]]; then
while IFS= read -r -d '' plugin_library; do
resolver_libraries+=("$plugin_library")
done < <(
find "$stage/share/echoion/bootstrap-plugins" -type f -name '*.so' \
-print0 | LC_ALL=C sort -z
)
fi
resolver_library_list=$(IFS=';'; echo "${resolver_libraries[*]}")
cmake \
"-DBUNDLE_ROOT=$stage" \
"-DBUNDLE_RESOLVER_EXECUTABLES=$build_dir/bin/echoiond;$build_dir/bin/echoion-updater" \
"-DBUNDLE_RESOLVER_LIBRARIES=$resolver_library_list" \
"-DBUNDLE_SEARCH_DIRECTORIES=$search_directories" \
"-DBUNDLE_SEED_FILES=$compiler_runtimes" \
"-DPATCHELF_EXECUTABLE=$(command -v patchelf)" \
-P "$source_dir/cmake/BundleRuntimeDependencies.cmake"
# Bootstrap plugins are copied into writable managed-plugin state by the
# installer. Services and the portable launcher point the loader at current/lib;
# this relative path also keeps the immutable source artifact directly usable.
for plugin_library in "${resolver_libraries[@]:1}"; do
# shellcheck disable=SC2016 # Dynamic linker token, not a shell variable.
patchelf --set-rpath '$ORIGIN/../../../../../lib' "$plugin_library"
done
dependency_report="$build_dir/dependency-report.txt"
elf_validation_args=(
--root "$stage"
--report "$dependency_report"
--max-glibc 2.35
--forbid-content-prefix "$source_dir"
--forbid-content-prefix "$build_dir"
)
[[ -z $void_source ]] ||
elf_validation_args+=(--forbid-content-prefix "$void_source")
[[ -z $void_teamspeak_source ]] ||
elf_validation_args+=(--forbid-content-prefix "$void_teamspeak_source")
python3 "$source_dir/scripts/validate-release-elf.py" \
"${elf_validation_args[@]}"
collect_licenses() {
local destination=$1
local candidate relative package_name license_name digest target package source_path soname
local -a license_roots=(
"$source_dir/EchoionApi"
"$source_dir/EchoionCore"
"$source_dir/EchoionHost"
"$source_dir/EchoionStandalone"
"$source_dir/EchoionWeb"
"$build_dir/_deps"
)
if [[ -n ${GCC_ROOT:-} && -d $GCC_ROOT/share/licenses ]]; then
license_roots+=("$GCC_ROOT/share/licenses")
fi
if [[ -n ${BOOST_ROOT:-} && -d $BOOST_ROOT/share/licenses ]]; then
license_roots+=("$BOOST_ROOT/share/licenses")
fi
if [[ -n ${FFMPEG_ROOT:-} && -d $FFMPEG_ROOT/share/licenses ]]; then
license_roots+=("$FFMPEG_ROOT/share/licenses")
fi
mkdir -p "$destination"
for source_path in "${license_roots[@]}"; do
[[ -d $source_path ]] || continue
while IFS= read -r -d '' candidate; do
relative=${candidate#"$source_path"/}
if [[ $relative == */* ]]; then
package_name=${relative%%/*}
else
package_name=$(basename -- "$source_path")
fi
license_name=$(basename -- "$candidate")
package_name=${package_name//[^A-Za-z0-9._+-]/_}
license_name=${license_name//[^A-Za-z0-9._+-]/_}
digest=$(sha256sum "$candidate" | cut -c1-12)
target="$destination/${package_name}--${license_name}--${digest}"
install -m 0644 -- "$candidate" "$target"
done < <(
find "$source_path" -maxdepth 5 -type f \
\( -iname 'LICENSE' -o -iname 'LICENSE.txt' -o \
-iname 'LICENSE.md' -o -iname 'LICENSE.rst' -o \
-iname 'LICENSE-*' -o -iname 'LICENSE_*' -o \
-iname 'COPYING' -o -iname 'COPYING.*' -o \
-iname 'NOTICE' -o -iname 'NOTICE.*' -o \
-iname 'COPYRIGHT' -o -iname 'COPYRIGHT.*' \) \
-not -path '*/node_modules/*' -not -path '*/.git/*' \
-print0 | LC_ALL=C sort -z
)
done
if command -v dpkg-query >/dev/null && command -v ldconfig >/dev/null; then
while IFS= read -r soname; do
[[ -n $soname ]] || continue
source_path=$(ldconfig -p 2>/dev/null |
awk -v name="$soname" '
$1 == name && !path { path = $NF }
END { if (path) print path }
')
[[ -n $source_path ]] || continue
package=$(dpkg-query -S "$(readlink -f -- "$source_path")" 2>/dev/null |
sed -n '1s/: .*//p') || package=
[[ -n $package ]] || continue
package=${package%%:*}
candidate="/usr/share/doc/${package}/copyright"
[[ -f $candidate ]] || continue
install -m 0644 -- "$candidate" "$destination/${package}--copyright"
done < <(
find "$stage/lib" -maxdepth 1 \( -type f -o -type l \) \
-printf '%f\n' | LC_ALL=C sort -u
)
fi
}
collect_licenses "$stage/share/echoion/licenses"
python3 "$source_dir/scripts/collect-frontend-licenses.py" \
--node-modules "$source_dir/EchoionWeb/frontend/node_modules" \
--output "$stage/share/echoion/licenses/frontend"
python3 "$source_dir/scripts/generate-release-manifest.py" \
--root "$stage" \
--version "$version" \
--output "$stage/manifest.json"
# Installer helpers are mutable prefix-level files and intentionally are not
# included in manifest.files. They are added only after the immutable manifest.
install -m 0755 "$source_dir/packaging/install.sh" "$stage/install.sh"
install -m 0755 "$source_dir/packaging/uninstall.sh" "$stage/uninstall.sh"
mkdir -p "$dist_dir"
artifact_base="echoion-${version}-linux-x86_64"
archive="$dist_dir/$artifact_base.tar.zst"
installer="$dist_dir/$artifact_base.run"
external_manifest="$dist_dir/$artifact_base.manifest.json"
external_report="$dist_dir/$artifact_base.dependencies.txt"
feed_payload="$dist_dir/$artifact_base.update-payload.json"
rm -f -- \
"$archive" "$archive.tmp" \
"$installer" "$installer.tmp" \
"$external_manifest" "$external_report" "$feed_payload" \
"$dist_dir/SHA256SUMS"
bash "$source_dir/scripts/package-release-payload.sh" \
"$stage" "$artifact_base" "$SOURCE_DATE_EPOCH" \
"$archive" "$installer" "$build_dir"
install -m 0644 "$stage/manifest.json" "$external_manifest"
install -m 0644 "$dependency_report" "$external_report"
if [[ -n $update_url ]]; then
feed_args=(
--artifact "$archive"
--manifest "$external_manifest"
--version "$version"
--url "$update_url"
--channel "$update_channel"
--feed-id "$update_feed_id"
--valid-days "$update_valid_days"
--output-payload "$feed_payload"
)
[[ -z $update_sequence ]] ||
feed_args+=(--sequence "$update_sequence")
python3 "$source_dir/scripts/generate-update-feed.py" "${feed_args[@]}"
fi
(
cd "$dist_dir"
checksum_files=(
"$(basename "$archive")" \
"$(basename "$installer")" \
"$(basename "$external_manifest")" \
"$(basename "$external_report")"
)
[[ -z $update_url ]] || checksum_files+=("$(basename "$feed_payload")")
sha256sum "${checksum_files[@]}" >SHA256SUMS
)
echo "Release created without starting Echoion:"
echo " $archive"
echo " $installer"
echo " $external_manifest"
echo " $external_report"
[[ -z $update_url ]] || echo " $feed_payload"
echo " $dist_dir/SHA256SUMS"