InBruker context i Kalender #31
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 | |
jobs: | |
build_and_deploy: | |
name: Build, push and deploy | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "20.x" | |
registry-url: "https://npm.pkg.github.com" | |
- name: Cache Node.js modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm ci | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }} | |
- name: Set up Docker Buildx | |
if: github.ref == 'refs/heads/main' | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Docker Registry | |
if: github.ref == 'refs/heads/main' | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build app | |
run: npm run build | |
- name: Build and push docker image to GAR | |
if: github.ref == 'refs/heads/main' | |
uses: nais/docker-build-push@main | |
id: docker-push | |
with: | |
target: runtime | |
team: tpts | |
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} | |
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} | |
build_secrets: NODE_AUTH_TOKEN=${{ secrets.READER_TOKEN }} | |
context: . | |
tags: ${{ env.IMAGE }}-test | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Notify Slack in case of build failure | |
if: ${{ failure() && (github.ref == 'refs/heads/main') }} | |
run: | | |
curl -X POST --data-urlencode "payload={ \"attachments\": [{ \"pretext\": \"[${{ github.event.repository.name }}] Build failed :cry:\", \"color\": \"danger\", \"fields\": [ { \"title\": \"Author\", \"value\": \"$AUTHOR\", \"short\": false }, { \"title\": \"Commit\", \"value\": \"<https://github.com/${{ github.repository }}/commit/$GITHUB_SHA|$GITHUB_SHA>\", \"short\": false } ] }] }" $WEBHOOK_URL | |
env: | |
BRANCH: ${{ github.ref }} | |
AUTHOR: ${{ github.event.pusher.name }} | |
WEBHOOK_URL: ${{ secrets.SLACK_INCOMING_WEBHOOK_URL }} | |
- name: Deploy to nais | |
uses: nais/deploy/actions/deploy@v2 | |
env: | |
CLUSTER: dev-gcp | |
VAR: image=${{ steps.docker-push.outputs.image }} | |
RESOURCE: .nais/nais.yml |