diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 2abb0590..fc835774 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -15,58 +15,46 @@ jobs: run: | set -e - LOCAL="/var/www/atom-nexst" - DEBUG="/tmp/release-debug.log" - : > "$DEBUG" + SRC="/tmp/epicnext-release" + rm -rf "$SRC" - debug() { echo "[$(date '+%H:%M:%S')] $*" >> "$DEBUG"; } + # Full clone for changelog + build (local bare repo = instant) + git clone --branch "${VERSION}" \ + /docker/gitea/gitea/git/repositories/remco/epicnext-cms.git \ + "$SRC" + cd "$SRC" - debug "=== RELEASE WORKFLOW START ===" - debug "VERSION=${VERSION}" - debug "PWD=$(pwd)" - debug "LOCAL=${LOCAL}" - debug "git -C ${LOCAL} tag list:" - git -C "$LOCAL" tag --sort=-creatordate >> "$DEBUG" 2>&1 - debug "git -C ${LOCAL} log -1:" - git -C "$LOCAL" log --oneline -1 >> "$DEBUG" 2>&1 - - # Generate changelog to a temp file - PREV_TAG="$(git -C "$LOCAL" tag --sort=-creatordate | head -2 | tail -1 || echo '')" - debug "PREV_TAG=${PREV_TAG}" + # Generate changelog + PREV_TAG="$(git tag --sort=-creatordate | head -2 | tail -1 || echo '')" + echo "=== Tags ===" + git tag --sort=-creatordate + echo "=== Version=${VERSION} Previous=${PREV_TAG} ===" if [ -n "$PREV_TAG" ] && [ "$PREV_TAG" != "$VERSION" ]; then RANGE="${PREV_TAG}..${VERSION}" - debug "RANGE=${RANGE}" - git -C "$LOCAL" log --oneline --no-decorate "${RANGE}" > /tmp/changelog.txt 2>>"$DEBUG" + echo "=== Range: ${RANGE} ===" + git log --oneline --no-decorate "${RANGE}" > /tmp/changelog.txt else - debug "First tag or same tag, using ${VERSION}" - git -C "$LOCAL" log --oneline --no-decorate "${VERSION}" > /tmp/changelog.txt 2>>"$DEBUG" + echo "=== First release, showing all commits ===" + git log --oneline --no-decorate "${VERSION}" > /tmp/changelog.txt fi - NOTES="$(cat /tmp/changelog.txt)" - debug "NOTES length: ${#NOTES}" - debug "NOTES first 200 chars: ${NOTES:0:200}" - - # Shallow clone for build - SRC="/tmp/epicnext-release" - rm -rf "$SRC" - git clone --branch "${VERSION}" --depth 1 \ - /docker/gitea/gitea/git/repositories/remco/epicnext-cms.git \ - "$SRC" 2>>"$DEBUG" - cd "$SRC" + echo "=== Changelog ===" + cat /tmp/changelog.txt + echo "=== End ===" + # Build if [ -f /var/www/atom-nexst/.env ]; then cp /var/www/atom-nexst/.env "$SRC/.env" fi - pnpm install --frozen-lockfile 2>>"$DEBUG" - pnpm prisma:generate 2>>"$DEBUG" + pnpm install --frozen-lockfile + pnpm prisma:generate export SKIP_ENV_VALIDATION=1 - pnpm build 2>>"$DEBUG" + pnpm build # Create release via API - debug "Creating release..." - python3 /dev/stdin << 'PYEOF' 2>>"$DEBUG" -import json, os + python3 << 'PYEOF' +import json, os, urllib.request, urllib.error version = os.environ["VERSION"] api = os.environ["GITEA_API"] @@ -74,19 +62,14 @@ repo = os.environ["GITEA_REPO"] token = "${{ secrets.GITEA_TOKEN }}" with open("/tmp/changelog.txt") as f: - notes_raw = f.read().strip() + notes = f.read().strip() or "Initial release" -print(f"Read {len(notes_raw)} chars from /tmp/changelog.txt") -print(f"Token set: {bool(token)}") -print(f"API URL: {api}") - -if not notes_raw: - notes_raw = "Initial release" +print(f"Changelog: {len(notes)} chars") body = f"""## EpicNext-CMS {version} ### Changes -{notes_raw} +{notes} --- *Automated release from Gitea Actions* @@ -100,8 +83,6 @@ payload = json.dumps({ "prerelease": False, }).encode("utf-8") -import urllib.request, urllib.error - def api_call(method, path, data=None): url = f"{api}/repos/{repo}/{path}" print(f"{method} {url}") @@ -118,10 +99,10 @@ def api_call(method, path, data=None): try: result = api_call("POST", "releases", payload) - print(f"Created: {result.get('html_url', result.get('id', '?'))}") + print(f"OK: {result.get('html_url', result.get('id', '?'))}") except urllib.error.HTTPError as e: - err = e.read().decode("utf-8") - print(f"POST {e.code}: {err}") + err_body = e.read().decode("utf-8") + print(f"POST {e.code}") if e.code == 409: releases = api_call("GET", "releases") for rel in releases: @@ -129,11 +110,7 @@ except urllib.error.HTTPError as e: result = api_call("PATCH", f"releases/{rel['id']}", payload) print(f"Updated: {result.get('html_url', result.get('id', '?'))}") break - else: - raise else: + print(f"API ERROR: {err_body}") raise PYEOF - - debug "=== RELEASE WORKFLOW END ===" - echo "Debug log: $DEBUG"