80 lines
2.2 KiB
Bash
Executable File
80 lines
2.2 KiB
Bash
Executable File
#!/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 <tag>"
|
|
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
|