81 lines
2.7 KiB
YAML
81 lines
2.7 KiB
YAML
name: CI · Test & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
# ─────────────────────────────────────────────
|
|
# JOB 1: Playwright smoke tests
|
|
# ─────────────────────────────────────────────
|
|
test:
|
|
name: Playwright tests
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Install Playwright + Chromium system deps
|
|
run: npx playwright install chromium --with-deps
|
|
|
|
# Start server AND run tests in the same shell so the background
|
|
# process is guaranteed alive for the full test run.
|
|
- name: Start server & run tests
|
|
run: |
|
|
npx --yes serve . --listen 9090 &
|
|
SERVER_PID=$!
|
|
sleep 3
|
|
npx playwright test --reporter=list
|
|
kill $SERVER_PID 2>/dev/null || true
|
|
env:
|
|
APP_URL: http://localhost:9090
|
|
|
|
# ─────────────────────────────────────────────
|
|
# JOB 2: Deploy to VPS (only if tests pass)
|
|
# ─────────────────────────────────────────────
|
|
deploy:
|
|
name: Deploy to VPS
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
printf '%s\n' "$VPS_SSH_KEY" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
ssh-keyscan -H 80.225.185.50 >> ~/.ssh/known_hosts
|
|
env:
|
|
VPS_SSH_KEY: ${{ secrets.VPS_SSH_KEY }}
|
|
|
|
- name: Upload static files
|
|
run: |
|
|
scp -i ~/.ssh/id_ed25519 index.html comarca-paths.js \
|
|
ubuntu@80.225.185.50:/srv/docker/data/comarques/public/
|
|
|
|
- name: Upload server files & rebuild
|
|
run: |
|
|
scp -i ~/.ssh/id_ed25519 server.js package.json Dockerfile \
|
|
ubuntu@80.225.185.50:/srv/docker/builds/comarques/
|
|
ssh -i ~/.ssh/id_ed25519 ubuntu@80.225.185.50 \
|
|
"cd /srv/docker/builds/comarques \
|
|
&& docker build -t comarques-de-catalunya:latest . \
|
|
&& cd /srv/docker/compose \
|
|
&& docker compose up -d comarques"
|
|
|
|
- name: Health check
|
|
run: |
|
|
sleep 5
|
|
curl -fs https://comarques.jaumegar.work/api/health \
|
|
|| (echo "Health check failed" && exit 1)
|