Files
Echoion/scripts/ci-checkout-components.sh
T
faumaray 458dde05a6
Modular container CI / release-build (push) Has been cancelled
Release: cut over Echoion 2.0 components
2026-07-29 20:35:27 +03:00

83 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if (($# < 1 || $# > 2)); then
echo "usage: $0 COMPONENT_WORKSPACE [DEPENDENCY_WORKSPACE]" >&2
exit 2
fi
if [[ -z ${ECHOION_COMPONENT_SSH_KEY:-} ]]; then
echo "ECHOION_COMPONENT_SSH_KEY is required" >&2
exit 2
fi
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
workspace=$(realpath -m -- "$1")
dependency_workspace=
if (($# == 2)); then
dependency_workspace=$(realpath -m -- "$2")
fi
credential_dir=$(mktemp -d)
cleanup() {
rm -f -- "$credential_dir/key" "$credential_dir/known_hosts"
rmdir -- "$credential_dir"
}
trap cleanup EXIT
umask 077
printf '%s\n' "$ECHOION_COMPONENT_SSH_KEY" >"$credential_dir/key"
printf '%s\n' \
'git.faumaray.ru ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCzZEz9JLrzk6oLiloSbueAN28vYL58Y/dTHBgRuBMMib9IJ1aDJShhr3kwC9sfOT0AzK0uwcMAqCAIkwJwttde8dIg0Mee0cmB/1JkoqFF4X3MUGD1r3nk8SSZNhIiPqo16hDF9Hf3FkovztIlBVntkyP9Iy9hYfP818Tiq3yRXROGdHjR7IfY4jR2QGfGrd/RtvPGExVqusxidy141240A8aRAwMFUqFdEvmXWjizrtCUqcrL/k1GEh0yJzbCdNOVUI6OuWd8tPluSBvmmeoNpKnCSl4Mkg36HObbOyrsme0asZqjcj0od65WYWApMPN0pUqhNu2CP83Nfor2VFwkdPRwe7cAZ0OD/8wyT6Hz5q1wWgf82y4tYDoDRYsd8JU86eebkJ07T5nCrEeC4Sj+qT4S5xv/kECAhxyP4QGnunORnY2fYsdNGzpPvbMN7gHe9UcIcQdOIgV3wrR1qpMVNcd8AEC2A3TRv/jzMCHSjmGGpgiy1Db2CZAjp5+PcjNmjvoPNN0NiA9X4rIVSeTfflWnDRmeNRJeZa73StjpU17EcAf97COUQPGWJQDgpJqINSpYU50fuaLBfzKnIRuiHjKQmyKe/zgRSmulnYFYM3AJfn8Ykg2VvkUQGvCt1+fqYiUa1iVFuwPP3ZigYF1mOZRpPnos5kaNmlB01q2sZw==' \
>"$credential_dir/known_hosts"
export GIT_SSH_COMMAND="ssh -i $credential_dir/key -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$credential_dir/known_hosts"
python3 "$script_dir/sync-components.py" \
--workspace "$workspace" \
--update
if [[ -n $dependency_workspace ]]; then
mkdir -p "$dependency_workspace"
while IFS=$'\t' read -r dependency repository revision; do
destination="$dependency_workspace/$dependency"
if [[ -e $destination && ! -d $destination/.git ]]; then
echo "dependency destination is not a Git repository: $destination" >&2
exit 1
fi
if [[ ! -d $destination/.git ]]; then
git clone --filter=blob:none --no-checkout \
"$repository" "$destination"
fi
git -C "$destination" remote set-url origin "$repository"
git -C "$destination" fetch --prune origin main
git -C "$destination" cat-file -e "$revision^{commit}"
git -C "$destination" checkout --detach "$revision"
git -C "$destination" diff --quiet
git -C "$destination" diff --cached --quiet
test "$(git -C "$destination" rev-parse HEAD)" = "$revision"
done < <(
python3 - "$script_dir/../cmake/DependencyLock.cmake" <<'PY'
import pathlib
import re
import sys
text = pathlib.Path(sys.argv[1]).read_text(encoding="utf-8")
repositories = {
"VoidLibrary": (
"ssh://gitea@git.faumaray.ru/void/voidlibrary.git",
"ECHOION_VOID_REVISION",
),
"VoidTeamspeak": (
"ssh://gitea@git.faumaray.ru/void/voidteamspeak.git",
"ECHOION_VOID_TEAMSPEAK_REVISION",
),
}
for name, (repository, variable) in repositories.items():
match = re.search(
rf'set\({variable}\s+"([0-9a-f]{{40}})"',
text,
re.MULTILINE,
)
if match is None:
raise SystemExit(f"missing exact {variable} in dependency lock")
print(name, repository, match.group(1), sep="\t")
PY
)
fi