From 7eb3ba1ce82f57f00f5919cad573793e380d63ab Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 20 Jul 2026 15:56:45 +0200 Subject: [PATCH] feat: add create-release.sh for manual release creation --- scripts/create-release.sh | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 scripts/create-release.sh diff --git a/scripts/create-release.sh b/scripts/create-release.sh new file mode 100755 index 00000000..2a42d50a --- /dev/null +++ b/scripts/create-release.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +set -euo pipefail + +BARE="/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git" +GITEA_API="${GITEA_API:-https://gitlab.epicnabbo.nl}" +REPO="remco/EpicNext-Cms" +TOKEN="${GITEA_TOKEN:-}" + +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +VERSION="$1" + +if [ -z "$TOKEN" ]; then + echo "ERROR: GITEA_TOKEN not set" + exit 1 +fi + +echo "=== Creating release for ${VERSION} ===" + +if ! git -C "$BARE" rev-parse "$VERSION" >/dev/null 2>&1; then + echo "ERROR: tag $VERSION not found in bare repo" + exit 1 +fi + +PREV_TAG="$(git -C "$BARE" tag --sort=-creatordate | head -2 | tail -1 || echo '')" + +if [ -n "$PREV_TAG" ] && [ "$PREV_TAG" != "$VERSION" ]; then + CHANGELOG="$(git -C "$BARE" log --oneline --no-decorate "${PREV_TAG}..${VERSION}")" +else + CHANGELOG="$(git -C "$BARE" log --oneline --no-decorate "${VERSION}")" +fi + +[ -z "$CHANGELOG" ] && CHANGELOG="Initial release" + +echo "Previous tag: ${PREV_TAG:-none}" +echo "Changelog (${#CHANGELOG} chars):" +echo "${CHANGELOG}" + +BODY="## EpicNext-CMS ${VERSION} + +### Changes +${CHANGELOG} + +--- +*Automated release from Gitea Actions* +" + +echo "$BODY" | jq -Rs '{tag_name: $v, name: $v, body: ., draft: false, prerelease: false}' --arg v "${VERSION}" > /tmp/payload.json + +HTTP_CODE="$(curl -s -w '%{http_code}' -o /tmp/release-resp.json \ + -X POST "${GITEA_API}/api/v1/repos/${REPO}/releases" \ + -H "Authorization: token ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d @/tmp/payload.json)" + +if [ "${HTTP_CODE}" = "409" ]; then + echo "Release exists, updating..." + RELEASES="$(curl -sf "${GITEA_API}/api/v1/repos/${REPO}/releases" \ + -H "Authorization: token ${TOKEN}")" + REL_ID="$(echo "$RELEASES" | jq -r ".[] | select(.tag_name==\"${VERSION}\") | .id")" + echo "Release ID: ${REL_ID}" + HTTP_CODE="$(curl -s -w '%{http_code}' -o /tmp/release-resp.json \ + -X PATCH "${GITEA_API}/api/v1/repos/${REPO}/releases/${REL_ID}" \ + -H "Authorization: token ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d @/tmp/payload.json)" +fi + +if [ "${HTTP_CODE:-0}" -ge 200 ] && [ "${HTTP_CODE:-0}" -lt 300 ]; then + echo "SUCCESS: Release ${VERSION} created/updated" + cat /tmp/release-resp.json | jq -r '.html_url // .id' +else + echo "FAILED HTTP ${HTTP_CODE}" + cat /tmp/release-resp.json + exit 1 +fi