Mh/pek 610 (#1466) #1528
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy | |
on: | |
push: | |
branches: | |
- main | |
- sandbox | |
- catbox | |
- magicbox | |
- dreambox | |
paths-ignore: | |
- '.gitignore' | |
- 'CODEOWNERS' | |
- 'LICENSE.md' | |
- 'README.md' | |
workflow_dispatch: | |
inputs: | |
prod: | |
description: Deploy to production | |
type: boolean | |
required: false | |
jobs: | |
build: | |
name: Build application | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Use Node.js v22.11.0 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22.11.0' | |
registry-url: 'https://npm.pkg.github.com' | |
- name: Cache node modules | |
id: cache-node | |
uses: actions/cache@v4 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
- name: Install dependencies | |
if: steps.cache-node.outputs.cache-hit != 'true' | |
run: npm ci | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} | |
- name: Fetch openapi backend types | |
run: npx openapi-typescript ${{ github.event.inputs.prod == 'true' && 'https://www.nav.no/pensjon/kalkulator/v3/api-docs/current' || 'https://staging.ekstern.dev.nav.no/pensjon/kalkulator/v3/api-docs/current' }} -o ./src/types/schema.d.ts | |
- name: Format backend scheme | |
run: npm run format:types | |
- name: Rebuild node-sass | |
run: npm rebuild node-sass | |
- name: Build staging application | |
if: github.event.inputs.prod != 'true' | |
run: npm run build | |
- name: Build production application | |
if: github.event.inputs.prod == 'true' | |
run: npm run build:production | |
- name: Build backend for frontend | |
run: npm run build:server | |
- name: Save build folder | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: dist | |
if-no-files-found: error | |
retention-days: 1 | |
- name: Create Docker image | |
id: image-creation | |
uses: nais/docker-build-push@v0 | |
with: | |
dockerfile: .docker/Dockerfile | |
team: pensjonskalkulator | |
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} | |
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} | |
outputs: | |
image: ${{ steps.image-creation.outputs.image }} | |
run-unit-tests: | |
name: Run unit tests | |
runs-on: ubuntu-latest | |
needs: build | |
strategy: | |
fail-fast: true | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Use Node.js v22.11.0 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22.11.0' | |
registry-url: 'https://npm.pkg.github.com' | |
- name: Cache node modules | |
id: cache-node | |
uses: actions/cache@v4 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
- name: Install dependencies | |
if: steps.cache-node.outputs.cache-hit != 'true' | |
run: npm ci | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} | |
- name: Rebuild node-sass | |
run: npm rebuild node-sass | |
- name: Run unit tests | |
run: npm run test | |
- name: Archive code coverage results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage-report | |
path: coverage | |
run-integration-tests: | |
name: Run integration tests | |
runs-on: ubuntu-latest | |
needs: build | |
strategy: | |
fail-fast: true | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Use Node.js v22.11.0 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22.11.0' | |
registry-url: 'https://npm.pkg.github.com' | |
- name: Cache node modules | |
id: cache-node | |
uses: actions/cache@v4 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
- name: Cache Cypress binary | |
id: cache-cypress | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/Cypress | |
key: ${{ runner.os }}-cypress-${{ hashFiles('**/package.json') }} | |
- name: Download the build folders | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist | |
path: dist | |
- name: Install dependencies | |
if: steps.cache-node.outputs.cache-hit != 'true' | |
run: npm ci | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} | |
- name: Install cypress | |
if: steps.cache-cypress.outputs.cache-hit != 'true' | |
run: npx cypress install | |
- name: Rebuild node-sass | |
run: npm rebuild node-sass | |
- name: Run integration tests on staging application | |
if: github.event.inputs.prod != 'true' | |
run: npm run cy:test | |
- name: Run integration tests on production application | |
if: github.event.inputs.prod == 'true' | |
run: npm run cy:test:production | |
- name: Archive Cypress artifacts | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: screenshots | |
path: cypress/screenshots | |
deploy-staging: | |
name: Deploy to staging | |
needs: [build, run-unit-tests, run-integration-tests] | |
permissions: write-all | |
runs-on: ubuntu-latest | |
if: | | |
(github.event_name == 'push' || | |
github.event_name == 'workflow_dispatch') && | |
github.event.inputs.prod != 'true' && | |
github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Deploy to staging | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-staging.yml | |
- name: Deploy veiledning to staging | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-veiledning-staging.yml | |
deploy-sandbox: | |
name: Deploy to sandbox | |
needs: [build, run-unit-tests, run-integration-tests] | |
permissions: write-all | |
runs-on: ubuntu-latest | |
if: | | |
(github.event_name == 'push' || | |
github.event_name == 'workflow_dispatch') && | |
github.event.inputs.prod != 'true' && | |
github.ref == 'refs/heads/sandbox' | |
env: | |
IMAGE: ghcr.io/${{ github.repository }}/pensjonskalkulator-frontend-node:${{ github.sha }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Deploy to sandbox | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-sandbox.yml | |
- name: Deploy veiledning to sandbox | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-veiledning-sandbox.yml | |
deploy-catbox: | |
name: Deploy to catbox | |
needs: [build, run-unit-tests, run-integration-tests] | |
permissions: write-all | |
runs-on: ubuntu-latest | |
if: | | |
(github.event_name == 'push' || | |
github.event_name == 'workflow_dispatch') && | |
github.event.inputs.prod != 'true' && | |
github.ref == 'refs/heads/catbox' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Deploy to catbox | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-catbox.yml | |
- name: Deploy veiledning to catbox | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-veiledning-catbox.yml | |
deploy-magicbox: | |
name: Deploy to magicbox | |
needs: [build, run-unit-tests, run-integration-tests] | |
permissions: write-all | |
runs-on: ubuntu-latest | |
if: | | |
(github.event_name == 'push' || | |
github.event_name == 'workflow_dispatch') && | |
github.event.inputs.prod != 'true' && | |
github.ref == 'refs/heads/magicbox' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Deploy to magicbox | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-magicbox.yml | |
- name: Deploy veiledning to magicbox | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-veiledning-magicbox.yml | |
deploy-dreambox: | |
name: Deploy to dreambox | |
needs: [build, run-unit-tests, run-integration-tests] | |
permissions: write-all | |
runs-on: ubuntu-latest | |
if: | | |
(github.event_name == 'push' || | |
github.event_name == 'workflow_dispatch') && | |
github.event.inputs.prod != 'true' && | |
github.ref == 'refs/heads/dreambox' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Deploy to dreambox | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-dreambox.yml | |
- name: Deploy veiledning to dreambox | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-veiledning-dreambox.yml | |
deploy-prod: | |
name: Deploy to prod-gcp | |
needs: [build, run-unit-tests, run-integration-tests] | |
permissions: write-all | |
runs-on: ubuntu-latest | |
if: | | |
github.ref == 'refs/heads/main' && | |
github.event_name == 'workflow_dispatch' && | |
github.event.inputs.prod == 'true' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Deploy to prod-gcp | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: prod-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-prod.yml | |
- name: Deploy veiledning to prod-gcp | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: prod-gcp | |
IMAGE: ${{ needs.build.outputs.image }} | |
RESOURCE: .nais/deploy-veiledning-prod.yml |