Local Build and Deploy / deploy (push) Successful in 1m29s
Shallow clone (--depth 1) prevented git log from seeing full history. Local bare repo clone is instant, so full clone adds no network delay.
117 lines
3.2 KiB
YAML
117 lines
3.2 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
|
|
|
|
SRC="/tmp/epicnext-release"
|
|
rm -rf "$SRC"
|
|
|
|
# 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"
|
|
|
|
# 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}"
|
|
echo "=== Range: ${RANGE} ==="
|
|
git log --oneline --no-decorate "${RANGE}" > /tmp/changelog.txt
|
|
else
|
|
echo "=== First release, showing all commits ==="
|
|
git log --oneline --no-decorate "${VERSION}" > /tmp/changelog.txt
|
|
fi
|
|
|
|
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
|
|
pnpm prisma:generate
|
|
export SKIP_ENV_VALIDATION=1
|
|
pnpm build
|
|
|
|
# Create release via API
|
|
python3 << 'PYEOF'
|
|
import json, os, urllib.request, urllib.error
|
|
|
|
version = os.environ["VERSION"]
|
|
api = os.environ["GITEA_API"]
|
|
repo = os.environ["GITEA_REPO"]
|
|
token = "${{ secrets.GITEA_TOKEN }}"
|
|
|
|
with open("/tmp/changelog.txt") as f:
|
|
notes = f.read().strip() or "Initial release"
|
|
|
|
print(f"Changelog: {len(notes)} chars")
|
|
|
|
body = f"""## EpicNext-CMS {version}
|
|
|
|
### Changes
|
|
{notes}
|
|
|
|
---
|
|
*Automated release from Gitea Actions*
|
|
"""
|
|
|
|
payload = json.dumps({
|
|
"tag_name": version,
|
|
"name": version,
|
|
"body": body,
|
|
"draft": False,
|
|
"prerelease": False,
|
|
}).encode("utf-8")
|
|
|
|
def api_call(method, path, data=None):
|
|
url = f"{api}/repos/{repo}/{path}"
|
|
print(f"{method} {url}")
|
|
req = urllib.request.Request(
|
|
url, data=data,
|
|
headers={
|
|
"Authorization": f"token {token}",
|
|
"Content-Type": "application/json",
|
|
},
|
|
method=method,
|
|
)
|
|
resp = urllib.request.urlopen(req)
|
|
return json.loads(resp.read().decode("utf-8"))
|
|
|
|
try:
|
|
result = api_call("POST", "releases", payload)
|
|
print(f"OK: {result.get('html_url', result.get('id', '?'))}")
|
|
except urllib.error.HTTPError as e:
|
|
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:
|
|
if rel["tag_name"] == version:
|
|
result = api_call("PATCH", f"releases/{rel['id']}", payload)
|
|
print(f"Updated: {result.get('html_url', result.get('id', '?'))}")
|
|
break
|
|
else:
|
|
print(f"API ERROR: {err_body}")
|
|
raise
|
|
PYEOF
|