Tests every push and pull request (tsc, unit tests); pushes to master build, prune dev dependencies and rsync dist/, src/, public/, node_modules/ and package.json over SSH as the Plesk subscription user, then restart Passenger via tmp/restart.txt. Only the app's own folders are mirrored with --delete; .env, logs/ and tmp/ in the app root are never touched. Optional smoke test via DEPLOY_SMOKE_URL. Same pattern as the calendar frontend; setup and what the deploy may touch are in docs/deployment.md. Also removes leftovers: bcrypt (unused since better-auth, and the only production dependency with a native build) and the SonarQube setup (sonar-project.properties, vitest-sonar-reporter). Checked locally: actionlint; in a clean node:26 container npm ci, tsc, 233 unit tests, build and prune; the pruned bundle started against a throwaway MariaDB (public feed, iCal, /docs, /admin/me); the upload step against a throwaway SSH server with .env, logs/ and tmp/ in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
105 lines
4.5 KiB
YAML
105 lines
4.5 KiB
YAML
# Tests every push and pull request; deploys pushes to master to the Plesk server.
|
|
# Setup and what the deploy may touch: docs/deployment.md.
|
|
#
|
|
# Same pattern as the calendar frontend (Calendar_Frontend/.gitea/workflows/deploy.yml): build here,
|
|
# deliver over SSH as the Plesk subscription user, restart Passenger. Unlike there, the app folder
|
|
# also holds things the deploy must never touch (.env with the secrets, logs/, tmp/), so only the
|
|
# app's own folders are synced with --delete and nothing is deleted at the top level.
|
|
name: Test and deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
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'
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
|
|
DEPLOY_PORT: ${{ vars.DEPLOY_PORT }}
|
|
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
|
|
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
|
|
# Absolute on purpose: rsync passes its -e string to ssh without a shell, and ssh expands "~"
|
|
# from the passwd entry, not $HOME (see the calendar frontend's docs/gotchas.md).
|
|
SSH_DIR: /tmp/deploy-ssh
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version-file: .nvmrc
|
|
- run: npm ci
|
|
- run: npm run build
|
|
# Only runtime dependencies go to the server (no typescript, vitest, ...).
|
|
- run: npm prune --omit=dev
|
|
|
|
- name: SSH setup
|
|
env:
|
|
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
|
|
run: |
|
|
test -n "$DEPLOY_HOST" && test -n "$DEPLOY_USER" && test -n "$DEPLOY_PATH"
|
|
if ! command -v rsync >/dev/null 2>&1 || ! command -v ssh >/dev/null 2>&1; then
|
|
apt-get update && apt-get install -y --no-install-recommends rsync openssh-client
|
|
fi
|
|
install -m 700 -d "$SSH_DIR"
|
|
printf '%s\n' "$DEPLOY_SSH_KEY" > "$SSH_DIR/key"
|
|
chmod 600 "$SSH_DIR/key"
|
|
# Pinned host key, never trust-on-first-use.
|
|
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$SSH_DIR/known_hosts"
|
|
|
|
- name: Upload
|
|
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"
|
|
# The app's own folders, each mirrored exactly (--delete within the folder only).
|
|
# src/ is needed at runtime: swagger-jsdoc reads the route docs from src/models/**/*.ts.
|
|
for dir in dist src public node_modules; do
|
|
rsync -az --delete -e "$rsh" "$dir/" "$target/$dir/"
|
|
done
|
|
# Single files at the top level, without --delete: .env, logs/ and tmp/ live there too.
|
|
# package.json is what makes Node treat dist/ as ES modules ("type": "module").
|
|
rsync -az -e "$rsh" package.json package-lock.json "$target/"
|
|
|
|
- name: Restart
|
|
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" \
|
|
-o IdentitiesOnly=yes -o BatchMode=yes "$DEPLOY_USER@$DEPLOY_HOST" \
|
|
"mkdir -p '$DEPLOY_PATH/tmp' && touch '$DEPLOY_PATH/tmp/restart.txt'"
|
|
|
|
# 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 != ''
|
|
env:
|
|
DEPLOY_SMOKE_URL: ${{ vars.DEPLOY_SMOKE_URL }}
|
|
run: |
|
|
# Passenger starts the app on the first request after the restart; give it a moment.
|
|
for _ in 1 2 3 4 5 6; do
|
|
if curl -fsS -o /dev/null "$DEPLOY_SMOKE_URL"; then echo "OK: $DEPLOY_SMOKE_URL"; exit 0; fi
|
|
sleep 5
|
|
done
|
|
echo "Smoke test failed: $DEPLOY_SMOKE_URL"
|
|
exit 1
|
|
|
|
- name: Remove key
|
|
if: always()
|
|
run: rm -f "$SSH_DIR/key"
|