# Tests every push and pull request; deploys pushes to master to the Plesk server. # Setup (secrets, variables, Plesk): docs/deployment.md. # # Deploy = build here, rsync the standalone bundle over SSH into the Node app's folder as the # subscription's own system user, then restart Passenger. No host paths are mounted into the # runner and no Docker socket is needed - the same pattern works for any Node app on Plesk. name: Test and deploy on: push: branches: [master] pull_request: jobs: # 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 }} DEPLOY_PORT: ${{ vars.DEPLOY_PORT }} DEPLOY_USER: ${{ vars.DEPLOY_USER }} DEPLOY_PATH: ${{ vars.DEPLOY_PATH }} # Absolute paths on purpose: rsync hands its -e string to ssh without a shell, and ssh # resolves "~" from the passwd entry, not $HOME - so "~/.ssh/..." can point somewhere else # than where the previous step wrote the key (found in a local dry run, 2026-11-08). SSH_DIR: /tmp/deploy-ssh 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 # 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: NEXT_PUBLIC_API_BASE_URL: ${{ vars.NEXT_PUBLIC_API_BASE_URL }} NEXT_PUBLIC_ADMIN_APP_URL: ${{ vars.NEXT_PUBLIC_ADMIN_APP_URL }} # Passenger wants a document root inside the app root; the app has no static files of its # 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 }} 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: a job that accepts any key would hand the # bundle to whoever answers on that address. 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, # so --delete leaves alone what isn't ours: tmp/ (Passenger's restart.txt) and # .well-known/ (in case Plesk puts certificate challenges there). rsync -az --delete --exclude '/tmp/' --exclude '/.well-known/' \ -e "ssh -p ${DEPLOY_PORT:-22} -i $SSH_DIR/key -o UserKnownHostsFile=$SSH_DIR/known_hosts -o IdentitiesOnly=yes -o BatchMode=yes" \ .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" \ -o IdentitiesOnly=yes -o BatchMode=yes "$DEPLOY_USER@$DEPLOY_HOST" \ "mkdir -p '$DEPLOY_PATH/tmp' && touch '$DEPLOY_PATH/tmp/restart.txt'" # 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: github.event_name == 'push' && github.ref == 'refs/heads/master' && vars.DEPLOY_SMOKE_URL != '' env: DEPLOY_SMOKE_URL: ${{ vars.DEPLOY_SMOKE_URL }} run: | for _ in 1 2 3 4 5 6; do if page="$(curl -fsS "$DEPLOY_SMOKE_URL")"; then break; fi sleep 5 done echo "$page" | grep -q '/_next/static/' asset="$(echo "$page" | grep -o '/_next/static/[^"]*\.css' | head -1)" curl -fsS -o /dev/null "${DEPLOY_SMOKE_URL%/}$asset" echo "OK: page and $asset served" - name: Remove key if: always() && github.event_name == 'push' && github.ref == 'refs/heads/master' run: rm -f "$SSH_DIR/key"