Files
alpine-packages/scripts/apk/publish-gitea.sh
T
Joachim Schlöffel caf722905b
Build Alpine Packages / preflight (pull_request) Successful in 10s
Build Alpine Packages / build (gitea) (pull_request) Successful in 58s
Build Alpine Packages / build (greptimedb) (pull_request) Successful in 1h9m44s
Build Alpine Packages / build (lavinmq) (pull_request) Successful in 2m21s
Build Alpine Packages / build (nifi) (pull_request) Successful in 6m55s
Build Alpine Packages / build (rclone-openrc) (pull_request) Successful in 15s
Build Alpine Packages / build (seaweedfs) (pull_request) Successful in 33m28s
Build Alpine Packages / verify-and-publish (pull_request) Failing after 6m29s
trigger package rebuild
2026-10-22 09:33:43 +02:00

153 lines
4.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# shellcheck source=scripts/apk/package-lib.sh
. "${repo_root}/scripts/apk/package-lib.sh"
repo_name="${ALPINE_REPO_NAME:-local}"
alpine_version="${ALPINE_VERSION:-3.24}"
arches="${ALPINE_ARCHES:-x86_64 aarch64}"
branch="${ALPINE_REGISTRY_BRANCH:-v${alpine_version}}"
repository="${ALPINE_REGISTRY_REPOSITORY:-${PACKAGE_NAME:-main}}"
instance_url="${INSTANCE_URL:-}"
owner="${PACKAGE_OWNER:-}"
user="${PACKAGE_USER:-}"
token="${PACKAGE_TOKEN:-}"
allow_conflicts="${GITEA_APK_ALLOW_CONFLICTS:-1}"
require_env() {
local name="$1"
local value="$2"
if [[ -z "${value}" ]]; then
printf 'missing required environment variable: %s\n' "${name}" >&2
exit 2
fi
}
require_env INSTANCE_URL "${instance_url}"
require_env PACKAGE_OWNER "${owner}"
require_env PACKAGE_USER "${user}"
require_env PACKAGE_TOKEN "${token}"
instance_url="${instance_url%/}"
upload_url="${instance_url}/api/packages/${owner}/alpine/${branch}/${repository}"
package_root="${repo_root}/packages/${repo_name}"
if [[ ! -d "${package_root}" ]]; then
printf 'missing local package repository: %s\n' "${package_root}" >&2
printf 'run: mise run apk:build-all\n' >&2
exit 1
fi
shopt -s nullglob
apks=("${package_root}"/*/*.apk)
shopt -u nullglob
if [[ "${#apks[@]}" -eq 0 ]]; then
printf 'no APK files found under %s\n' "${package_root}" >&2
exit 1
fi
declare -A expected_apks=()
declare -A package_names=()
while IFS= read -r package_dir; do
apk_validate_package_dir "${package_dir}"
for arch in ${arches}; do
if ! apk_package_supports_arch "${package_dir}" "${arch}"; then
continue
fi
while IFS= read -r apk_name; do
expected_apks["${package_root}/${arch}/${apk_name}"]=1
done < <(apk_package_apk_names "${package_dir}" "${arch}")
while IFS= read -r package_version; do
package_names["${package_version%%=*}"]=1
done < <(apk_package_versioned_names "${package_dir}" "${arch}")
done
done < <(apk_all_package_dirs "${repo_root}")
current_apks=()
stale_count=0
for apk in "${apks[@]}"; do
if [[ -z "${expected_apks[${apk}]:-}" ]]; then
printf 'Skipping stale local APK: %s\n' "${apk#"${repo_root}/"}"
stale_count=$((stale_count + 1))
continue
fi
current_apks+=("${apk}")
done
if [[ "${#current_apks[@]}" -eq 0 ]]; then
printf 'no current APK files found under %s\n' "${package_root}" >&2
exit 1
fi
printf 'Publishing %d APK files to %s\n' "${#current_apks[@]}" "${upload_url}"
if [[ "${stale_count}" -ne 0 ]]; then
printf 'Skipping %d stale local APK file(s)\n' "${stale_count}"
fi
for apk in "${current_apks[@]}"; do
filename="$(basename "${apk}")"
status="$(
curl --silent --show-error --location \
--user "${user}:${token}" \
--upload-file "${apk}" \
--write-out '%{http_code}' \
--output /tmp/gitea-apk-publish-response \
"${upload_url}"
)"
case "${status}" in
201)
printf 'published: %s\n' "${filename}"
;;
409)
if [[ "${allow_conflicts}" == "1" ]]; then
printf 'already exists: %s\n' "${filename}"
else
printf 'conflict: %s already exists\n' "${filename}" >&2
cat /tmp/gitea-apk-publish-response >&2
exit 1
fi
;;
*)
printf 'publish failed for %s: HTTP %s\n' "${filename}" "${status}" >&2
cat /tmp/gitea-apk-publish-response >&2
exit 1
;;
esac
done
# Alpine's repository path groups registry files, but does not associate package
# records with the Gitea code repository. Link each package explicitly so it is
# visible from the repository's Packages tab as well as the owner package list.
for package_name in "${!package_names[@]}"; do
link_url="${instance_url}/api/v1/packages/${owner}/alpine/${package_name}/-/link/${repository}"
status="$(
curl --silent --show-error --location \
--request POST \
--user "${user}:${token}" \
--write-out '%{http_code}' \
--output /tmp/gitea-apk-link-response \
"${link_url}"
)"
case "${status}" in
201)
printf 'linked to repository: %s\n' "${package_name}"
;;
409)
printf 'already linked to repository: %s\n' "${package_name}"
;;
*)
printf 'repository link failed for %s: HTTP %s\n' "${package_name}" "${status}" >&2
cat /tmp/gitea-apk-link-response >&2
exit 1
;;
esac
done