Files
s3-gateway/ci/publish-release.sh
T
William GillandClaude Opus 4.8 6b35d863c9 Initial s3-gateway de-brand build pipeline
ScoutFS-Build-style pipeline that pulls upstream versitygw release tags, applies the web-UI de-brand patch series, and builds GoReleaser releases (binaries + deb/rpm) for publishing to Gitea. Artifact names stay versitygw; only the embedded admin UI is rebranded to S3 Gateway.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 13:20:15 -05:00

65 lines
2.8 KiB
Bash

#!/bin/bash
# Publish built artifacts to a Gitea release in the s3-gateway repo.
# Idempotent: re-running for the same tag replaces existing assets.
#
# Environment:
# GITEA_API_URL e.g. https://git.anomalous.dev/api/v1 (required)
# GITEA_OWNER e.g. alphacentri (required)
# GITEA_REPO e.g. s3-gateway (required)
# GITEA_TOKEN API token with repo write scope (required)
# VGW_TAG upstream tag being published (required)
# VGW_DIST_DIR artifact dir (default: <VGW_SRC_DIR>/dist)
# RELEASE_TAG git tag for the release (default: VGW_TAG)
# RELEASE_TARGET target commitish for the tag (default: main)
# RELEASE_NOTE release body (default: auto)
set -euo pipefail
: "${GITEA_API_URL:?}"; : "${GITEA_OWNER:?}"; : "${GITEA_REPO:?}"; : "${GITEA_TOKEN:?}"
: "${VGW_TAG:?VGW_TAG must be set}"
DIST="${VGW_DIST_DIR:-${VGW_SRC_DIR:-src}/dist}"
RELEASE_TAG="${RELEASE_TAG:-${VGW_TAG}}"
RELEASE_TARGET="${RELEASE_TARGET:-main}"
RELEASE_NOTE="${RELEASE_NOTE:-De-branded versitygw ${VGW_TAG} build.}"
API="${GITEA_API_URL%/}/repos/${GITEA_OWNER}/${GITEA_REPO}"
auth=(-H "Authorization: token ${GITEA_TOKEN}")
echo ">>> ensuring release ${RELEASE_TAG} in ${GITEA_OWNER}/${GITEA_REPO}..."
rel_id="$(curl -fsSL "${auth[@]}" "${API}/releases/tags/${RELEASE_TAG}" 2>/dev/null \
| jq -r '.id // empty' || true)"
if [[ -z "${rel_id}" ]]; then
echo ">>> creating release ${RELEASE_TAG}"
rel_id="$(curl -fsSL "${auth[@]}" -H 'Content-Type: application/json' \
-X POST "${API}/releases" \
-d "$(jq -n --arg tag "$RELEASE_TAG" --arg tgt "$RELEASE_TARGET" \
--arg name "$RELEASE_TAG" --arg body "$RELEASE_NOTE" \
'{tag_name:$tag, target_commitish:$tgt, name:$name, body:$body, draft:false, prerelease:false}')" \
| jq -r '.id')"
else
echo ">>> release ${RELEASE_TAG} already exists (id ${rel_id})"
fi
shopt -s nullglob
assets=( "${DIST}"/*.tar.gz "${DIST}"/*.zip "${DIST}"/*.deb "${DIST}"/*.rpm "${DIST}"/checksums.txt )
shopt -u nullglob
(( ${#assets[@]} )) || { echo "ERROR: no artifacts in ${DIST}" >&2; exit 1; }
existing="$(curl -fsSL "${auth[@]}" "${API}/releases/${rel_id}/assets" || echo '[]')"
for f in "${assets[@]}"; do
name="$(basename "$f")"
old="$(echo "$existing" | jq -r --arg n "$name" '.[] | select(.name==$n) | .id' 2>/dev/null || true)"
if [[ -n "$old" ]]; then
echo ">>> replacing asset ${name}"
curl -fsSL "${auth[@]}" -X DELETE "${API}/releases/${rel_id}/assets/${old}" >/dev/null
else
echo ">>> uploading asset ${name}"
fi
curl -fsSL "${auth[@]}" -F "attachment=@${f}" \
"${API}/releases/${rel_id}/assets?name=${name}" >/dev/null
done
echo ">>> published ${#assets[@]} artifact(s) to release ${RELEASE_TAG}"