#!/usr/bin/env bash # Attach files to an existing Gitea release, found by tag. Re-runnable: an # asset of the same name is replaced. Use this to add a build CI can't produce # (e.g., the macOS arm64 bundle, built on a Mac) to a release CI already made. # # Required env: # GITEA_API e.g., https://git.scient.ing/api/v1/repos// # GITEA_TOKEN a token with contents:write # TAG the release tag the assets belong to # ASSETS space-separated list of files to upload # Optional env: # JQ jq command (default: jq); on a Mac without jq, set to # "pixi exec --spec jq -- jq" set -euo pipefail : "${GITEA_API:?}"; : "${GITEA_TOKEN:?}"; : "${TAG:?}"; : "${ASSETS:?}" : "${JQ:=jq}" auth="Authorization: token ${GITEA_TOKEN}" rid="$(curl -fsSL -H "$auth" "${GITEA_API}/releases/tags/${TAG}" | $JQ -r '.id')" [ -n "$rid" ] && [ "$rid" != "null" ] || { echo "no release found for tag ${TAG}" >&2; exit 1; } for f in $ASSETS; do n="$(basename "$f")" for aid in $(curl -fsSL -H "$auth" "${GITEA_API}/releases/${rid}/assets" \ | $JQ -r --arg n "$n" '.[] | select(.name==$n) | .id'); do curl -fsSL -X DELETE -H "$auth" "${GITEA_API}/releases/${rid}/assets/${aid}" || true done echo "uploading $n to release ${TAG}" curl -fsSL -X POST -H "$auth" -F "attachment=@${f}" \ "${GITEA_API}/releases/${rid}/assets?name=${n}" done