fix: generate changelog from bare repo before clone, use jq

Bare repo ensures all tags and full history are available.
Changelog saved before clone to avoid filesystem isolation issues.
This commit is contained in:
openhands committed 2026-07-20 15:38:42 +02:00
1 parent cb683b7322
commit 323e2cd9d3
1 file changed
+53 -45
+53 -45
View File
@@ -16,46 +16,47 @@ jobs:
set -e
exec 2>&1
echo "=== VERSION=${VERSION} ==="
echo "=== API=${GITEA_API} ==="
echo "=== REPO=${GITEA_REPO} ==="
BARE="/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git"
echo "=== START ${VERSION} ==="
SRC="/tmp/epicnext-release"
rm -rf "$SRC"
git clone --branch "${VERSION}" \
/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git \
"$SRC" 2>&1
cd "$SRC"
echo "=== Cloned ==="
PREV_TAG="$(git tag --sort=-creatordate | head -2 | tail -1 || echo '')"
echo "=== Tags ==="
git tag --sort=-creatordate
echo "=== Previous=${PREV_TAG} ==="
# Generate changelog from bare repo (always has full history)
PREV_TAG="$(git -C "$BARE" tag --sort=-creatordate | head -2 | tail -1 || echo '')"
echo "Previous tag: ${PREV_TAG}"
if [ -n "$PREV_TAG" ] && [ "$PREV_TAG" != "$VERSION" ]; then
git log --oneline --no-decorate "${PREV_TAG}..${VERSION}" > /tmp/changelog.txt
echo "Range: ${PREV_TAG}..${VERSION}"
CHANGELOG="$(git -C "$BARE" log --oneline --no-decorate "${PREV_TAG}..${VERSION}" 2>&1)"
else
git log --oneline --no-decorate "${VERSION}" > /tmp/changelog.txt
echo "First release or same tag"
CHANGELOG="$(git -C "$BARE" log --oneline --no-decorate "${VERSION}" 2>&1)"
fi
echo "=== Changelog ==="
cat /tmp/changelog.txt
[ -z "$CHANGELOG" ] && CHANGELOG="Initial release"
echo "=== Changelog (${#CHANGELOG} chars) ==="
echo "${CHANGELOG}"
echo "=== End ==="
# Write to file for API step
echo "$CHANGELOG" > /tmp/changelog.txt
# Clone for build
SRC="/tmp/epicnext-release"
rm -rf "$SRC"
git clone --branch "${VERSION}" --depth 1 "$BARE" "$SRC"
cd "$SRC"
if [ -f /var/www/atom-nexst/.env ]; then
cp /var/www/atom-nexst/.env "$SRC/.env"
fi
pnpm install --frozen-lockfile 2>&1
pnpm prisma:generate 2>&1
pnpm install --frozen-lockfile
pnpm prisma:generate
export SKIP_ENV_VALIDATION=1
pnpm build 2>&1
pnpm build
echo "=== Creating release ==="
# Create release via Gitea API
echo "=== Creating/updating release ==="
NOTES="$(cat /tmp/changelog.txt)"
[ -z "$NOTES" ] && NOTES="Initial release"
# Build JSON with jq, send with curl
BODY="## EpicNext-CMS ${VERSION}
### Changes
@@ -65,31 +66,38 @@ ${NOTES}
*Automated release from Gitea Actions*
"
PAYLOAD="$(echo "$BODY" | jq -Rs '{tag_name: $v, name: $v, body: ., draft: false, prerelease: false}' --arg v "${VERSION}")"
echo "Payload length: ${#PAYLOAD}"
PAYLOAD="$(echo "$BODY" | jq -Rs '{tag_name: $v, name: $v, body: ., draft: false, prerelease: false}' --arg v "${VERSION}" 2>&1)"
echo "Payload: ${#PAYLOAD} bytes"
RESP="$(curl -s -w '\n%{http_code}' -X POST \
"${GITEA_API}/repos/${GITEA_REPO}/releases" \
# Try create, fallback to update
HTTP_CODE="$(curl -s -w '%{http_code}' -o /tmp/release-resp.json \
-X POST "${GITEA_API}/repos/${GITEA_REPO}/releases" \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")"
HTTP_CODE="$(echo "$RESP" | tail -1)"
RESP_BODY="$(echo "$RESP" | head -n -1)"
echo "HTTP ${HTTP_CODE}: ${RESP_BODY:0:200}"
-d "$PAYLOAD" 2>&1)"
echo "POST response: ${HTTP_CODE}"
if [ "$HTTP_CODE" = "409" ] || [ "$HTTP_CODE" = "409" ]; then
# Release exists — update it
if [ "${HTTP_CODE}" = "409" ]; then
echo "Release exists, updating..."
RELEASES="$(curl -sf "${GITEA_API}/repos/${GITEA_REPO}/releases" \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}")"
REL_ID="$(echo "$RELEASES" | jq -r ".[] | select(.tag_name==\"${VERSION}\") | .id")"
if [ -n "$REL_ID" ] && [ "$REL_ID" != "null" ]; then
RESP2="$(curl -s -w '\n%{http_code}' -X PATCH \
"${GITEA_API}/repos/${GITEA_REPO}/releases/${REL_ID}" \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")"
echo "PATCH result: $(echo "$RESP2" | tail -1)"
fi
echo "Release ID: ${REL_ID}"
HTTP_CODE="$(curl -s -w '%{http_code}' -o /tmp/release-resp.json \
-X PATCH "${GITEA_API}/repos/${GITEA_REPO}/releases/${REL_ID}" \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" 2>&1)"
echo "PATCH response: ${HTTP_CODE}"
fi
echo "=== Done ==="
if [ "${HTTP_CODE:-0}" -ge 200 ] && [ "${HTTP_CODE:-0}" -lt 300 ]; then
echo "SUCCESS"
cat /tmp/release-resp.json | jq -r '.html_url // .id' 2>/dev/null || true
else
echo "FAILED with HTTP ${HTTP_CODE}"
cat /tmp/release-resp.json 2>/dev/null || true
exit 1
fi
echo "=== DONE ==="