Files
coursebank/scripts/attach-asset.sh
T
alexm 3a7a0d5873
Pipeline / check (push) Successful in 1m56s
Pipeline / release (push) Skipped
Pipeline / docs (push) Successful in 1m47s
Pipeline / nightly (push) Successful in 6m41s
feat: provide way to build and attach platforms
2026-08-08 11:46:15 -04:00

34 lines
1.4 KiB
Bash
Executable File

#!/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/<owner>/<repo>
# 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