fix: generate release changelog from full local repo
Local Build and Deploy / deploy (push) Successful in 1m23s
Local Build and Deploy / deploy (push) Successful in 1m23s
Shallow clone (depth 1) only has one commit, so git log was empty. Now generates changelog from the bare repo before cloning, and uses Python to build the JSON payload for proper multiline escaping.
This commit is contained in:
1 parent
aea9d83865
commit
15ed8ffbf0
1 file changed
+56
-36
@@ -15,28 +15,27 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# ── Checkout ────────────────────────────────────────────────
|
REPO="/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git"
|
||||||
SRC="/tmp/epicnext-release"
|
|
||||||
rm -rf "$SRC"
|
|
||||||
git clone --branch "${VERSION}" --depth 1 \
|
|
||||||
/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git \
|
|
||||||
"$SRC"
|
|
||||||
cd "$SRC"
|
|
||||||
|
|
||||||
# ── Generate Release Notes ───────────────────────────────────
|
# ── Generate changelog ────────────────────────────────────────
|
||||||
PREV_TAG="$(git tag --sort=-creatordate | head -2 | tail -1 || echo '')"
|
PREV_TAG="$(git -C "$REPO" tag --sort=-creatordate | head -2 | tail -1 || echo '')"
|
||||||
if [ -n "$PREV_TAG" ]; then
|
if [ -n "$PREV_TAG" ]; then
|
||||||
RANGE="${PREV_TAG}..${VERSION}"
|
RANGE="${PREV_TAG}..${VERSION}"
|
||||||
NOTES="$(git log --oneline --no-decorate "${RANGE}" 2>/dev/null || git log --oneline --no-decorate -20)"
|
git -C "$REPO" log --oneline --no-decorate "${RANGE}" > /tmp/changelog.txt 2>/dev/null || \
|
||||||
|
git -C "$REPO" log --oneline --no-decorate -30 > /tmp/changelog.txt
|
||||||
else
|
else
|
||||||
NOTES="$(git log --oneline --no-decorate -30)"
|
git -C "$REPO" log --oneline --no-decorate -30 > /tmp/changelog.txt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "=== Release Notes ==="
|
echo "=== Changelog ==="
|
||||||
echo "$NOTES"
|
cat /tmp/changelog.txt
|
||||||
|
|
||||||
|
# ── Build ─────────────────────────────────────────────────────
|
||||||
|
SRC="/tmp/epicnext-release"
|
||||||
|
rm -rf "$SRC"
|
||||||
|
git clone --branch "${VERSION}" --depth 1 "$REPO" "$SRC"
|
||||||
|
cd "$SRC"
|
||||||
|
|
||||||
# ── Build ────────────────────────────────────────────────────
|
|
||||||
# Copy env for Prisma client generation and build
|
|
||||||
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
|
||||||
@@ -45,28 +44,49 @@ jobs:
|
|||||||
export SKIP_ENV_VALIDATION=1
|
export SKIP_ENV_VALIDATION=1
|
||||||
pnpm build
|
pnpm build
|
||||||
|
|
||||||
# ── Create Gitea Release ─────────────────────────────────────
|
# ── Create release (Python handles JSON properly) ─────────────
|
||||||
BODY="## EpicNext-CMS ${VERSION}
|
python3 << 'PYEOF'
|
||||||
|
import json, os, urllib.request
|
||||||
|
|
||||||
### Changes
|
version = os.environ['VERSION']
|
||||||
${NOTES}
|
api = os.environ['GITEA_API']
|
||||||
|
repo = os.environ['GITEA_REPO']
|
||||||
|
token = "${{ secrets.GITEA_TOKEN }}"
|
||||||
|
|
||||||
---
|
with open('/tmp/changelog.txt') as f:
|
||||||
_Automated release from Gitea Actions_
|
notes = f.read()
|
||||||
"
|
|
||||||
|
|
||||||
curl -s -X POST "${GITEA_API}/repos/${GITEA_REPO}/releases" \
|
body = f"""## EpicNext-CMS {version}
|
||||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "$(cat <<-ENDJSON
|
|
||||||
{
|
|
||||||
"tag_name": "${VERSION}",
|
|
||||||
"name": "${VERSION}",
|
|
||||||
"body": $(echo "$BODY" | jq -Rs '.'),
|
|
||||||
"draft": false,
|
|
||||||
"prerelease": false
|
|
||||||
}
|
|
||||||
ENDJSON
|
|
||||||
)"
|
|
||||||
|
|
||||||
echo "Release ${VERSION} created successfully!"
|
### Changes
|
||||||
|
{notes}
|
||||||
|
---
|
||||||
|
*Automated release from Gitea Actions*
|
||||||
|
"""
|
||||||
|
|
||||||
|
payload = json.dumps({
|
||||||
|
'tag_name': version,
|
||||||
|
'name': version,
|
||||||
|
'body': body,
|
||||||
|
'draft': False,
|
||||||
|
'prerelease': False,
|
||||||
|
}).encode('utf-8')
|
||||||
|
|
||||||
|
req = urllib.request.Request(
|
||||||
|
f'{api}/repos/{repo}/releases',
|
||||||
|
data=payload,
|
||||||
|
headers={
|
||||||
|
'Authorization': f'token {token}',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
method='POST',
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = urllib.request.urlopen(req)
|
||||||
|
result = json.loads(resp.read().decode('utf-8'))
|
||||||
|
print(f"Release created: {result.get('html_url', result.get('id', '?'))}")
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(f"API error {e.code}: {e.read().decode('utf-8')}")
|
||||||
|
raise
|
||||||
|
PYEOF
|
||||||
Reference in new issue
Block a user