diff --git a/.woodpecker.yml b/.woodpecker.yml index f96344a..2113bf7 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,5 +1,18 @@ steps: - - name: build-and-upload-debian-package + - name: build-and-upload-debian-package-ubuntu-22-04 + image: ubuntu:22.04 + pull: true + environment: + GITEA_PACKAGE_TOKEN: + from_secret: gitea_token + commands: + - ./scripts/ci/bootstrap-apt.sh + - ./scripts/ci/build-package.sh + - ./scripts/ci/upload-package.sh + when: + - event: [push, cron, manual] + + - name: build-and-upload-debian-package-ubuntu-24-04 image: ubuntu:24.04 pull: true environment: @@ -11,3 +24,55 @@ steps: - ./scripts/ci/upload-package.sh when: - event: [push, cron, manual] + + - name: build-and-upload-debian-package-ubuntu-26-04 + image: ubuntu:26.04 + pull: true + environment: + GITEA_PACKAGE_TOKEN: + from_secret: gitea_token + commands: + - ./scripts/ci/bootstrap-apt.sh + - ./scripts/ci/build-package.sh + - ./scripts/ci/upload-package.sh + when: + - event: [push, cron, manual] + + - name: build-and-upload-debian-package-debian-12 + image: debian:12 + pull: true + environment: + GITEA_PACKAGE_TOKEN: + from_secret: gitea_token + commands: + - ./scripts/ci/bootstrap-apt.sh + - ./scripts/ci/build-package.sh + - ./scripts/ci/upload-package.sh + when: + - event: [push, cron, manual] + + - name: build-and-upload-debian-package-debian-13 + image: debian:13 + pull: true + environment: + GITEA_PACKAGE_TOKEN: + from_secret: gitea_token + commands: + - ./scripts/ci/bootstrap-apt.sh + - ./scripts/ci/build-package.sh + - ./scripts/ci/upload-package.sh + when: + - event: [push, cron, manual] + + - name: build-and-upload-debian-package-debian-11 + image: debian:11 + pull: true + environment: + GITEA_PACKAGE_TOKEN: + from_secret: gitea_token + commands: + - ./scripts/ci/bootstrap-apt.sh + - ./scripts/ci/build-package.sh + - ./scripts/ci/upload-package.sh + when: + - event: [push, cron, manual] diff --git a/scripts/ci/bootstrap-apt.sh b/scripts/ci/bootstrap-apt.sh index cb932fd..37ddc1a 100755 --- a/scripts/ci/bootstrap-apt.sh +++ b/scripts/ci/bootstrap-apt.sh @@ -2,15 +2,40 @@ set -euo pipefail +source "$(cd "$(dirname "$0")/.." && pwd)/lib/common.sh" + export DEBIAN_FRONTEND=noninteractive +distribution_id="$(detect_debian_distribution_id)" +distribution_codename="$(detect_debian_distribution)" +refresh_package_indexes=false + +log "Bootstrapping APT packages for $distribution_id:$distribution_codename" + printf 'Acquire::http::Proxy "http://cbrapt01.lan.cyber.gent:3142";\n' >/etc/apt/apt.conf.d/80proxy apt-get update apt-get upgrade -y apt-get install -y --no-install-recommends build-essential -apt-get install -y --no-install-recommends software-properties-common -add-apt-repository -y universe -apt-get update + +case "$distribution_id" in + ubuntu) + apt-get install -y --no-install-recommends software-properties-common + if ! grep -RqsE '(^|[[:space:]])universe([[:space:]]|$)' /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null; then + add-apt-repository -y universe + refresh_package_indexes=true + fi + ;; + debian) + ;; + *) + die "Unsupported distribution ID: $distribution_id" + ;; +esac + +if [[ "$refresh_package_indexes" == true ]]; then + apt-get update +fi + apt-get install -y --no-install-recommends \ autoconf \ automake \ diff --git a/scripts/ci/build-package.sh b/scripts/ci/build-package.sh index 64f6f20..1e5e6c4 100755 --- a/scripts/ci/build-package.sh +++ b/scripts/ci/build-package.sh @@ -80,6 +80,7 @@ package_name="$(dpkg-deb -f "$raw_package_path" Package)" package_version="$(dpkg-deb -f "$raw_package_path" Version)" package_arch="$(dpkg-deb -f "$raw_package_path" Architecture)" artifact_path="$artifacts_dir/${package_name}_${package_version}_${package_arch}.deb" +package_distribution="${DEBIAN_DISTRIBUTION:-$(detect_debian_distribution)}" if [[ "$raw_package_path" != "$artifact_path" ]]; then cp "$raw_package_path" "$artifact_path" @@ -90,7 +91,7 @@ PACKAGE_FILE=$artifact_path PACKAGE_NAME=$package_name PACKAGE_VERSION=$package_version PACKAGE_ARCHITECTURE=$package_arch -PACKAGE_DISTRIBUTION=${DEBIAN_DISTRIBUTION:-$DEFAULT_DEBIAN_DISTRIBUTION} +PACKAGE_DISTRIBUTION=$package_distribution PACKAGE_COMPONENT=${DEBIAN_COMPONENT:-$DEFAULT_DEBIAN_COMPONENT} EOF diff --git a/scripts/lib/common.sh b/scripts/lib/common.sh index 275bf46..da92a37 100755 --- a/scripts/lib/common.sh +++ b/scripts/lib/common.sh @@ -2,13 +2,6 @@ set -euo pipefail -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="noble" -readonly DEFAULT_DEBIAN_COMPONENT="main" -readonly DEFAULT_CI_WORK_ROOT="$REPO_ROOT/.ci-work" - log() { printf '[%s] %s\n' "$(basename "$0")" "$*" } @@ -18,6 +11,88 @@ die() { 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" }