#!/usr/bin/env bash set -euo pipefail source "$(cd "$(dirname "$0")/.." && pwd)/lib/common.sh" require_cmd bash require_cmd dpkg-deb require_cmd git load_build_config work_root="$(ci_work_root)" helper_dir="$work_root/hercules-helper" artifacts_dir="$work_root/artifacts" build_path="/home/bill/hyperion-build-package" metadata_file="$(ci_metadata_file)" if [[ -f "$metadata_file" ]]; then set -a # shellcheck disable=SC1090 . "$metadata_file" set +a if [[ "${SKIP_PACKAGE_BUILD:-false}" == "true" ]]; then log "Skipping package build because the package already exists in Gitea" exit 0 fi fi log "Preparing CI work root at $work_root" rm -rf "$work_root" mkdir -p "$artifacts_dir" log "Cloning helper repo $REPO (branch: $BRANCH)" git clone --depth 1 --branch "$BRANCH" "$REPO" "$helper_dir" helper_entrypoint="" if [[ -f "$helper_dir/packagers/debian/create-package-hyperion.sh" ]]; then helper_entrypoint="$helper_dir/packagers/debian/create-package-hyperion.sh" elif [[ -f "$helper_dir/create-package-hyperion.sh" ]]; then helper_entrypoint="$helper_dir/create-package-hyperion.sh" else die "No Hyperion package entrypoint found in $helper_dir" fi compat_template_dir="$helper_dir/packagers/debian/hyperion-4.4" if [[ -d "$helper_dir/packagers/debian/hercules-hyperion" ]] && [[ ! -e "$compat_template_dir" ]]; then ln -s "hercules-hyperion" "$compat_template_dir" fi mkdir -p /home/bill rm -rf "$build_path" mkdir -p "$build_path" log "Invoking helper repo Debian package script" ( cd "$helper_dir" env \ opt_prompts=false \ opt_beeps=false \ opt_verbose=true \ TRACE=false \ build_path="$build_path" \ OUTPUT_DIR="$artifacts_dir" \ bash "$helper_entrypoint" ) artifact_candidates=() while IFS= read -r candidate; do artifact_candidates+=("$candidate") done < <( find "$artifacts_dir" -maxdepth 1 -type f -name '*.deb' 2>/dev/null | sort ) if (( ${#artifact_candidates[@]} == 0 )); then while IFS= read -r candidate; do artifact_candidates+=("$candidate") done < <( find "$build_path" -maxdepth 1 -type f -name '*.deb' 2>/dev/null | sort ) fi (( ${#artifact_candidates[@]} > 0 )) || die "Expected package was not created under $artifacts_dir or $build_path" raw_package_path="${artifact_candidates[0]}" if (( ${#artifact_candidates[@]} > 1 )); then raw_package_path="${artifact_candidates[-1]}" fi 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" fi cat >"$metadata_file" <