Files
Calendar_Frontend/.gitea/workflows/deploy.yml
T
PaddyandClaude Opus 5.5 b0cd657fd9 Deploy with Gitea Actions instead of Jenkins
Tests every push and pull request (lint, typecheck, Vitest, production
build); pushes to master build the standalone bundle in the runner and
rsync it over SSH as the subscription user into the subdomain's Plesk
folder, then restart Passenger via tmp/restart.txt. No mounted host paths;
rsync --delete leaves tmp/ and .well-known/ alone. Optional smoke test once
DEPLOY_SMOKE_URL is set.

Setup (deploy key, pinned host key, Gitea secrets and variables, Plesk
Node.js settings) and the switchover order are in docs/deployment.md.
Checked locally with actionlint and against a throwaway SSH server, which
also caught "~" in the rsync -e string resolving to the wrong home.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 21:09:19 +01:00

117 lines
5.1 KiB
YAML

# 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:
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'
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:
node-version-file: .nvmrc
- run: npm ci
- 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
run: mkdir -p .next/standalone/public
- 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: 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
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
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: 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()
run: rm -f "$SSH_DIR/key"