From 9a17209db2fc7c92a26ecf3e116cfc47a7599b16 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Thu, 9 Apr 2026 22:04:23 +0200 Subject: [PATCH] Add CI and deploy workflow - Run typecheck, panel build, and integration tests in Gitea - Deploy main branch to VPS over SSH and verify the health endpoint --- .gitea/workflows/ci-deploy.yml | 132 +++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 .gitea/workflows/ci-deploy.yml diff --git a/.gitea/workflows/ci-deploy.yml b/.gitea/workflows/ci-deploy.yml new file mode 100644 index 0000000..6549b68 --- /dev/null +++ b/.gitea/workflows/ci-deploy.yml @@ -0,0 +1,132 @@ +name: CI / Deploy + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:17-alpine + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: aurora_test + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Bun + run: | + curl -fsSL https://bun.sh/install | bash + echo "$HOME/.bun/bin" >> "$GITHUB_PATH" + + - name: Install Dependencies + run: bun install --frozen-lockfile + + - name: Create Config File + run: | + mkdir -p shared/config + cat < shared/config/config.json + { + "leveling": { "base": 100, "exponent": 2.5, "chat": { "cooldownMs": 60000, "minXp": 15, "maxXp": 25 } }, + "economy": { + "daily": { "amount": "100", "streakBonus": "10", "weeklyBonus": "50", "cooldownMs": 86400000 }, + "transfers": { "allowSelfTransfer": false, "minAmount": "1" }, + "exam": { "multMin": 0.05, "multMax": 0.03 } + }, + "inventory": { "maxStackSize": "99", "maxSlots": 50 }, + "commands": {}, + "lootdrop": { + "activityWindowMs": 120000, "minMessages": 1, "spawnChance": 1, "cooldownMs": 3000, + "reward": { "min": 40, "max": 150, "currency": "Astral Units" } + }, + "studentRole": "123", "visitorRole": "456", "colorRoles": [], + "moderation": { + "prune": { "maxAmount": 100, "confirmThreshold": 50, "batchSize": 100, "batchDelayMs": 1000 }, + "cases": { "dmOnWarn": false } + }, + "trivia": { + "entryFee": "50", "rewardMultiplier": 1.5, "timeoutSeconds": 30, "cooldownMs": 60000, + "categories": [], "difficulty": "random" + }, + "system": {} + } + EOF + + - name: Typecheck + run: bunx tsc --noEmit + + - name: Build Panel + run: bun run panel:build + + - name: Setup Test Database + run: bun run db:push:local + env: + DATABASE_URL: postgresql://postgres:postgres@postgres:5432/aurora_test + DISCORD_BOT_TOKEN: test_token + DISCORD_CLIENT_ID: "123" + DISCORD_GUILD_ID: "123" + + - name: Run Tests + run: | + cat < .env.test + DATABASE_URL="postgresql://postgres:postgres@postgres:5432/aurora_test" + DISCORD_BOT_TOKEN="test_token" + DISCORD_CLIENT_ID="123456789" + DISCORD_GUILD_ID="123456789" + DISCORD_CLIENT_SECRET="test-client-secret" + SESSION_SECRET="test-session-secret" + ADMIN_TOKEN="admin_token_123" + LOG_LEVEL="error" + EOF + bash shared/scripts/test-isolated.sh --integration + env: + NODE_ENV: test + + deploy: + needs: test + if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main' + runs-on: ubuntu-latest + + steps: + - name: Configure SSH + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + VPS_HOST: ${{ secrets.VPS_HOST }} + run: | + install -m 700 -d ~/.ssh + printf '%s\n' "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts + + - name: Deploy on VPS + env: + VPS_HOST: ${{ secrets.VPS_HOST }} + VPS_USER: ${{ secrets.VPS_USER }} + VPS_PROJECT_PATH: ${{ secrets.VPS_PROJECT_PATH }} + run: | + set -euo pipefail + REMOTE_DIR="${VPS_PROJECT_PATH:-~/Aurora}" + ssh -o BatchMode=yes "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && bash shared/scripts/deploy.sh" + + - name: Post-deploy Health Check + env: + VPS_HOST: ${{ secrets.VPS_HOST }} + VPS_USER: ${{ secrets.VPS_USER }} + VPS_PROJECT_PATH: ${{ secrets.VPS_PROJECT_PATH }} + run: | + set -euo pipefail + REMOTE_DIR="${VPS_PROJECT_PATH:-~/Aurora}" + ssh -o BatchMode=yes "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && curl -fsS http://127.0.0.1:3000/api/health >/dev/null"