Files
azy5030-overlay/scripts/bump-version.sh
T
azy5030 ee9cca3d81
CI / build (push) Failing after 5m27s
fix(bump): preserve GITHUB_SERVER_URL scheme when cloning
The Gitea runner's GITHUB_SERVER_URL is the internal http endpoint
(http://172.17.0.1:3000); hard-coding https:// in the clone URL caused a TLS
error. Derive the scheme from GITHUB_SERVER_URL, and use the public host for
the PR-body vendor link.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 20:59:08 -05:00

132 lines
5.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Check upstream gitea/runner releases and, if a newer version exists than the
# newest gitea-runner ebuild, generate + upload a vendor tarball, bump the
# ebuild, regenerate the Manifest, and open a pull request.
#
# Expects a Gentoo environment with: go, pkgdev, git, curl, xz, jq.
# Required env: BUMP_TOKEN, GITHUB_SERVER_URL, GITHUB_REPOSITORY.
# Optional env: GITHUB_API_URL (defaults to ${GITHUB_SERVER_URL}/api/v1).
set -euo pipefail
PN="gitea-runner"
UPSTREAM_RSS="https://gitea.com/gitea/runner/releases.rss"
UPSTREAM_ARCHIVE="https://gitea.com/gitea/runner/archive"
UPSTREAM_GOMOD="https://gitea.com/gitea/runner/raw/tag"
: "${BUMP_TOKEN:?BUMP_TOKEN is required}"
: "${GITHUB_SERVER_URL:?GITHUB_SERVER_URL is required}"
: "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}"
API="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
# Preserve the scheme of GITHUB_SERVER_URL — on a Gitea runner this is the
# internal endpoint (e.g. http://172.17.0.1:3000), which speaks plain HTTP.
scheme="${GITHUB_SERVER_URL%%://*}"
host="${GITHUB_SERVER_URL#*://}"
api() { curl -fsSL -H "Authorization: token ${BUMP_TOKEN}" "$@"; }
# --- determine versions ------------------------------------------------------
latest=$(curl -fsSL "$UPSTREAM_RSS" \
| grep -oE '<title>v[0-9]+\.[0-9]+\.[0-9]+</title>' \
| head -1 | sed -E 's#</?title>##g; s/^v//')
[ -n "$latest" ] || { echo "could not parse upstream version"; exit 1; }
WORK=$(mktemp -d)
git clone "${scheme}://x-access-token:${BUMP_TOKEN}@${host}/${GITHUB_REPOSITORY}.git" "$WORK"
cd "$WORK"
pkgdir="dev-util/${PN}"
current=$(find "$pkgdir" -name "${PN}-*.ebuild" \
| sed -E "s#.*/${PN}-(.*)\.ebuild#\1#" | sort -V | tail -1)
echo "upstream=${latest} current=${current}"
newest=$(printf '%s\n%s\n' "$current" "$latest" | sort -V | tail -1)
if [ "$newest" = "$current" ] && [ "$latest" != "$current" ]; then
echo "current ($current) is newer than upstream ($latest); nothing to do"; exit 0
fi
[ "$latest" != "$current" ] || { echo "already at latest ($current)"; exit 0; }
branch="bump/${PN}-${latest}"
if api "${API}/repos/${GITHUB_REPOSITORY}/branches/${branch}" >/dev/null 2>&1; then
echo "branch ${branch} already exists; nothing to do"; exit 0
fi
echo "bumping ${PN}: ${current} -> ${latest}"
# --- generate + upload the vendor tarball ------------------------------------
dist=$(mktemp -d)
curl -fsSL "${UPSTREAM_ARCHIVE}/v${latest}.tar.gz" -o "${dist}/${PN}-${latest}.tar.gz"
tar xzf "${dist}/${PN}-${latest}.tar.gz" -C "$dist"
( cd "${dist}/runner" && go mod vendor )
XZ_OPT=-9 tar --sort=name --mtime='UTC 1970-01-01' --owner=0 --group=0 --numeric-owner \
--create --auto-compress --file "${dist}/${PN}-${latest}-vendor.tar.xz" \
-C "$dist" runner/vendor
vendor_tag="${PN}-${latest}-vendor"
rel_id=$(api "${API}/repos/${GITHUB_REPOSITORY}/releases/tags/${vendor_tag}" 2>/dev/null \
| jq -r '.id // empty' || true)
if [ -z "$rel_id" ]; then
rel_id=$(api -X POST -H 'Content-Type: application/json' \
"${API}/repos/${GITHUB_REPOSITORY}/releases" \
-d "{\"tag_name\":\"${vendor_tag}\",\"target_commitish\":\"master\",\"name\":\"${vendor_tag}\",\"body\":\"Vendored Go modules for ${PN} ${latest}.\"}" \
| jq -r '.id')
fi
api -X POST -H 'Content-Type: multipart/form-data' \
-F "attachment=@${dist}/${PN}-${latest}-vendor.tar.xz" \
"${API}/repos/${GITHUB_REPOSITORY}/releases/${rel_id}/assets?name=${PN}-${latest}-vendor.tar.xz" \
>/dev/null
# --- bump the ebuild ---------------------------------------------------------
git config user.name "gitea-actions"
git config user.email "actions@azy.dev"
git checkout -b "$branch"
git mv "${pkgdir}/${PN}-${current}.ebuild" "${pkgdir}/${PN}-${latest}.ebuild"
# Track the upstream go.mod's required Go version in BDEPEND.
goreq=$(curl -fsSL "${UPSTREAM_GOMOD}/v${latest}/go.mod" \
| grep -oE '^go [0-9]+\.[0-9]+(\.[0-9]+)?' | awk '{print $2}')
[ -n "$goreq" ] && sed -i -E \
"s#^BDEPEND=\">=dev-lang/go-[0-9.]+\"#BDEPEND=\">=dev-lang/go-${goreq}\"#" \
"${pkgdir}/${PN}-${latest}.ebuild"
# Regenerate the Manifest (pkgdev fetches distfiles into DISTDIR first).
mkdir -p /var/cache/distfiles
cp "${dist}/${PN}-${latest}.tar.gz" /var/cache/distfiles/
cp "${dist}/${PN}-${latest}-vendor.tar.xz" /var/cache/distfiles/
mkdir -p /etc/portage/repos.conf
printf '[DEFAULT]\nmain-repo = gentoo\n\n[gentoo]\nlocation = /var/db/repos/gentoo\n' \
> /etc/portage/repos.conf/gentoo.conf
printf '[azy5030]\nlocation = %s\nmasters = gentoo\nauto-sync = false\n' "$WORK" \
> /etc/portage/repos.conf/azy5030.conf
( cd "${pkgdir}" && pkgdev manifest )
# --- validate, commit, push, open PR ----------------------------------------
pkgcheck scan --repo "$WORK" "${pkgdir}" || true
mkdir -p /etc/portage/package.accept_keywords
echo 'dev-util/gitea-runner ~amd64' > /etc/portage/package.accept_keywords/gitea-runner
emerge -v --getbinpkg "=dev-util/${PN}-${latest}"
gitea-runner --version | grep -q "v${latest}"
git add -A
git commit -m "dev-util/${PN}: bump to ${latest}"
git push origin "$branch"
body=$(cat <<EOF
Automated bump of \`dev-util/${PN}\` from ${current} to ${latest}.
- Upstream release: https://gitea.com/gitea/runner/releases/tag/v${latest}
- Vendor tarball: https://git.azy.dev/${GITHUB_REPOSITORY}/releases/tag/${vendor_tag}
Review checklist:
- [ ] LICENSE still covers all vendored module licenses (\`go-licenses report ./...\`)
- [ ] BDEPEND Go version matches upstream go.mod (set to >=${goreq:-unchanged})
- [ ] version ldflags path \`internal/pkg/ver.version\` unchanged upstream
CI build + \`gitea-runner --version\` passed in this workflow.
EOF
)
api -X POST -H 'Content-Type: application/json' \
"${API}/repos/${GITHUB_REPOSITORY}/pulls" \
-d "$(jq -n --arg h "$branch" --arg t "dev-util/${PN}: bump to ${latest}" --arg b "$body" \
'{head:$h, base:"master", title:$t, body:$b}')" \
| jq -r '"opened PR #\(.number): \(.html_url)"'