From 85726d8def330c0594c300868e5c14c3428a0714 Mon Sep 17 00:00:00 2001 From: Philip Peterson <1326208+philip-peterson@users.noreply.github.com> Date: Sat, 31 Oct 2026 00:43:12 -0800 Subject: [PATCH] Upload each build's RPMs to the forge's RPM registry .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 --- .forgejo/upload-rpms.sh | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 .forgejo/upload-rpms.sh diff --git a/.forgejo/upload-rpms.sh b/.forgejo/upload-rpms.sh new file mode 100755 index 00000000..30bbf34b --- /dev/null +++ b/.forgejo/upload-rpms.sh @@ -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/. +# +# Usage: upload-rpms.sh CACHE_DIR (a libdnf5 cache: one directory per +# repository, -/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]}'