Upload each build's RPMs to the forge's RPM registry
All checks were successful
Build Aurora / build (push) Successful in 3m58s
All checks were successful
Build Aurora / build (push) Successful in 3m58s
.forgejo/upload-rpms.sh, from the rpm-mirror-test branch: a group per upstream repository, packages already there skipped. Best effort: the step never fails the build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
36b34ba66c
commit
85726d8def
1 changed files with 47 additions and 0 deletions
47
.forgejo/upload-rpms.sh
Executable file
47
.forgejo/upload-rpms.sh
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env bash
|
||||
# Uploads the RPMs a build downloaded (its dnf cache, kept by
|
||||
# Containerfile.in's cache mounts) to this forge's RPM registry, one group
|
||||
# per upstream repository: fedora, updates, terra, copr-ublue-os-packages...
|
||||
# Each group is a dnf repository at
|
||||
# https://forge.quinefoundation.com/api/packages/quine-global-labs/rpm/<group>.
|
||||
#
|
||||
# Usage: upload-rpms.sh CACHE_DIR (a libdnf5 cache: one directory per
|
||||
# repository, <repo id>-<hash>/packages/*.rpm)
|
||||
#
|
||||
# Needs REGISTRY_USER and REGISTRY_TOKEN (package write access). Packages
|
||||
# the registry already has are skipped (409). Best effort: a failed upload
|
||||
# is a warning, not a failure.
|
||||
set -euo pipefail
|
||||
|
||||
cache=$1
|
||||
api=${RPM_API:-https://forge.quinefoundation.com/api/packages/quine-global-labs/rpm}
|
||||
|
||||
# The token goes to curl in a file, not on its command line.
|
||||
netrc=$(mktemp)
|
||||
trap 'rm -f "$netrc"' EXIT
|
||||
chmod 600 "$netrc"
|
||||
printf 'machine %s login %s password %s\n' \
|
||||
"$(sed -E 's|^https?://([^/]+).*|\1|' <<<"$api")" "$REGISTRY_USER" "$REGISTRY_TOKEN" >"$netrc"
|
||||
|
||||
upload() { # group rpm
|
||||
local code
|
||||
code=$(curl -sS -o /dev/null -w '%{http_code}' --retry 3 --netrc-file "$netrc" \
|
||||
--upload-file "$2" "$api/$1/upload") || code=000
|
||||
case $code in
|
||||
201) echo "new $1 ${2##*/}" ;;
|
||||
409) echo "had $1 ${2##*/}" ;;
|
||||
*) echo "::warning::$code uploading ${2##*/} to $1" ;;
|
||||
esac
|
||||
}
|
||||
export -f upload
|
||||
export api netrc
|
||||
|
||||
for dir in "$cache"/*/; do
|
||||
id=$(basename "$dir")
|
||||
id=${id%-*} # the hash libdnf5 appends
|
||||
[[ $id == @* ]] && continue # @commandline: local files, not a repository
|
||||
# copr:copr.fedorainfracloud.org:ublue-os:packages -> copr-ublue-os-packages
|
||||
group=$(sed -E 's/^copr:[^:]+:/copr-/; s/:/-/g' <<<"$id")
|
||||
find "$dir" -name '*.rpm' -printf "$group\0%p\0"
|
||||
done | xargs -0 -n 2 -P 4 bash -c 'upload "$@"' _ |
|
||||
tee /dev/stderr | awk '{n[$1]++} END {for (k in n) printf "%s: %d\n", k, n[k]}'
|
||||
Loading…
Reference in a new issue