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 set -e
exec 2>&1 exec 2>&1
echo "=== VERSION=${VERSION} ===" BARE="/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git"
echo "=== API=${GITEA_API} ===" echo "=== START ${VERSION} ==="
echo "=== REPO=${GITEA_REPO} ==="
SRC="/tmp/epicnext-release" # Generate changelog from bare repo (always has full history)
rm -rf "$SRC" PREV_TAG="$(git -C "$BARE" tag --sort=-creatordate | head -2 | tail -1 || echo '')"
git clone --branch "${VERSION}" \ echo "Previous tag: ${PREV_TAG}"
/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} ==="
if [ -n "$PREV_TAG" ] && [ "$PREV_TAG" != "$VERSION" ]; then 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 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 fi
echo "=== Changelog ===" [ -z "$CHANGELOG" ] && CHANGELOG="Initial release"
cat /tmp/changelog.txt
echo "=== Changelog (${#CHANGELOG} chars) ==="
echo "${CHANGELOG}"
echo "=== End ===" 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 if [ -f /var/www/atom-nexst/.env ]; then
cp /var/www/atom-nexst/.env "$SRC/.env" cp /var/www/atom-nexst/.env "$SRC/.env"
fi fi
pnpm install --frozen-lockfile 2>&1 pnpm install --frozen-lockfile
pnpm prisma:generate 2>&1 pnpm prisma:generate
export SKIP_ENV_VALIDATION=1 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)" NOTES="$(cat /tmp/changelog.txt)"
[ -z "$NOTES" ] && NOTES="Initial release"
# Build JSON with jq, send with curl
BODY="## EpicNext-CMS ${VERSION} BODY="## EpicNext-CMS ${VERSION}
### Changes ### Changes
@@ -65,31 +66,38 @@ ${NOTES}
*Automated release from Gitea Actions* *Automated release from Gitea Actions*
" "
PAYLOAD="$(echo "$BODY" | jq -Rs '{tag_name: $v, name: $v, body: ., draft: false, prerelease: false}' --arg v "${VERSION}")" PAYLOAD="$(echo "$BODY" | jq -Rs '{tag_name: $v, name: $v, body: ., draft: false, prerelease: false}' --arg v "${VERSION}" 2>&1)"
echo "Payload length: ${#PAYLOAD}" echo "Payload: ${#PAYLOAD} bytes"
RESP="$(curl -s -w '\n%{http_code}' -X POST \ # Try create, fallback to update
"${GITEA_API}/repos/${GITEA_REPO}/releases" \ 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 "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$PAYLOAD")" -d "$PAYLOAD" 2>&1)"
HTTP_CODE="$(echo "$RESP" | tail -1)" echo "POST response: ${HTTP_CODE}"
RESP_BODY="$(echo "$RESP" | head -n -1)"
echo "HTTP ${HTTP_CODE}: ${RESP_BODY:0:200}"
if [ "$HTTP_CODE" = "409" ] || [ "$HTTP_CODE" = "409" ]; then if [ "${HTTP_CODE}" = "409" ]; then
# Release exists — update it echo "Release exists, updating..."
RELEASES="$(curl -sf "${GITEA_API}/repos/${GITEA_REPO}/releases" \ RELEASES="$(curl -sf "${GITEA_API}/repos/${GITEA_REPO}/releases" \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}")" -H "Authorization: token ${{ secrets.GITEA_TOKEN }}")"
REL_ID="$(echo "$RELEASES" | jq -r ".[] | select(.tag_name==\"${VERSION}\") | .id")" REL_ID="$(echo "$RELEASES" | jq -r ".[] | select(.tag_name==\"${VERSION}\") | .id")"
if [ -n "$REL_ID" ] && [ "$REL_ID" != "null" ]; then echo "Release ID: ${REL_ID}"
RESP2="$(curl -s -w '\n%{http_code}' -X PATCH \ HTTP_CODE="$(curl -s -w '%{http_code}' -o /tmp/release-resp.json \
"${GITEA_API}/repos/${GITEA_REPO}/releases/${REL_ID}" \ -X PATCH "${GITEA_API}/repos/${GITEA_REPO}/releases/${REL_ID}" \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \ -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$PAYLOAD")" -d "$PAYLOAD" 2>&1)"
echo "PATCH result: $(echo "$RESP2" | tail -1)" echo "PATCH response: ${HTTP_CODE}"
fi
fi 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 ==="