Run tests and deploy in one Gitea Actions job #23

Merged
Paddy merged 1 commits from feature/ci-single-job into master 2026-11-08 21:53:59 +00:00
2 changed files with 41 additions and 25 deletions
Showing only changes of commit ae4f153482 - Show all commits

No files matched your search

+23 -21
View File
@@ -13,23 +13,12 @@ on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
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'
# One job, not test + deploy: every job starts in a fresh container, so two jobs meant checking out,
# setting up Node and running `npm ci` twice (~2 min each, 2026-11-08). The deploy steps only run
# for pushes to master; on pull requests the job ends after the tests. 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 }}
@@ -45,11 +34,22 @@ jobs:
with:
node-version-file: .nvmrc
- 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, ...).
- 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
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 }}
@@ -65,6 +65,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: |
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"
@@ -78,6 +79,7 @@ jobs:
rsync -az -e "$rsh" package.json package-lock.json "$target/"
- 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" \
@@ -87,7 +89,7 @@ jobs:
# 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).
- 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: |
@@ -100,5 +102,5 @@ jobs:
exit 1
- name: Remove key
if: always()
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/master'
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)
├─ test job: npm ci, tsc --noEmit, npm test (unit tests)
└─ deploy job: npm ci, build, prune dev deps ─ rsync over SSH ─▶
└─ one job: npm ci, tsc --noEmit, npm test (unit tests)
└─ (master only) build, prune dev deps ─ rsync over SSH ─▶
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)
@@ -69,8 +70,14 @@ is the one nachklang.art itself depends on.
## Switchover (done once)
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`.
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.
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
- 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,
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`