name: Continuous Integration on: workflow_dispatch: {} 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_PATH: dist/ DEPLOY_ENVIRONMENT: test DEPLOY_PATH: /html/test/slpsoftware 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 }} deploy_environment: ${{ steps.set.outputs.deploy_environment }} deploy_path: ${{ steps.set.outputs.deploy_path }} steps: - id: set run: | echo "artifact_name=${{ env.ARTIFACT_NAME }}" >> "$GITHUB_OUTPUT" echo "deploy_environment=${{ env.DEPLOY_ENVIRONMENT }}" >> "$GITHUB_OUTPUT" echo "deploy_path=${{ env.DEPLOY_PATH }}" >> "$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 run: pnpm run build env: # 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 }} - name: Upload build artifact uses: actions/upload-artifact@v3 with: name: ${{ env.ARTIFACT_NAME }} 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 }}