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] # 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 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: # 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] # TIJDELIJK: 'pull_request' is toegevoegd zodat elke PR ook automatisch # naar de testomgeving deployed, om testen tijdens deze werkbranch te # vereenvoudigen. Verwijder de 'pull_request'-conditie hieronder weer # zodra dat niet meer nodig is. # # De push-naar-master- en pull_request-condities hieronder zijn 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. if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_test == 'true') || github.event_name == 'pull_request' || (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 }}