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
230 lines
6.1 KiB
Bash
230 lines
6.1 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(cd "$(dirname "$0")/.." && pwd)/lib/common.sh"
|
|
|
|
require_cmd awk
|
|
require_cmd curl
|
|
require_cmd dpkg
|
|
require_cmd git
|
|
require_cmd gzip
|
|
|
|
load_build_config
|
|
|
|
work_root="$(ci_work_root)"
|
|
artifacts_dir="$(ci_artifacts_dir)"
|
|
metadata_file="$(ci_metadata_file)"
|
|
helper_dir="$work_root/hercules-helper-preflight"
|
|
hyperion_dir="$work_root/hyperion-preflight"
|
|
|
|
owner="${GITEA_PACKAGE_OWNER:-${CI_REPO_OWNER:-}}"
|
|
username="${GITEA_PACKAGE_USERNAME:-${CI_REPO_OWNER:-}}"
|
|
base_url="${GITEA_BASE_URL:-$DEFAULT_GITEA_BASE_URL}"
|
|
package_distribution="${DEBIAN_DISTRIBUTION:-$(detect_debian_distribution)}"
|
|
package_component="${DEBIAN_COMPONENT:-$DEFAULT_DEBIAN_COMPONENT}"
|
|
package_architecture="$(dpkg --print-architecture)"
|
|
|
|
resolve_helper_template_dir() {
|
|
local template_dir="$1/packagers/debian/hercules-hyperion"
|
|
|
|
if [[ -d "$template_dir" ]]; then
|
|
printf '%s\n' "$template_dir"
|
|
return 0
|
|
fi
|
|
|
|
template_dir="$(
|
|
find "$1/packagers/debian" -mindepth 1 -maxdepth 1 -type d -name 'hyperion-*' \
|
|
| sort -V \
|
|
| tail -n 1
|
|
)"
|
|
|
|
[[ -n "$template_dir" ]] || die "No Hyperion Debian package template directory found under $1/packagers/debian"
|
|
printf '%s\n' "$template_dir"
|
|
}
|
|
|
|
resolve_hyperion_repo_url() {
|
|
printf '%s\n' "${GIT_REPO_HYPERION:-${git_repo_hyperion:-https://github.com/SDL-Hercules-390/hyperion.git}}"
|
|
}
|
|
|
|
resolve_hyperion_repo_branch() {
|
|
printf '%s\n' "${GIT_BRANCH_HYPERION:-${git_branch_hyperion:-}}"
|
|
}
|
|
|
|
resolve_hyperion_repo_commit() {
|
|
printf '%s\n' "${GIT_COMMIT_HYPERION:-${git_commit_hyperion:-}}"
|
|
}
|
|
|
|
clone_repo() {
|
|
local repo_url="$1"
|
|
local repo_dir="$2"
|
|
local repo_branch="${3:-}"
|
|
|
|
rm -rf "$repo_dir"
|
|
|
|
if [[ -n "$repo_branch" ]]; then
|
|
git clone --branch "$repo_branch" "$repo_url" "$repo_dir"
|
|
else
|
|
git clone "$repo_url" "$repo_dir"
|
|
fi
|
|
}
|
|
|
|
determine_hyperion_version() {
|
|
local repo_dir="$1"
|
|
|
|
if [[ -x "$repo_dir/_dynamic_version" ]]; then
|
|
(
|
|
cd "$repo_dir"
|
|
./_dynamic_version . VERSION \
|
|
| awk '{sub("-modified","", $0); print}' \
|
|
| tr -d '"'
|
|
)
|
|
return 0
|
|
fi
|
|
|
|
git -C "$repo_dir" describe --tags --dirty --always 2>/dev/null || echo unknown
|
|
}
|
|
|
|
fetch_package_index() {
|
|
local response_file
|
|
local status_code
|
|
local url
|
|
local suffix
|
|
|
|
response_file="$(mktemp)"
|
|
|
|
for suffix in Packages Packages.gz; do
|
|
url="$base_url/api/packages/$owner/debian/dists/$package_distribution/$package_component/binary-$package_architecture/$suffix"
|
|
status_code="$(
|
|
curl \
|
|
--silent \
|
|
--show-error \
|
|
--location \
|
|
--output "$response_file" \
|
|
--write-out '%{http_code}' \
|
|
--user "$username:$GITEA_PACKAGE_TOKEN" \
|
|
"$url"
|
|
)"
|
|
|
|
case "$status_code" in
|
|
200)
|
|
if [[ "$suffix" == "Packages.gz" ]]; then
|
|
gzip -dc "$response_file"
|
|
else
|
|
cat "$response_file"
|
|
fi
|
|
rm -f "$response_file"
|
|
return 0
|
|
;;
|
|
404)
|
|
;;
|
|
*)
|
|
cat "$response_file" >&2
|
|
rm -f "$response_file"
|
|
die "Package index query failed with HTTP $status_code for $url"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
rm -f "$response_file"
|
|
return 1
|
|
}
|
|
|
|
package_exists_in_index() {
|
|
local package_name="$1"
|
|
local package_version="$2"
|
|
|
|
awk -v target_package="$package_name" -v target_version="$package_version" '
|
|
BEGIN {
|
|
RS = ""
|
|
FS = "\n"
|
|
}
|
|
{
|
|
found_package = 0
|
|
found_version = 0
|
|
for (i = 1; i <= NF; i++) {
|
|
if ($i == "Package: " target_package) {
|
|
found_package = 1
|
|
}
|
|
if ($i == "Version: " target_version) {
|
|
found_version = 1
|
|
}
|
|
}
|
|
if (found_package && found_version) {
|
|
matched = 1
|
|
exit
|
|
}
|
|
}
|
|
END {
|
|
if (matched) {
|
|
exit 0
|
|
}
|
|
exit 1
|
|
}
|
|
'
|
|
}
|
|
|
|
write_metadata() {
|
|
local skip_build="$1"
|
|
local package_name="$2"
|
|
local package_version="$3"
|
|
|
|
mkdir -p "$artifacts_dir"
|
|
|
|
cat >"$metadata_file" <<EOF
|
|
SKIP_PACKAGE_BUILD=$skip_build
|
|
PACKAGE_NAME=$package_name
|
|
PACKAGE_VERSION=$package_version
|
|
PACKAGE_ARCHITECTURE=$package_architecture
|
|
PACKAGE_DISTRIBUTION=$package_distribution
|
|
PACKAGE_COMPONENT=$package_component
|
|
EOF
|
|
}
|
|
|
|
require_env GITEA_PACKAGE_TOKEN
|
|
[[ -n "$owner" ]] || die "Unable to determine Gitea package owner. Set GITEA_PACKAGE_OWNER or CI_REPO_OWNER."
|
|
[[ -n "$username" ]] || die "Unable to determine Gitea package username. Set GITEA_PACKAGE_USERNAME or CI_REPO_OWNER."
|
|
|
|
mkdir -p "$work_root"
|
|
|
|
log "Cloning helper repo $REPO (branch: $BRANCH) for package preflight"
|
|
clone_repo "$REPO" "$helper_dir" "$BRANCH"
|
|
|
|
template_dir="$(resolve_helper_template_dir "$helper_dir")"
|
|
control_file="$template_dir/DEBIAN/control"
|
|
[[ -f "$control_file" ]] || die "Package control file not found: $control_file"
|
|
package_name="$(awk '/^Package:/ {print $2; exit}' "$control_file")"
|
|
[[ -n "$package_name" ]] || die "Unable to determine package name from $control_file"
|
|
|
|
hyperion_repo_url="$(resolve_hyperion_repo_url)"
|
|
hyperion_repo_branch="$(resolve_hyperion_repo_branch)"
|
|
hyperion_repo_commit="$(resolve_hyperion_repo_commit)"
|
|
|
|
log "Cloning Hyperion source repo for version preflight"
|
|
clone_repo "$hyperion_repo_url" "$hyperion_dir" "$hyperion_repo_branch"
|
|
if [[ -n "$hyperion_repo_commit" ]]; then
|
|
git -C "$hyperion_dir" checkout "$hyperion_repo_commit"
|
|
fi
|
|
|
|
package_version="$(determine_hyperion_version "$hyperion_dir")"
|
|
[[ -n "$package_version" ]] || die "Unable to determine package version"
|
|
|
|
log "Checking Gitea for $package_name/$package_version ($package_distribution/$package_component/$package_architecture)"
|
|
package_index_file="$(mktemp)"
|
|
have_package_index=false
|
|
|
|
if fetch_package_index >"$package_index_file"; then
|
|
have_package_index=true
|
|
fi
|
|
|
|
if [[ "$have_package_index" == "true" ]] && package_exists_in_index "$package_name" "$package_version" <"$package_index_file"; then
|
|
rm -f "$package_index_file"
|
|
write_metadata true "$package_name" "$package_version"
|
|
log "Package already exists in registry; build will be skipped"
|
|
exit 0
|
|
fi
|
|
|
|
rm -f "$package_index_file"
|
|
write_metadata false "$package_name" "$package_version"
|
|
log "Package does not exist in registry; build will continue"
|