Files
hercules-hyperion/scripts/lib/common.sh
Yvan Janssens f3ee735362
Some checks failed
ci/woodpecker/push/woodpecker/4 Pipeline was successful
ci/woodpecker/push/woodpecker/2 Pipeline was successful
ci/woodpecker/push/woodpecker/3 Pipeline was successful
ci/woodpecker/push/woodpecker/5 Pipeline was successful
ci/woodpecker/push/woodpecker/1 Pipeline was successful
ci/woodpecker/push/woodpecker/6 Pipeline was successful
ci/woodpecker/manual/woodpecker/1 Pipeline failed
ci/woodpecker/manual/woodpecker/2 Pipeline was successful
ci/woodpecker/manual/woodpecker/6 Pipeline was successful
ci/woodpecker/manual/woodpecker/4 Pipeline was successful
ci/woodpecker/manual/woodpecker/3 Pipeline was successful
ci/woodpecker/manual/woodpecker/5 Pipeline was successful
Skip CI builds for existing packages
2026-05-05 12:35:23 +02:00

128 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
log() {
printf '[%s] %s\n' "$(basename "$0")" "$*"
}
die() {
printf '[%s] %s\n' "$(basename "$0")" "$*" >&2
exit 1
}
detect_debian_distribution_id() {
local os_release="/etc/os-release"
local distro_id=""
local lsb_id=""
if [[ -r "$os_release" ]]; then
# shellcheck disable=SC1090
. "$os_release"
distro_id="${ID:-}"
fi
if [[ -n "$distro_id" ]]; then
case "$distro_id" in
ubuntu|debian)
printf '%s\n' "$distro_id"
return 0
;;
esac
fi
if command -v lsb_release >/dev/null 2>&1; then
lsb_id="$(lsb_release -is | tr '[:upper:]' '[:lower:]')"
case "$lsb_id" in
ubuntu|debian)
printf '%s\n' "$lsb_id"
return 0
;;
esac
fi
die "Unable to determine Debian/Ubuntu distribution ID from $os_release"
}
detect_debian_distribution() {
local os_release="/etc/os-release"
local distro_id=""
local version_codename=""
local ubuntu_codename=""
if [[ -r "$os_release" ]]; then
# shellcheck disable=SC1090
. "$os_release"
distro_id="${ID:-}"
version_codename="${VERSION_CODENAME:-}"
ubuntu_codename="${UBUNTU_CODENAME:-}"
fi
case "$distro_id" in
ubuntu)
if [[ -n "$ubuntu_codename" ]]; then
printf '%s\n' "$ubuntu_codename"
return 0
fi
;;
debian)
if [[ -n "$version_codename" ]]; then
printf '%s\n' "$version_codename"
return 0
fi
;;
esac
if [[ -n "$version_codename" ]]; then
printf '%s\n' "$version_codename"
return 0
fi
if command -v lsb_release >/dev/null 2>&1; then
lsb_release -cs
return 0
fi
die "Unable to determine Debian/Ubuntu distribution codename from $os_release"
}
readonly REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
readonly BUILD_CONFIG_FILE="${BUILD_CONFIG_FILE:-$REPO_ROOT/build.config}"
readonly DEFAULT_GITEA_BASE_URL="https://git.cyber.gent"
readonly DEFAULT_DEBIAN_DISTRIBUTION="$(detect_debian_distribution)"
readonly DEFAULT_DEBIAN_COMPONENT="main"
readonly DEFAULT_CI_WORK_ROOT="$REPO_ROOT/.ci-work"
require_cmd() {
command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1"
}
require_env() {
local name="$1"
[[ -n "${!name:-}" ]] || die "Required environment variable is missing: $name"
}
load_build_config() {
[[ -f "$BUILD_CONFIG_FILE" ]] || die "Build config not found: $BUILD_CONFIG_FILE"
set -a
# shellcheck disable=SC1090
. "$BUILD_CONFIG_FILE"
set +a
[[ -n "${REPO:-}" ]] || die "REPO is missing in $BUILD_CONFIG_FILE"
[[ -n "${BRANCH:-}" ]] || die "BRANCH is missing in $BUILD_CONFIG_FILE"
}
ci_work_root() {
printf '%s\n' "${CI_WORK_ROOT:-$DEFAULT_CI_WORK_ROOT}"
}
ci_artifacts_dir() {
printf '%s/artifacts\n' "$(ci_work_root)"
}
ci_metadata_file() {
printf '%s/package.env\n' "$(ci_artifacts_dir)"
}