Run tests and deploy in one Gitea Actions job
Test and deploy / test-and-deploy (pull_request) Successful in 33s

Two jobs meant checking out, setting up Node and running npm ci (and in the
frontend the build) twice, about two minutes each, because every job starts
in a fresh container. Now one job tests and, for pushes to master only,
deploys. The push-to-master condition is spelled out on every deploy step
instead of an env flag compared to 'true', which would skip the deploy
silently and stay green if the boolean were rendered differently. A failed
test still stops the deploy (an if: without a status function implies
success()).

Docs: the one-job layout, and that Jenkins deployed as root - files it left
in an app folder must be chowned to the subscription user before the first
Gitea deploy (hit on the API).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PaddyandClaude Opus 5.5 committed 2026-11-08 22:51:30 +01:00
1 parent 1bfcc7a079
commit ae4f153482
2 files changed
+41 -25

No files matched your search

+23 -21
View File
@@ -13,23 +13,12 @@ on:
pull_request: pull_request:
jobs: jobs:
test: # One job, not test + deploy: every job starts in a fresh container, so two jobs meant checking out,
runs-on: ubuntu-latest # setting up Node and running `npm ci` twice (~2 min each, 2026-11-08). The deploy steps only run
steps: # for pushes to master; on pull requests the job ends after the tests. The condition is spelled out
- uses: actions/checkout@v4 # on every deploy step rather than stored in an env flag: a flag compared as a string ('true') would
- uses: actions/setup-node@v4 # skip the deploy silently - and green - if the runner ever rendered the boolean differently.
with: test-and-deploy:
node-version-file: .nvmrc
- run: npm ci
- run: npx tsc --noEmit
# Unit tests only. The integration tests (npm run test:integration) start their own MariaDB
# container and aren't run here.
# FEEDBACK_IP_SALT (which the Jenkins job exported) isn't needed: vitest.config.ts sets one.
- run: npm test
deploy:
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }} DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
@@ -45,11 +34,22 @@ jobs:
with: with:
node-version-file: .nvmrc node-version-file: .nvmrc
- run: npm ci - run: npm ci
- run: npm run build - run: npx tsc --noEmit
# Unit tests only. The integration tests (npm run test:integration) start their own MariaDB
# container and aren't run here.
# FEEDBACK_IP_SALT (which the Jenkins job exported) isn't needed: vitest.config.ts sets one.
- run: npm test
- name: Build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: npm run build
# Only runtime dependencies go to the server (no typescript, vitest, ...). # Only runtime dependencies go to the server (no typescript, vitest, ...).
- run: npm prune --omit=dev - name: Prune dev dependencies
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: npm prune --omit=dev
- name: SSH setup - name: SSH setup
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
env: env:
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }} DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
@@ -65,6 +65,7 @@ jobs:
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$SSH_DIR/known_hosts" printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$SSH_DIR/known_hosts"
- name: Upload - name: Upload
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: | run: |
rsh="ssh -p ${DEPLOY_PORT:-22} -i $SSH_DIR/key -o UserKnownHostsFile=$SSH_DIR/known_hosts -o IdentitiesOnly=yes -o BatchMode=yes" rsh="ssh -p ${DEPLOY_PORT:-22} -i $SSH_DIR/key -o UserKnownHostsFile=$SSH_DIR/known_hosts -o IdentitiesOnly=yes -o BatchMode=yes"
target="$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH" target="$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH"
@@ -78,6 +79,7 @@ jobs:
rsync -az -e "$rsh" package.json package-lock.json "$target/" rsync -az -e "$rsh" package.json package-lock.json "$target/"
- name: Restart - name: Restart
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: | run: |
# Passenger restarts the app on its next request when tmp/restart.txt is touched. # 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" \ ssh -p "${DEPLOY_PORT:-22}" -i "$SSH_DIR/key" -o "UserKnownHostsFile=$SSH_DIR/known_hosts" \
@@ -87,7 +89,7 @@ jobs:
# Set DEPLOY_SMOKE_URL to an endpoint that must answer 200 without a session, e.g. # Set DEPLOY_SMOKE_URL to an endpoint that must answer 200 without a session, e.g.
# https://api.nachklang.art/calendar/events/public/json (what nachklang.art itself reads). # https://api.nachklang.art/calendar/events/public/json (what nachklang.art itself reads).
- name: Smoke test - name: Smoke test
if: vars.DEPLOY_SMOKE_URL != '' if: github.event_name == 'push' && github.ref == 'refs/heads/master' && vars.DEPLOY_SMOKE_URL != ''
env: env:
DEPLOY_SMOKE_URL: ${{ vars.DEPLOY_SMOKE_URL }} DEPLOY_SMOKE_URL: ${{ vars.DEPLOY_SMOKE_URL }}
run: | run: |
@@ -100,5 +102,5 @@ jobs:
exit 1 exit 1
- name: Remove key - name: Remove key
if: always() if: always() && github.event_name == 'push' && github.ref == 'refs/heads/master'
run: rm -f "$SSH_DIR/key" run: rm -f "$SSH_DIR/key"
+18 -4
View File
@@ -8,12 +8,13 @@ Node.js App").
``` ```
push to master ──▶ Gitea ──▶ runner (container on the server) push to master ──▶ Gitea ──▶ runner (container on the server)
├─ test job: npm ci, tsc --noEmit, npm test (unit tests) └─ one job: npm ci, tsc --noEmit, npm test (unit tests)
└─ deploy job: npm ci, build, prune dev deps ─ rsync over SSH ─▶ └─ (master only) build, prune dev deps ─ rsync over SSH ─▶
plesk-nachklang@nachklang.art:<app root> + tmp/restart.txt plesk-nachklang@nachklang.art:<app root> + tmp/restart.txt
``` ```
Pull requests only run the test job. Pull requests run the same job up to the tests; the deploy steps only run for pushes to master. It
used to be two jobs, which ran `npm ci` twice (~2 min each); merged into one on 2026-11-08.
## Plesk (as configured, 2026-11-08) ## Plesk (as configured, 2026-11-08)
@@ -69,8 +70,14 @@ is the one nachklang.art itself depends on.
## Switchover (done once) ## Switchover (done once)
1. Pause the Jenkins API job (done 2026-11-08). 1. Pause the Jenkins API job (done 2026-11-08).
1a. **Fix file ownership** (as root): Jenkins deployed as **root**, so `dist/`, `src/` and
`node_modules/` were `root:root`, and the first Gitea deploy failed with rsync "Operation not
permitted" / "Permission denied" - the subscription user can't change root's files. Fixed with
`chown -R plesk-nachklang:psacln dist src node_modules` in the app root (the group of the files
the app creates itself, e.g. `.env`, `logs/`); then re-run the failed job.
Check: `find . ! -user plesk-nachklang` prints nothing.
2. Set `DEPLOY_PATH` and `DEPLOY_SMOKE_URL`. 2. Set `DEPLOY_PATH` and `DEPLOY_SMOKE_URL`.
3. Open a PR → green test job → merge → watch the deploy job. Unlike the calendar there is no gap: 3. Open a PR → green run → merge → watch the deploy steps. Unlike the calendar there is no gap:
the folder keeps working while files are replaced, and Passenger restarts on the next request. the folder keeps working while files are replaced, and Passenger restarts on the next request.
4. Check `https://api.nachklang.art/docs` and the calendar/feedback/tickets apps. 4. Check `https://api.nachklang.art/docs` and the calendar/feedback/tickets apps.
@@ -93,6 +100,13 @@ Not checked: the workflow on the real runner.
## Notes ## Notes
- There was **no `package.json` on the server** before the first rsync deploy (Jenkins never copied
it); `dist/app.js` still ran as ES modules, probably because Node ≥ 22 detects ES module syntax on
its own [inference, not checked]. The deploy now ships `package.json`, so it doesn't depend on that.
- A failed upload leaves new and old files mixed in `dist/`, but the running app is unaffected:
the restart step is skipped, so Passenger keeps the old code in memory until the next deploy (or an
unplanned restart - fix and re-run soon).
- `bcrypt` was removed on 2026-11-08: nothing imported it any more (passwords moved to better-auth, - `bcrypt` was removed on 2026-11-08: nothing imported it any more (passwords moved to better-auth,
which hashes with its own scrypt). It was the only production dependency with a native build step. which hashes with its own scrypt). It was the only production dependency with a native build step.
- `FEEDBACK_IP_SALT`, which the Jenkins test step exported, isn't needed in CI: `vitest.config.ts` - `FEEDBACK_IP_SALT`, which the Jenkins test step exported, isn't needed in CI: `vitest.config.ts`