Files
SlpSoftware/.gitea/workflows/continuous_integration.yaml
T
SluijsensandClaude Sonnet 5 a208aebae0 Automatiseer productie-deploy als opt-in stap naast de bestaande testdeploy
Voegt build-production en deploy-production jobs toe aan
continuous_integration.yaml, alleen actief bij een handmatige
workflow_dispatch-run met het deploy_production-vinkje aangevinkt (nooit
automatisch bij een push naar master). Een aparte build-production job is
nodig omdat VITE_APP_ENV een build-time Vite-variabele is: dezelfde bundel
kan niet zowel als test als production getagd zijn in Sentry/analytics.
Uploadpad komt uit de nieuwe Gitea-variable DEPLOY_PATH_PRODUCTION, analoog
aan DEPLOY_PATH_TEST. Documentatie en production-readiness-checklist
bijgewerkt om dit open item als opgelost te markeren.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-27 12:05:19 +02:00

250 lines
9.4 KiB
YAML

name: Continuous Integration
on:
workflow_dispatch:
inputs:
deploy_production:
description: 'Na een succesvolle build/test ook naar productie deployen (naast de automatische testdeploy)?'
type: boolean
default: false
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [master]
# 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 }}
VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID }}
# 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 bepaalt of dev/test-only UI (zoals de tijdelijke
# SentryTestButton) zichtbaar is; zie src/components/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:
# Zelfde Umami/Sentry-variabelen als de testbuild hierboven, want er
# is (nog) geen apart productie-Umami-website-ID of -Sentry-project
# gekozen. Splits deze pas op zodra dat nodig blijkt.
VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }}
VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID }}
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]
if: github.event_name == 'workflow_dispatch' || (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 }}