Files
httptoolkit/.build/prod/release.sh
T
2026-08-15 02:14:26 +05:00

49 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Create a Gitea release for a tag and upload everything in out/.
# Mirrors the repo's existing Gitea-API release convention.
#
# Config via env (or a local .env next to this script):
# GITEA_SERVER_URL, GITEA_REPOSITORY, GITEA_TOKEN
# Tag: passed as $1 (in CI: gitea.ref_name), else derived from the current commit.
#
set -euo pipefail
cd "$(dirname "$0")"
# Optional: load credentials from a local .env for manual runs.
[ -f .env ] && source ./.env
: "${GITEA_SERVER_URL:?}"
: "${GITEA_REPOSITORY:?}"
: "${GITEA_TOKEN:?}"
TAG="${1:-$(git tag --points-at HEAD | head -n1)}"
[ -n "$TAG" ] || { echo "No tag (pass as arg, or run on a tagged commit)"; exit 1; }
OUT_DIR="$(pwd)/out"
API="${GITEA_SERVER_URL}/api/v1/repos/${GITEA_REPOSITORY}/releases"
echo "==> Creating release $TAG"
RESP=$(curl -s -X POST "$API" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\": \"${TAG}\", \"name\": \"HTTP Toolkit ${TAG}\", \"body\": \"Self-hosted single-file build.\"}")
RID=$(echo "$RESP" | jq -r '.id')
if [ "$RID" = "null" ] || [ -z "$RID" ]; then
echo "!! Failed to create release:"; echo "$RESP"; exit 1
fi
echo "==> Release id $RID"
shopt -s nullglob
for f in "$OUT_DIR"/*; do
[ -f "$f" ] || continue
name=$(basename "$f")
echo "==> Uploading $name"
curl -s -X POST "${API}/${RID}/assets?name=${name}" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary "@${f}" > /dev/null
done
echo "==> Release complete."