`scp -r dist/.` also sets the mode of the target folder, which only its owner may do. Copying the contents (`dist/*`, with dotglob for hidden files) leaves the folder itself alone, so group write access on the test folder is enough. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
264 lines
9.7 KiB
YAML
264 lines
9.7 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
|
|
|
|
jobs:
|
|
# lint, opmaak, tests (incl. property-based en axe), build en audit
|
|
check:
|
|
runs-on: ubuntu-latest
|
|
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
|
|
|
|
- name: Build
|
|
run: pnpm build
|
|
|
|
- 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/
|
|
retention-days: 7
|
|
|
|
# Lighthouse tegen de gebouwde site (mobiel en desktop)
|
|
lighthouse:
|
|
needs: check
|
|
runs-on: ubuntu-latest
|
|
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
|
|
|
|
- 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
|
|
|
|
# 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
|
|
|
|
# Test wacht niet op Lighthouse: test is om te testen, de rapporten zie je
|
|
# achteraf. Lighthouse draait ernaast.
|
|
deploy-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: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download build artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: web/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})"
|
|
|
|
- name: Controle na deploy
|
|
env:
|
|
HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_TEST }}
|
|
run: |
|
|
if [ -z "$HEALTH_URL" ]; then echo "Geen HEALTH_CHECK_URL_TEST ingesteld; overgeslagen"; exit 0; fi
|
|
curl -fsS -o /dev/null --retry 5 --retry-delay 3 "$HEALTH_URL"
|
|
curl -fsSI "$HEALTH_URL" | grep -qi '^content-security-policy:'
|
|
echo "Test bereikbaar met security headers"
|
|
|
|
# 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: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download build artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: web/dist
|
|
|
|
- name: IIS-configuratie toevoegen
|
|
run: cp deploy/iis/web.config dist/web.config
|
|
|
|
# FTP met TLS (verplicht) naar de webhoster. Eerst alle bestanden behalve
|
|
# index.html, dan index.html, en pas daarna oude bestanden opruimen. Zo
|
|
# verwijst een bezoeker nooit naar een bestand dat er nog niet staat.
|
|
- 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
|
|
lftp --env-password -u "$FTP_USER" "$FTP_HOST" -e "
|
|
set ftp:ssl-force true;
|
|
set ftp:ssl-protect-data true;
|
|
set net:max-retries 3;
|
|
mirror --reverse --verbose --exclude-glob index.html dist/ $FTP_DIR/;
|
|
put -O $FTP_DIR dist/index.html;
|
|
mirror --reverse --delete --verbose dist/ $FTP_DIR/;
|
|
quit"
|
|
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
|
|
curl -fsS -o /dev/null --retry 5 --retry-delay 3 "$HEALTH_URL"
|
|
curl -fsSI "$HEALTH_URL" | grep -qi '^content-security-policy:'
|
|
echo "Productie bereikbaar met security headers"
|