The schedule trigger and its conditions in the jobs are gone; docs say that a content change needs no rebuild (NFR-10) and that production gets the same only once it is served by the CMS host. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
369 lines
15 KiB
YAML
369 lines
15 KiB
YAML
name: Continuous Integration
|
|
|
|
# Branchstrategie (zie aidlc-docs/.../operations/deployment/deployment-plan.md):
|
|
# - Pull request → controles, geen deploy
|
|
# - Merge/push naar master → controles + automatisch naar test
|
|
# - Handmatig, elke branch → controles + naar test als 'Deploy to Test' aan staat
|
|
# - Handmatig, release/* → controles + naar productie als 'Deploy to Production' aan staat
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
deploy_test:
|
|
description: 'Deploy to Test'
|
|
type: boolean
|
|
default: false
|
|
deploy_production:
|
|
description: 'Deploy to Production (alleen vanaf een release/*-branch)'
|
|
type: boolean
|
|
default: false
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
push:
|
|
branches: [master]
|
|
|
|
# Alleen bij pull requests een verouderde run afbreken; een deploy wordt nooit
|
|
# halverwege gestopt.
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
|
|
env:
|
|
NODE_VERSION: '24'
|
|
# Vaste Playwright-versie: levert Chromium voor linux-arm64 (er bestaat geen
|
|
# officiële Chrome voor ARM64, en Ubuntu's chromium is een snap die niet in
|
|
# een container werkt)
|
|
PLAYWRIGHT_VERSION: '1.55.0'
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: web
|
|
|
|
# Runners (labels per eigenschap; een job draait op een runner met al zijn
|
|
# runs-on-labels): 'linux' = elke vrije runner (Pi of pc), 'raspberry-pi' =
|
|
# alleen de Pi.
|
|
# Volgorde: Gitea geeft wachtende jobs uit in de volgorde van dit bestand.
|
|
# Daarom staan de deploys boven lighthouse: met één vrije runner gaat de deploy
|
|
# eerst, met twee draaien ze tegelijk.
|
|
jobs:
|
|
# lint, opmaak, tests (incl. property-based en axe), build en audit
|
|
check:
|
|
runs-on: linux
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
|
|
# pnpm-versie komt uit "packageManager" in web/package.json
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
package_json_file: web/package.json
|
|
|
|
- name: Get pnpm store directory
|
|
id: pnpm-store
|
|
run: echo "path=$(pnpm store path)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Cache pnpm store
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ steps.pnpm-store.outputs.path }}
|
|
key: pnpm-${{ hashFiles('web/pnpm-lock.yaml') }}
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Lint
|
|
run: pnpm lint
|
|
|
|
- name: Format
|
|
run: pnpm format:check
|
|
|
|
# Logt de fast-check-seed; opnieuw afspelen met FC_SEED=<seed> pnpm test
|
|
- name: Tests
|
|
run: pnpm test
|
|
|
|
# Sentry toont bij elke fout uit welke commit de build komt
|
|
# Dit artefact (dist) is ook wat naar productie gaat: bewust zonder
|
|
# OFFERINGS_URL, dus met de gecommitte pakketlijst. De testbuild met de
|
|
# pakketten uit het CMS is job build-test.
|
|
- name: Build
|
|
run: pnpm build
|
|
env:
|
|
VITE_RELEASE: ${{ github.sha }}
|
|
|
|
- name: Audit (productiepakketten, blokkerend)
|
|
run: pnpm audit:deps
|
|
|
|
- name: Audit (ontwikkeltools, alleen melden)
|
|
run: pnpm audit:dev
|
|
|
|
- name: Upload build artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: web/dist/client/
|
|
retention-days: 7
|
|
|
|
# De build voor de testsite: zelfde code als dist, maar met de pakketten uit
|
|
# het CMS van de testomgeving (OFFERINGS_URL uit de repo-variabele
|
|
# ASF_OFFERINGS_URL_TEST). Productie krijgt dit artefact nooit: die blijft op
|
|
# dist met de gecommitte lijst tot er een productie-CMS is.
|
|
build-test:
|
|
needs: check
|
|
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')
|
|
runs-on: linux
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
package_json_file: web/package.json
|
|
|
|
- name: Get pnpm store directory
|
|
id: pnpm-store
|
|
run: echo "path=$(pnpm store path)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Restore pnpm store
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ steps.pnpm-store.outputs.path }}
|
|
key: pnpm-${{ hashFiles('web/pnpm-lock.yaml') }}
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Build (testomgeving, pakketten uit het CMS)
|
|
run: pnpm build
|
|
env:
|
|
VITE_RELEASE: ${{ github.sha }}
|
|
OFFERINGS_URL: ${{ vars.ASF_OFFERINGS_URL_TEST }}
|
|
# De testsite staat op zichzelf: canonical, og:url, og:image,
|
|
# JSON-LD en sitemap wijzen naar het eigen adres, zodat een gedeelde
|
|
# link (WhatsApp, Discord) ook zijn eigen plaatje toont. Alleen in
|
|
# deze testbuild; het productie-artefact (job check) krijgt de
|
|
# variabele niet en houdt https://andreaslop.nl.
|
|
VITE_SITE_URL: https://test.andreaslop.nl
|
|
# Het contactformulier staat alleen in deze testbuild open; standaard
|
|
# (en in het productie-artefact) is het dicht. Productie aanzetten
|
|
# vraagt Bryans expliciete go (docs/go-live-checklist.md).
|
|
VITE_CONTACT_FORM_ENABLED: 'true'
|
|
|
|
- name: Upload build artifact (test)
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: dist-test
|
|
path: web/dist/client/
|
|
retention-days: 7
|
|
|
|
# Test wacht niet op Lighthouse: test is om te testen, de rapporten zie je
|
|
# achteraf. Lighthouse draait ernaast of erna (zie de volgorde bovenaan).
|
|
# Deploys alleen vanaf de Pi: die bereikt zichzelf zeker, en container-
|
|
# actions werken niet op Podman.
|
|
deploy-test:
|
|
needs: [check, build-test]
|
|
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')
|
|
runs-on: raspberry-pi
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
# Voor config/printCsp.ts (de exacte CSP in de controle na deploy)
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
|
|
- name: Download build artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dist-test
|
|
path: web/dist
|
|
|
|
# Alleen de clientmap hoort online: geen servermap, geen source maps
|
|
- name: Controle van de build
|
|
run: bash deploy/check-artifact.sh dist
|
|
|
|
# Eenvoudig: de testmap leegmaken en de nieuwe build erin zetten. Oude
|
|
# versies worden niet bewaard. Op de Pi draait ook de huidige
|
|
# WordPress-site; daarom weigert deze stap een lege variabele, '/', of
|
|
# een map waarin WordPress staat.
|
|
- name: Upload naar de testserver
|
|
env:
|
|
# Secrets via env, zodat bash tekens als $ of ` niet nog eens uitlegt
|
|
SSHPASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
|
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
|
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
|
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
|
DEPLOY_PATH: ${{ vars.DEPLOY_PATH_TEST }}
|
|
run: |
|
|
case "$DEPLOY_PATH" in
|
|
''|'/'|*' '*) echo "DEPLOY_PATH_TEST ontbreekt of is ongeldig: '$DEPLOY_PATH'"; exit 1 ;;
|
|
esac
|
|
sudo apt-get update && sudo apt-get install -y sshpass
|
|
SSH="sshpass -e ssh -p $SSH_PORT -o StrictHostKeyChecking=accept-new $SSH_USER@$SSH_HOST"
|
|
$SSH "set -e
|
|
if [ -e '$DEPLOY_PATH/wp-config.php' ] || [ -d '$DEPLOY_PATH/wp-content' ]; then
|
|
echo 'Geweigerd: $DEPLOY_PATH bevat WordPress'; exit 1
|
|
fi
|
|
mkdir -p '$DEPLOY_PATH'
|
|
find '$DEPLOY_PATH' -mindepth 1 -delete"
|
|
# De inhoud kopiëren (dist/*), niet de map zelf (dist/.): dan probeert
|
|
# scp de rechten van de doelmap niet te zetten, wat alleen de eigenaar
|
|
# mag. Zo zijn groeps-schrijfrechten op de doelmap genoeg.
|
|
# dotglob: ook bestanden die met een punt beginnen gaan mee.
|
|
shopt -s dotglob
|
|
sshpass -e scp -P "$SSH_PORT" -o StrictHostKeyChecking=accept-new -r dist/* "$SSH_USER@$SSH_HOST:$DEPLOY_PATH/"
|
|
echo "Gedeployd naar test: ${GITHUB_REF_NAME} (${GITHUB_SHA::7})"
|
|
|
|
# Vergelijkt wat de server teruggeeft met dist. Met de oude nginx-config
|
|
# (homepage voor elk pad) wordt deze stap rood: de nieuwe config moet er
|
|
# dus staan voor de deploy (zie pi-install-instructions.md).
|
|
- name: Controle na deploy
|
|
env:
|
|
HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_TEST }}
|
|
# 'true' zodra test.andreaslop.nl door de CMS-host (Api.AndreaSlopFotografie)
|
|
# wordt bediend in plaats van nginx: dan controleert het script ook de
|
|
# exacte CSP en de CMS-routes. Zet hem om samen met de proxy-route.
|
|
SERVED_BY_CMS: ${{ vars.ASF_TEST_SERVED_BY_CMS }}
|
|
run: |
|
|
if [ -z "$HEALTH_URL" ]; then echo "Geen HEALTH_CHECK_URL_TEST ingesteld; overgeslagen"; exit 0; fi
|
|
if [ "$SERVED_BY_CMS" = "true" ]; then
|
|
EXPECTED_CSP="$(node config/printCsp.ts)" bash deploy/verify-deployment.sh "$HEALTH_URL" dist --test --cms
|
|
else
|
|
bash deploy/verify-deployment.sh "$HEALTH_URL" dist --test
|
|
fi
|
|
echo "Test bereikbaar en gelijk aan de build"
|
|
|
|
# Lighthouse tegen de gebouwde site (mobiel en desktop)
|
|
lighthouse:
|
|
needs: check
|
|
runs-on: linux
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
package_json_file: web/package.json
|
|
|
|
- name: Get pnpm store directory
|
|
id: pnpm-store
|
|
run: echo "path=$(pnpm store path)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Restore pnpm store
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ steps.pnpm-store.outputs.path }}
|
|
key: pnpm-${{ hashFiles('web/pnpm-lock.yaml') }}
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Download build artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: web/dist/client
|
|
|
|
- name: Install Chromium
|
|
run: |
|
|
pnpm dlx playwright@${{ env.PLAYWRIGHT_VERSION }} install --with-deps chromium
|
|
CHROME_PATH="$(find "$HOME/.cache/ms-playwright" -path '*chrome-linux*' -name chrome -type f | head -n 1)"
|
|
test -x "$CHROME_PATH"
|
|
echo "CHROME_PATH=$CHROME_PATH" >> "$GITHUB_ENV"
|
|
"$CHROME_PATH" --version
|
|
|
|
# De serverregeltests (e2e/serverRules.e2e.ts) starten een echte nginx met
|
|
# het gegenereerde testblok (BR-HST-24). nginx komt uit de distributie:
|
|
# het runner-image heeft 1.24, de hosting-Pi draait 1.30.6. Dat verschil
|
|
# is bewust geaccepteerd; de gebruikte directives zijn oud en stabiel.
|
|
# lftp is nodig voor de uploadtests van de productiedeploy. De jobs draaien
|
|
# met het netwerk van de host, dus de service van het pakket mag niet
|
|
# starten (policy-rc.d): die zou poort 80 van de runner proberen te pakken.
|
|
# De test draait zijn eigen onbevoorrechte nginx op een vrije poort.
|
|
# nginx -v maakt de versie in de log zichtbaar.
|
|
- name: Install nginx and lftp (serverregeltests)
|
|
run: |
|
|
printf '#!/bin/sh\nexit 101\n' | sudo tee /usr/sbin/policy-rc.d > /dev/null
|
|
sudo chmod +x /usr/sbin/policy-rc.d
|
|
sudo apt-get update && sudo apt-get install -y nginx lftp
|
|
nginx -v
|
|
|
|
# Browsertests tegen de gebouwde site (preview-server op dist/client). Chrome
|
|
# komt uit de stap hierboven; dezelfde containerflags als bij Lighthouse.
|
|
# CI staat hier expliciet aan: zonder nginx moet de job falen en niet
|
|
# stilzwijgend de serverregeltests overslaan.
|
|
- name: Browsertests
|
|
env:
|
|
CI: 'true'
|
|
LIGHTHOUSE_CHROME_FLAGS: '--no-sandbox --headless=new --disable-dev-shm-usage'
|
|
run: pnpm e2e
|
|
|
|
# Chrome in een container (gelezen door lighthouserc.cjs, zie daar waarom
|
|
# niet via LHCI_*):
|
|
# --no-sandbox: als root weigert Chrome anders te starten
|
|
# --disable-dev-shm-usage: /dev/shm is in een container maar 64 MB; met
|
|
# de grote hero-foto's crasht het tabblad anders (TARGET_CRASHED)
|
|
# Performance op de Pi is niet representatief (CPU-vertraging bovenop een
|
|
# trage machine): hier alleen melden, blokkerend in `pnpm check` op een pc.
|
|
# Toegankelijkheid, Best Practices en SEO blokkeren wel.
|
|
- name: Lighthouse
|
|
env:
|
|
LIGHTHOUSE_CHROME_FLAGS: '--no-sandbox --headless=new --disable-dev-shm-usage'
|
|
LIGHTHOUSE_PERFORMANCE: warn
|
|
run: pnpm lighthouse
|
|
|
|
- name: Upload Lighthouse-rapporten
|
|
if: always()
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: lighthouse-reports
|
|
path: web/lighthouse-reports/
|
|
retention-days: 14
|
|
|
|
# Productie wacht wel op Lighthouse: toegankelijkheid, Best Practices en SEO
|
|
# moeten slagen voordat er iets live gaat.
|
|
deploy-production:
|
|
needs: [check, lighthouse]
|
|
# Alleen handmatig, en alleen vanaf een release-branch
|
|
if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true' && startsWith(github.ref, 'refs/heads/release/')
|
|
runs-on: raspberry-pi
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download build artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: web/dist
|
|
|
|
# FTP met TLS (verplicht) naar de webhoster, in drie rondes (zie
|
|
# deploy/upload-production.sh): eerst alles behalve HTML en web.config,
|
|
# dan web.config en alle HTML, en pas daarna oude bestanden opruimen. Zo
|
|
# verwijst een bezoeker nooit naar een bestand dat er nog niet staat.
|
|
# Deze job kan pas draaien als er een webhost is.
|
|
- name: Upload naar productie (FTPS)
|
|
env:
|
|
FTP_HOST: ${{ secrets.FTP_HOST }}
|
|
FTP_USER: ${{ secrets.FTP_USERNAME }}
|
|
LFTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
|
|
FTP_DIR: ${{ vars.FTP_REMOTE_DIR || 'wwwroot' }}
|
|
run: |
|
|
sudo apt-get update && sudo apt-get install -y lftp
|
|
bash deploy/upload-production.sh dist "$FTP_DIR"
|
|
echo "Gedeployd naar productie: ${GITHUB_REF_NAME} (${GITHUB_SHA::7})"
|
|
|
|
- name: Controle na deploy
|
|
env:
|
|
HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }}
|
|
run: |
|
|
if [ -z "$HEALTH_URL" ]; then echo "Geen HEALTH_CHECK_URL_PRODUCTION ingesteld; overgeslagen"; exit 0; fi
|
|
bash deploy/verify-deployment.sh "$HEALTH_URL" dist
|
|
echo "Productie bereikbaar en gelijk aan de build"
|