treefmt / nix fmt (pull_request) Successful in 3s
test ebook search / test-ebook-search (pull_request) Successful in 1m22s
build_systems / prebuild-common-x86-64-v3 (pull_request) Successful in 39s
build_systems / build-brain (pull_request) Failing after 1m50s
build_systems / build-jeeves (pull_request) Successful in 2m20s
build_systems / build-portal-1 (pull_request) Successful in 41s
build_systems / build-rhapsody-in-green (pull_request) Successful in 1m20s
build_systems / build-bob (pull_request) Failing after 14m17s
54 lines
1.9 KiB
Bash
54 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Newer runner modules export INSTANCE_DIR and multiple colon-separated state paths.
|
|
instance_dir="${INSTANCE_DIR:-${STATE_DIRECTORY%%:*}/$1}"
|
|
legacy_instance_dir="$(dirname "$instance_dir")/$(hostname)"
|
|
runner_url="$2"
|
|
runner_config_file="$3"
|
|
shift 3
|
|
runner_labels="$(IFS=,; printf '%s' "$*")"
|
|
|
|
if [ "$legacy_instance_dir" != "$instance_dir" ] && [ -d "$legacy_instance_dir" ]; then
|
|
# systemd may have already created an empty instance directory.
|
|
if [ ! -e "$instance_dir" ] || rmdir "$instance_dir" 2>/dev/null; then
|
|
mv "$legacy_instance_dir" "$instance_dir"
|
|
fi
|
|
fi
|
|
|
|
mkdir -vp "$instance_dir"
|
|
cd "$instance_dir" || exit 1
|
|
|
|
# Newer modules use LoadCredential; older ones export TOKEN via EnvironmentFile.
|
|
runner_token="${TOKEN:-}"
|
|
if [ -n "${CREDENTIALS_DIRECTORY:-}" ]; then
|
|
runner_token="$(cat "$CREDENTIALS_DIRECTORY/token")"
|
|
# Keep accepting the legacy TOKEN= format as well as a raw token.
|
|
while IFS= read -r token_line; do
|
|
if [[ "$token_line" =~ ^[[:space:]]*TOKEN= ]]; then
|
|
runner_token="${token_line#*=}"
|
|
fi
|
|
done <<< "$runner_token"
|
|
fi
|
|
: "${runner_token:?Runner registration token is missing}"
|
|
|
|
token_hash_file="$instance_dir/.token-hash"
|
|
token_hash_current="$(printf '%s' "$runner_token" | sha256sum | cut -d' ' -f1)"
|
|
token_hash_stored="$(cat "$token_hash_file" 2>/dev/null || echo "")"
|
|
labels_file="$instance_dir/.labels"
|
|
labels_wanted="$(printf '%s\n' "$@" | sort)"
|
|
labels_current="$(cat "$labels_file" 2>/dev/null || echo 0)"
|
|
|
|
if [ ! -e "$instance_dir/.runner" ] || [ "$labels_wanted" != "$labels_current" ] || [ "$token_hash_current" != "$token_hash_stored" ]; then
|
|
rm -v "$instance_dir/.runner" || true
|
|
|
|
gitea-runner register --no-interactive \
|
|
--instance "$runner_url" \
|
|
--token "$runner_token" \
|
|
--name "jeeves-$(hostname)" \
|
|
--labels "$runner_labels" \
|
|
--config "$runner_config_file"
|
|
|
|
printf '%s' "$token_hash_current" > "$token_hash_file"
|
|
printf '%s\n' "$labels_wanted" > "$labels_file"
|
|
fi
|