Local Build and Deploy / deploy (push) Successful in 1m27s
Bare repo ensures all tags and full history are available. Changelog saved before clone to avoid filesystem isolation issues.
104 lines
3.6 KiB
YAML
104 lines
3.6 KiB
YAML
name: Create Release
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
jobs:
|
|
release:
|
|
runs-on: shell
|
|
steps:
|
|
- name: Build & release
|
|
env:
|
|
VERSION: ${{ gitea.ref_name }}
|
|
GITEA_API: ${{ gitea.api_url }}
|
|
GITEA_REPO: ${{ gitea.repository }}
|
|
run: |
|
|
set -e
|
|
exec 2>&1
|
|
|
|
BARE="/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git"
|
|
echo "=== START ${VERSION} ==="
|
|
|
|
# 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
|
|
echo "Range: ${PREV_TAG}..${VERSION}"
|
|
CHANGELOG="$(git -C "$BARE" log --oneline --no-decorate "${PREV_TAG}..${VERSION}" 2>&1)"
|
|
else
|
|
echo "First release or same tag"
|
|
CHANGELOG="$(git -C "$BARE" log --oneline --no-decorate "${VERSION}" 2>&1)"
|
|
fi
|
|
|
|
[ -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
|
|
pnpm prisma:generate
|
|
export SKIP_ENV_VALIDATION=1
|
|
pnpm build
|
|
|
|
# Create release via Gitea API
|
|
echo "=== Creating/updating release ==="
|
|
NOTES="$(cat /tmp/changelog.txt)"
|
|
BODY="## EpicNext-CMS ${VERSION}
|
|
|
|
### Changes
|
|
${NOTES}
|
|
|
|
---
|
|
*Automated release from Gitea Actions*
|
|
"
|
|
|
|
PAYLOAD="$(echo "$BODY" | jq -Rs '{tag_name: $v, name: $v, body: ., draft: false, prerelease: false}' --arg v "${VERSION}" 2>&1)"
|
|
echo "Payload: ${#PAYLOAD} bytes"
|
|
|
|
# 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" 2>&1)"
|
|
echo "POST response: ${HTTP_CODE}"
|
|
|
|
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")"
|
|
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
|
|
|
|
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 ==="
|