Files
Echoion/scripts/ci-checkout-components.sh

81 lines
2.3 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)
# shellcheck source=scripts/lib/component-ssh.sh
source "$script_dir/lib/component-ssh.sh"
workspace=$(realpath -m -- "$1")
dependency_workspace=
if (($# == 2)); then
dependency_workspace=$(realpath -m -- "$2")
fi
credential_dir=$(mktemp -d)
cleanup() {
rm -rf -- "$credential_dir"
}
trap cleanup EXIT
umask 077
echoion_configure_component_ssh \
"$credential_dir" "$ECHOION_COMPONENT_SSH_KEY"
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