Files
SlpSoftware/.gitea/workflows/continuous_integration.yaml
SluijsensandClaude Sonnet 5 ea3ad38bdc
Continuous Integration / config (pull_request) Successful in 9s
Continuous Integration / prepare (pull_request) Successful in 1m18s
Continuous Integration / build-production (pull_request) Skipped
Continuous Integration / build (pull_request) Successful in 2m0s
Continuous Integration / test (pull_request) Successful in 1m53s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Verwijder automatische test-deploy bij PR's
De tijdelijke pull_request-conditie in deploy-test zorgde dat elke PR
automatisch naar test deployde. Dat is niet meer gewenst: een
test-deploy vanaf een feature-branch kan al zonder PR via een
handmatige workflow_dispatch-run met 'Deploy to Test' aangevinkt.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-17 10:18:06 +02:00

291 lines
12 KiB
YAML

name: Continuous Integration
on:
workflow_dispatch:
inputs:
deploy_production:
description: 'Deploy to Production'
type: boolean
default: false
# Bij een handmatige run wordt standaard NIET naar test gedeployed
# (default false), analoog aan deploy_production hierboven - je vinkt
# dit bewust aan. Dit is los van de automatische testdeploy bij een
# push naar master (zie de 'if' van de deploy-test-job hieronder), die
# altijd blijft gebeuren ongeacht dit vinkje.
deploy_test:
description: 'Deploy to Test'
type: boolean
default: false
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [master]
# Annuleert een lopende workflow-run voor dezelfde PR zodra er een nieuwe push
# naar die PR gebeurt (bv. een extra commit tijdens review) - zo draait de CI
# niet nodeloos door op een verouderde commit. De group-key valt terug op
# github.run_id (altijd uniek) voor niet-PR events (push naar master,
# workflow_dispatch), zodat die runs elkaar NOOIT annuleren - met name de
# automatische test-deploy bij een push naar master mag niet halverwege
# afgebroken worden door een snel daaropvolgende tweede push.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
# Herbruikbare instellingen voor deze workflow. Pas deze aan op één plek als
# de Node/pnpm-versie, de artifact-naam/pad of de testdeploy-bestemming
# wijzigt. Let op: de env-context is NIET beschikbaar in de `with:`-inputs
# van een aangeroepen reusable workflow (zie de `config`-job hieronder, die
# dit oplost door deze waarden via job-outputs door te geven aan de
# `deploy-test`-job).
env:
NODE_VERSION: '20'
PNPM_VERSION: '9'
ARTIFACT_NAME: dist
ARTIFACT_NAME_PRODUCTION: dist-production
ARTIFACT_PATH: dist/
DEPLOY_ENVIRONMENT: test
# Niet hardcoded: DEPLOY_PATH komt uit een Gitea Actions repository variable
# (Repository → Settings → Actions → Variables), zodat het pad per omgeving
# aangepast kan worden zonder de workflow zelf te wijzigen. Zie
# deployment-instructions.md voor de eenmalige setup van deze variable.
DEPLOY_PATH: ${{ vars.DEPLOY_PATH_TEST }}
DEPLOY_ENVIRONMENT_PRODUCTION: production
DEPLOY_PATH_PRODUCTION: ${{ vars.DEPLOY_PATH_PRODUCTION }}
jobs:
# Geeft de env-variabelen hierboven door als job-outputs, zodat ze ook
# gebruikt kunnen worden in de `with:`-sectie van de `deploy-test`-job
# hieronder (waar de env-context zelf niet beschikbaar is, omdat dat een
# aanroep naar een reusable workflow is).
config:
runs-on: ubuntu-latest
outputs:
artifact_name: ${{ steps.set.outputs.artifact_name }}
artifact_name_production: ${{ steps.set.outputs.artifact_name_production }}
deploy_environment: ${{ steps.set.outputs.deploy_environment }}
deploy_path: ${{ steps.set.outputs.deploy_path }}
deploy_environment_production: ${{ steps.set.outputs.deploy_environment_production }}
deploy_path_production: ${{ steps.set.outputs.deploy_path_production }}
steps:
- id: set
run: |
echo "artifact_name=${{ env.ARTIFACT_NAME }}" >> "$GITHUB_OUTPUT"
echo "artifact_name_production=${{ env.ARTIFACT_NAME_PRODUCTION }}" >> "$GITHUB_OUTPUT"
echo "deploy_environment=${{ env.DEPLOY_ENVIRONMENT }}" >> "$GITHUB_OUTPUT"
echo "deploy_path=${{ env.DEPLOY_PATH }}" >> "$GITHUB_OUTPUT"
echo "deploy_environment_production=${{ env.DEPLOY_ENVIRONMENT_PRODUCTION }}" >> "$GITHUB_OUTPUT"
echo "deploy_path_production=${{ env.DEPLOY_PATH_PRODUCTION }}" >> "$GITHUB_OUTPUT"
prepare:
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:
version: ${{ env.PNPM_VERSION }}
- 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('pnpm-lock.yaml') }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
build:
needs: prepare
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:
version: ${{ env.PNPM_VERSION }}
- 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('pnpm-lock.yaml') }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
env:
VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }}
# Gitea-variable heet VITE_UMAMI_WEBSITE_ID_TEST (niet zonder suffix),
# analoog aan VITE_UMAMI_WEBSITE_ID_PRODUCTION in de build-production
# job hieronder. Linkerkant (VITE_UMAMI_WEBSITE_ID) is wél altijd
# gelijk: dat is de Vite-buildtime-envvar-naam die de app verwacht
# (zie src/components/UmamiAnalytics.tsx), niet aan te passen.
VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_TEST }}
# Sentry DSN is niet gevoelig (veilig om in de client-bundle te zitten),
# daarom een Gitea Actions "vars"-waarde i.p.v. een secret. Optioneel:
# als deze niet is ingesteld, wordt Sentry-logging simpelweg overgeslagen
# (zie src/main.tsx) en blijft alleen console-logging actief.
VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }}
# Build-time tag die de Sentry environment (test vs. production) bepaalt;
# zie src/main.tsx. De SentryTestButton zelf is hier los van: die is
# uitsluitend zichtbaar bij `pnpm dev`, in geen enkele build (zie
# src/components/shared/SentryTestButton.tsx).
# Dit is de testomgeving-build, dus altijd gelijk aan DEPLOY_ENVIRONMENT
# ('test'). Zie de build-production job hieronder voor de aparte
# productie-build met VITE_APP_ENV=production.
VITE_APP_ENV: ${{ env.DEPLOY_ENVIRONMENT }}
run: pnpm run build
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_PATH }}
retention-days: 1
# Aparte build voor productie, alleen nodig/gedraaid als deploy_production
# is aangevinkt bij een handmatige workflow_dispatch-run. Dit bestaat naast
# de gewone `build`-job (in plaats van die job te hergebruiken) omdat
# VITE_APP_ENV een build-time Vite-variabele is: één en dezelfde dist/-bundel
# kan niet zowel als 'test' als 'production' getagd zijn. Zonder deze aparte
# build zou de test-bundel (met environment: test) naar productie
# gedeployed worden, wat Sentry-events/analytics verkeerd zou taggen.
build-production:
needs: prepare
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- 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('pnpm-lock.yaml') }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
env:
# Umami-website-ID's zijn NIET gedeeld tussen omgevingen: elke Umami
# "website"-entry (test.slpsoftware.nl vs slpsoftware.nl) heeft een
# eigen ID, anders komt productieverkeer in de teststatistieken
# terecht (of andersom). Vereist dus een eigen Umami-website +
# Gitea-variable VITE_UMAMI_WEBSITE_ID_PRODUCTION — zie umami-setup.md.
VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }}
VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_PRODUCTION }}
# VITE_SENTRY_DSN wordt wél gedeeld met de testbuild: één Sentry-
# project voor beide omgevingen, VITE_APP_ENV hieronder tagt de
# events al als 'test' vs 'production'. Splits dit pas op als je
# ooit aparte Sentry-projecten per omgeving wilt.
VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }}
VITE_APP_ENV: ${{ env.DEPLOY_ENVIRONMENT_PRODUCTION }}
run: pnpm run build
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME_PRODUCTION }}
path: ${{ env.ARTIFACT_PATH }}
retention-days: 1
test:
needs: build
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:
version: ${{ env.PNPM_VERSION }}
- 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('pnpm-lock.yaml') }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm run lint
- name: Unit tests
run: pnpm run test
deploy-test:
needs: [build, test, config]
# De push-naar-master-conditie hieronder is bewust ONAFHANKELIJK van het
# 'deploy_test'-vinkje: de automatische testdeploy bij een merge naar
# master moet altijd blijven gebeuren. Het vinkje geldt alleen voor
# handmatige workflow_dispatch-runs. Een PR triggert hier bewust GEEN
# deploy: wil je een feature-branch naar test deployen, start dan zelf
# een workflow_dispatch-run op die branch met 'Deploy to Test' aangevinkt
# (Gitea: Actions → Continuous Integration → Run workflow → branch
# selecteren) - dat vereist geen (afgeronde) PR.
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')
uses: ./.gitea/workflows/deploy.yaml
secrets: inherit
# Deze waarden komen uit het `env:`-blok bovenaan dit bestand, via de
# `config`-job (die ze doorgeeft als job-outputs). Pas de waarden dus aan
# in het `env:`-blok, niet hier.
with:
artifact_name: ${{ needs.config.outputs.artifact_name }}
environment: ${{ needs.config.outputs.deploy_environment }}
deploy_path: ${{ needs.config.outputs.deploy_path }}
# Productie-deploy is bewust NIET automatisch bij elke push naar master
# (in tegenstelling tot deploy-test hierboven): dit is pas een expliciete,
# bewuste actie via workflow_dispatch met het "deploy_production"-vinkje
# aangevinkt. Zo blijft de bestaande testdeploy-flow ongewijzigd en kan
# niemand per ongeluk productie deployen door simpelweg naar master te
# pushen of de workflow handmatig te starten zonder dat vinkje.
deploy-production:
needs: [build-production, test, config]
if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true'
uses: ./.gitea/workflows/deploy.yaml
secrets: inherit
with:
artifact_name: ${{ needs.config.outputs.artifact_name_production }}
environment: ${{ needs.config.outputs.deploy_environment_production }}
deploy_path: ${{ needs.config.outputs.deploy_path_production }}