Files
hercules-hyperion/scripts/ci/build-package.sh
Yvan Janssens 741c029a1b
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Fix CI package helper path handling
2026-05-05 09:57:44 +02:00

98 lines
2.8 KiB
Bash
Executable File

#!/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="$artifacts_dir/package.env"
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"
if [[ "$raw_package_path" != "$artifact_path" ]]; then
cp "$raw_package_path" "$artifact_path"
fi
cat >"$metadata_file" <<EOF
PACKAGE_FILE=$artifact_path
PACKAGE_NAME=$package_name
PACKAGE_VERSION=$package_version
PACKAGE_ARCHITECTURE=$package_arch
PACKAGE_DISTRIBUTION=${DEBIAN_DISTRIBUTION:-$DEFAULT_DEBIAN_DISTRIBUTION}
PACKAGE_COMPONENT=${DEBIAN_COMPONENT:-$DEFAULT_DEBIAN_COMPONENT}
EOF
log "Built package artifact: $artifact_path"