diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 6e07923..1dc2e13 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -12,28 +12,12 @@ on: pull_request: jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - # Same major as Passenger on the server (26.13.0 as of 2026-11-08). - node-version-file: .nvmrc - - run: npm ci - - run: npm run lint - - run: npx tsc --noEmit - - run: npm test - # Proves the production build works, with the production values: NEXT_PUBLIC_* are inlined - # at build time, and lib/env.ts fails the build if one is missing. - - run: npm run build - env: - NEXT_PUBLIC_API_BASE_URL: ${{ vars.NEXT_PUBLIC_API_BASE_URL }} - NEXT_PUBLIC_ADMIN_APP_URL: ${{ vars.NEXT_PUBLIC_ADMIN_APP_URL }} - - deploy: - needs: test - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + # One job, not test + deploy: every job starts in a fresh container, so two jobs meant checking out, + # setting up Node, `npm ci` and building twice (~2 min each, 2026-11-08). The deploy steps only run + # for pushes to master; on pull requests the job ends after the build. The condition is spelled out + # on every deploy step rather than stored in an env flag: a flag compared as a string ('true') would + # skip the deploy silently - and green - if the runner ever rendered the boolean differently. + test-and-deploy: runs-on: ubuntu-latest env: DEPLOY_HOST: ${{ vars.DEPLOY_HOST }} @@ -48,8 +32,14 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: + # Same major as Passenger on the server (26.13.0 as of 2026-11-08). node-version-file: .nvmrc - run: npm ci + - run: npm run lint + - run: npx tsc --noEmit + - run: npm test + # The production build, with the production values: NEXT_PUBLIC_* are inlined at build time, + # and lib/env.ts fails the build if one is missing. On master this is also what gets deployed. - name: Build run: npm run build env: @@ -60,9 +50,11 @@ jobs: # own there (server.js serves .next/static), so an empty public/ is enough. Created here so # rsync --delete doesn't remove it on the server. - name: Prepare bundle + if: github.event_name == 'push' && github.ref == 'refs/heads/master' run: mkdir -p .next/standalone/public - name: SSH setup + if: github.event_name == 'push' && github.ref == 'refs/heads/master' env: DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }} @@ -79,6 +71,7 @@ jobs: printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$SSH_DIR/known_hosts" - name: Upload + if: github.event_name == 'push' && github.ref == 'refs/heads/master' run: | # Straight into the app folder (no release folders - decided 2026-11-08; a rollback is a # redeploy of an older commit). That folder is the one Plesk created for the subdomain, @@ -89,6 +82,7 @@ jobs: .next/standalone/ "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/" - name: Restart + if: github.event_name == 'push' && github.ref == 'refs/heads/master' run: | # Passenger restarts the app on its next request when tmp/restart.txt is touched. ssh -p "${DEPLOY_PORT:-22}" -i "$SSH_DIR/key" -o "UserKnownHostsFile=$SSH_DIR/known_hosts" \ @@ -98,7 +92,7 @@ jobs: # Optional until Plesk serves the Node app: set DEPLOY_SMOKE_URL then. Checks the page loads # and references the build's static files (the classic standalone failure is missing CSS/JS). - name: Smoke test - if: vars.DEPLOY_SMOKE_URL != '' + if: github.event_name == 'push' && github.ref == 'refs/heads/master' && vars.DEPLOY_SMOKE_URL != '' env: DEPLOY_SMOKE_URL: ${{ vars.DEPLOY_SMOKE_URL }} run: | @@ -112,5 +106,5 @@ jobs: echo "OK: page and $asset served" - name: Remove key - if: always() + if: always() && github.event_name == 'push' && github.ref == 'refs/heads/master' run: rm -f "$SSH_DIR/key" diff --git a/docs/deployment.md b/docs/deployment.md index bce4c9d..72a7eff 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -7,13 +7,15 @@ real deploy settles them - record the outcome here. ``` push to master ──▶ Gitea ──▶ runner (Docker container on the Plesk server) - ├─ test job: npm ci, lint, tsc, test, build - └─ deploy job: build ─ rsync over SSH ─▶ plesk-nachklang@server: - └─ touch tmp/restart.txt + └─ one job: npm ci, lint, tsc, test, build + └─ (master only) rsync over SSH ─▶ plesk-nachklang@server: + └─ touch tmp/restart.txt browser ──https──▶ Plesk (nginx + Passenger) ──▶ /server.js ``` -Pull requests only run the test job. +Pull requests run the same job up to the build; the deploy steps only run for pushes to master. +It used to be two jobs (test, then deploy); since every job starts in a fresh container that meant +`npm ci` and the build twice (~2 min each), so they were merged on 2026-11-08. ## Why SSH and not mounted paths @@ -155,7 +157,7 @@ to port 3000 if Passenger doesn't intercept. 4. **Back up the Angular build**: download `calendar.nachklang.art/` as a ZIP in Plesk's file manager. The first deploy replaces those files, and this backup is the quick way back. 5. **Merge** `feature/nextjs-rewrite` into master and watch the run under *Actions*. When the - deploy job has finished, the folder holds the Next app but Plesk still serves it as static + deploy steps have finished, the folder holds the Next app but Plesk still serves it as static files - **the subdomain is down from here until step 6** (no `index.html` any more). 6. **Step 5 above, right away** - switch the subdomain to the Node app. This is the moment the new app goes live; doing it right after the run keeps the gap to a few minutes. (Plesk might accept diff --git a/docs/gotchas.md b/docs/gotchas.md index 88d12f8..3615ba6 100644 --- a/docs/gotchas.md +++ b/docs/gotchas.md @@ -62,6 +62,15 @@ Collected during the rewrite (September 2026); the progress log in an `ssh host 'cmd'` never runs, exit 255). The deploy user uses plain `/bin/bash` instead. - **SSH is on port 42069**, not 22 (22 is closed); the deploy user is `plesk-nachklang`, not `nachklang`. +- **Jenkins deployed as root.** Files it copied into an app folder belong to `root:root`, so the + first Gitea deploy (as `plesk-nachklang`) fails with rsync "Operation not permitted" / "Permission + denied". Before switching an app, run `find . ! -user plesk-nachklang` in its folder and + `chown -R plesk-nachklang:psacln` what it lists (hit on the API, 2026-11-08; the calendar folder + only held files directly in a folder the user owned, so deleting them worked). +- **Every Gitea Actions job starts in a fresh container.** Splitting test and deploy into two jobs + repeats checkout, Node setup and `npm ci` (and here the build); one job with the deploy steps + conditioned on push-to-master is faster. Spell the condition out on each step instead of comparing + an env flag to `'true'` - a mismatch there skips the deploy silently and the run stays green. - **Disable the Jenkins job before merging to master**, or it runs `ng build` on the next push. ## shadcn / Base UI