Gitea runner build failed with "dotnet: command not found". Added ensure_dotnet() to lib.sh, using the vendored dotnet-install.sh to bootstrap the SDK into .dotnet/ when not already on PATH, called from build.sh/test.sh/prepush.sh. Also trigger CI on build-runner-fix to verify the fix.
64 lines
2.2 KiB
Bash
Executable File
64 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Shared helpers for scripts/ci/*.sh.
|
|
# Every script in this directory is meant to run identically in CI and on a
|
|
# developer's machine - no Gitea/GitHub-specific built-in actions, just bash.
|
|
set -euo pipefail
|
|
|
|
log() {
|
|
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] $*"
|
|
}
|
|
|
|
fail() {
|
|
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] ERROR: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
# Repo root, regardless of caller's cwd.
|
|
CI_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
|
|
# Registry configuration. All values come from the environment (CI secrets or
|
|
# a developer's shell) - nothing is hardcoded, per project convention.
|
|
REGISTRY="${REGISTRY:-}"
|
|
REGISTRY_OWNER="${REGISTRY_OWNER:-}"
|
|
REGISTRY_USER="${REGISTRY_USER:-}"
|
|
REGISTRY_TOKEN="${REGISTRY_TOKEN:-}"
|
|
|
|
GIT_SHA="$(git -C "$CI_ROOT" rev-parse --short HEAD)"
|
|
|
|
require_registry_vars() {
|
|
[[ -n "$REGISTRY" ]] || fail "REGISTRY env var is required (e.g. gitea.example.com)"
|
|
[[ -n "$REGISTRY_OWNER" ]] || fail "REGISTRY_OWNER env var is required (e.g. your gitea org/user)"
|
|
}
|
|
|
|
# Populates API_IMAGE / ADMIN_IMAGE, e.g. gitea.example.com/james/miccheck-api
|
|
image_names() {
|
|
require_registry_vars
|
|
API_IMAGE="$REGISTRY/$REGISTRY_OWNER/miccheck-api"
|
|
ADMIN_IMAGE="$REGISTRY/$REGISTRY_OWNER/miccheck-admin"
|
|
}
|
|
|
|
# Installs .NET into $CI_ROOT/.dotnet via the vendored dotnet-install.sh if
|
|
# `dotnet` isn't already on PATH, then prepends it to PATH for this process.
|
|
# Keeps bare runners (no SDK preinstalled) working the same as a dev machine.
|
|
ensure_dotnet() {
|
|
if command -v dotnet > /dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
|
|
local install_dir="$CI_ROOT/.dotnet"
|
|
if [[ ! -x "$install_dir/dotnet" ]]; then
|
|
log "dotnet not found on PATH; installing .NET SDK via dotnet-install.sh"
|
|
bash "$CI_ROOT/dotnet-install.sh" --channel LTS --install-dir "$install_dir"
|
|
fi
|
|
export PATH="$install_dir:$PATH"
|
|
export DOTNET_ROOT="$install_dir"
|
|
}
|
|
|
|
registry_login() {
|
|
require_registry_vars
|
|
[[ -n "$REGISTRY_USER" ]] || fail "REGISTRY_USER env var is required to push images"
|
|
[[ -n "$REGISTRY_TOKEN" ]] || fail "REGISTRY_TOKEN env var is required to push images"
|
|
log "Logging in to $REGISTRY as $REGISTRY_USER"
|
|
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin
|
|
}
|