name: Deploy on: push: branches: - main tags: - "v*" jobs: release: if: startsWith(gitea.ref_name, 'v') runs-on: shell steps: - name: Create 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 "=== Creating release for ${VERSION} ===" PREV_TAG="$(git -C "$BARE" tag --sort=-creatordate | head -2 | tail -1 || echo '')" if [ -n "$PREV_TAG" ] && [ "$PREV_TAG" != "$VERSION" ]; then CHANGELOG="$(git -C "$BARE" log --oneline --no-decorate --max-count=50 "${PREV_TAG}..${VERSION}")" [ -z "$CHANGELOG" ] && CHANGELOG="No commit changes since ${PREV_TAG}" else TOTAL="$(git -C "$BARE" rev-list --count "${VERSION}" 2>/dev/null || echo '?')" CHANGELOG="Initial release of EpicNext-CMS (${TOTAL} commits)." fi [ -z "$CHANGELOG" ] && CHANGELOG="Initial release" # Pin the other components at their current commits so the release is reproducible. CAT_REF="$(git ls-remote https://gitlab.epicnabbo.nl/remco/Epicnabbo-Catalogus-Updated-Daily.git Beta-3 2>/dev/null | awk '{print $1}')" NITRO_REF="$(git ls-remote https://github.com/duckietm/Nitro-V3.git main 2>/dev/null | awk '{print $1}')" RENDER_REF="$(git ls-remote https://github.com/duckietm/Nitro_Render_V3.git main 2>/dev/null | awk '{print $1}')" EMU_REF="$(git ls-remote https://github.com/duckietm/Polaris-Emulator.git main 2>/dev/null | awk '{print $1}')" { echo "# EpicNext-CMS ${VERSION}" echo "" echo "> Modern, high-performance CMS for Habbo hotel emulators — built on Next.js 16, React 19 and Prisma 7. Integrates with Polaris / Arcturus Morningstar databases." echo "" echo "## Menu" echo "- [What is EpicNext-CMS?](#user-content-what-is-epicnext-cms)" echo "- [System Requirements](#user-content-system-requirements)" echo "- [Installation Wizard](#user-content-installation-wizard)" echo "- [How it is used](#user-content-how-it-is-used)" echo "- [Changes](#user-content-changes)" echo "- [Linked repositories](#user-content-linked-repositories-exact-commits)" echo "" echo "## What is EpicNext-CMS?" echo "" echo "EpicNext-CMS is a full public-facing hotel website plus an administrative panel. It features NextAuth authentication (argon2id/bcrypt with MD5 upgrade), real-time RCON communication with the emulator, Server-Sent Events for live radio, smooth page transitions and extensive extensibility. Full documentation: https://gitlab.epicnabbo.nl/remco/EpicNext-Cms/src/branch/main/README.md" echo "" echo "## System Requirements" echo "" echo "What you need to install before running the CMS:" echo "" echo "| Component | Version | Notes |" echo "| --------- | ------- | ----- |" echo "| Node.js | >= 22 | Required by Next.js 16 |" echo "| pnpm | >= 10.33.4 | Package manager (npm/yarn not supported) |" echo "| MySQL / MariaDB | 8.0+ / 10.6+ | Shared with the emulator |" echo "| Redis | 7.x+ | Optional — caching, rate limiting, SSE |" echo "| Java | 17+ | Only if building the emulator |" echo "| Maven | 3.9+ | Only if building the emulator |" echo "" echo "The CMS shares its database with the Polaris / Arcturus emulator. It only reads/writes emulator-owned tables and never alters them." echo "" echo "## Installation Wizard" echo "" echo "### 1. Clone & Install" echo '```bash' echo "git clone https://gitlab.epicnabbo.nl/remco/EpicNext-Cms.git" echo "cd EpicNext-Cms" echo "pnpm install" echo '```' echo "" echo "### 2. Database Setup" echo "" echo "Use an existing emulator database or create a new one:" echo '```sql' echo "CREATE DATABASE IF NOT EXISTS epicnext_cms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" echo '```' echo "" echo "### 3. Configure Environment" echo '```bash' echo "cp .env.example .env" echo '```' echo "" echo "Edit .env with at minimum: DATABASE_URL, AUTH_SECRET, HOTEL_NAME and APP_URL. See .env.example for RCON, email, Redis, OAuth and PayPal options." echo "" echo "### 4. Generate Prisma Client" echo '```bash' echo "pnpm prisma:generate" echo '```' echo "" echo "### 5. Run CMS Migrations" echo '```bash' echo "pnpm db:migrate" echo '```' echo "" echo "Creates all CMS-owned tables (website_*, radio_*, acl_*, admin_audit_log). Emulator tables are never touched. Check status with pnpm db:migrate:status." echo "" echo "### 6. Build & Start" echo '```bash' echo "# Development (hot reload)" echo "pnpm dev" echo "" echo "# Production" echo "pnpm build && pnpm start" echo '```' echo "" echo "Open http://localhost:3000 in your browser." echo "" echo "### 7. First Login" echo "" echo "1. Register at /register, or log in with an existing emulator account." echo "2. Grant admin access: UPDATE users SET rank = 7 WHERE username = 'yourname';" echo "3. Visit /admin and configure your hotel via Admin -> CMS Settings." echo "" echo "## How it is used" echo "" echo "- Public site: browse the hotel, news, radio and the Nitro client at /client." echo "- Admin panel: /admin for CMS settings, theming (12 presets), users, radio and more." echo "- Background jobs: run pnpm jobs:worker for daily backups and cleanup." echo "- Optional: Cloudflare Turnstile / reCAPTCHA, OpenAI moderation and email/PayPal via .env." echo "" echo "## Changes" echo '```' echo "${CHANGELOG}" echo '```' echo "" echo "## Linked repositories (exact commits)" echo "" echo "The game components below are pinned to the exact commits used by this release and are deployed alongside the CMS:" echo "" echo "| Component | Repository | Commit |" echo "|-----------|------------|--------|" echo "| Catalogus | https://gitlab.epicnabbo.nl/remco/Epicnabbo-Catalogus-Updated-Daily | ${CAT_REF:-?} |" echo "| Nitro-V3 | https://github.com/duckietm/Nitro-V3 | ${NITRO_REF:-?} |" echo "| Nitro-Render-V3 | https://github.com/duckietm/Nitro_Render_V3 | ${RENDER_REF:-?} |" echo "| Polaris Emulator | https://github.com/duckietm/Polaris-Emulator | ${EMU_REF:-?} |" echo "" echo "---" echo "*Automated release from Gitea Actions*" } > /tmp/release-body.md PAYLOAD="$(jq -Rs --arg v "${VERSION}" '{tag_name: $v, name: $v, body: ., draft: false, prerelease: false}' < /tmp/release-body.md)" TOKEN="${GITEA_TOKEN:-${{ secrets.GITEA_TOKEN }}}" HTTP_CODE="$(curl -s -w '%{http_code}' -o /tmp/release-resp.json \ -X POST "${GITEA_API}/repos/${GITEA_REPO}/releases" \ -H "Authorization: token ${TOKEN}" \ -H "Content-Type: application/json" \ -d "$PAYLOAD")" if [ "${HTTP_CODE}" = "409" ]; then RELEASES="$(curl -sf "${GITEA_API}/repos/${GITEA_REPO}/releases" \ -H "Authorization: token ${TOKEN}")" REL_ID="$(echo "$RELEASES" | jq -r ".[] | select(.tag_name==\"${VERSION}\") | .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 ${TOKEN}" \ -H "Content-Type: application/json" \ -d "$PAYLOAD")" fi if [ "${HTTP_CODE:-0}" -ge 200 ] && [ "${HTTP_CODE:-0}" -lt 300 ]; then echo "SUCCESS: Release ${VERSION} created/updated" cat /tmp/release-resp.json | jq -r '.html_url // .id' else echo "FAILED HTTP ${HTTP_CODE}" cat /tmp/release-resp.json exit 1 fi deploy: if: startsWith(gitea.ref_name, 'v') == false runs-on: shell steps: - name: Deploy run: | set -e exec 9>/var/tmp/epic_web_control_deploy.lock flock -n 9 || { echo "ERROR: Another deployment is already running! Cancelling."; exit 1; } echo "--- Deploying ---" error_handler() { echo "!!! DEPLOYMENT FAILED on line $1 !!!" >&2 sudo systemctl start atom-nexst.service || true exit 1 } trap 'error_handler $LINENO' ERR docker image prune -f cd /var/www/atom-nexst/ DEPLOY_USER="$(id -un)" DEPLOY_GROUP="$(id -gn)" sudo chown -R "${DEPLOY_USER}:${DEPLOY_GROUP}" /var/www/atom-nexst/ git config --global --add safe.directory /var/www/atom-nexst git remote set-url origin /docker/gitea/gitea/git/repositories/remco/epicnext-cms.git/ echo "Fetching origin/main..." git fetch origin --prune echo "Clearing sticky git index bits (if any)..." STICKY_LIST="$(git ls-files -v | awk '/^[a-zS]/ {print substr($0,3)}' || true)" if [ -n "${STICKY_LIST}" ]; then echo "${STICKY_LIST}" | while IFS= read -r f; do [ -n "$f" ] || continue git update-index --no-skip-worktree --no-assume-unchanged -- "$f" 2>/dev/null || true done fi echo "Hard reset to origin/main..." git reset --hard origin/main echo "Nuclear-replacing src/ from HEAD..." rm -rf src git checkout -f HEAD -- src git clean -fd -e .env -e .env.local -e .env.production -e .env*.local if ! git diff --exit-code HEAD -- src >/dev/null; then echo "ERROR: src/ still differs from HEAD after nuclear checkout:" >&2 git diff --stat HEAD -- src >&2 || true exit 1 fi echo "Verified src/ matches HEAD" rm -f tsconfig.tsbuildinfo .tsbuildinfo find . -maxdepth 3 -name '*.tsbuildinfo' -delete 2>/dev/null || true rm -rf .output dist .next/types .next/dev export APP_VERSION="$(git rev-parse --short HEAD)" export NEXT_PUBLIC_APP_VERSION="${APP_VERSION}" echo "APP_VERSION=${APP_VERSION}" pnpm install --frozen-lockfile pnpm db:migrate pnpm prisma:generate pnpm typecheck pnpm test export SKIP_ENV_VALIDATION=1 pnpm build sudo chown -R www-data:www-data /var/www/atom-nexst/ echo "Hard resetting systemd service..." sudo systemctl stop atom-nexst.service || true pkill -f 'next-server' || true sudo systemctl start atom-nexst.service sleep 2 if ! systemctl is-active --quiet atom-nexst.service; then echo "ERROR: atom-nexst.service failed to start!" >&2 exit 1 fi echo "--- Deployed successfully ---"