Skip to content

Deploy spesifikk commit til dev #115

Deploy spesifikk commit til dev

Deploy spesifikk commit til dev #115

name: Deploy spesifikk commit til dev
on:
workflow_dispatch:
inputs:
commitHash:
description: 'SHA of the commit to deploy'
required: true
jobs:
lag_tag:
name: Lag en tag
permissions:
contents: write
id-token: write # For å kunne kjøre workflowen fra master-branchen
actions: write # For å kunne kjøre workflowen fra master-branchen
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.lage-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commitHash }}
- name: Lag tag for senere workflows
id: lage-tag
run: |
export TAG="denne_skal_deployes_til_dev-$(TZ=Europe/Oslo date +%Y-%m-%dT%H.%M.%S)"
git tag $TAG
git push origin $TAG
echo "TAG=$TAG" >> $GITHUB_OUTPUT
build:
needs: [ lag_tag ]
if: ${{ needs.lag_tag.outputs.tag != '' }}
permissions:
contents: read
id-token: write
uses: ./.github/workflows/build-image.yml
secrets: inherit
with:
ref: ${{ needs.lag_tag.outputs.tag }}
deployDev:
name: deploy to dev
needs: [ lag_tag, build ]
runs-on: ubuntu-latest
permissions:
id-token: write # for nais/login
steps:
- uses: nais/login@v0
id: login
with:
team: tbd
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
- uses: actions/checkout@v4
with:
ref: ${{ needs.lag_tag.outputs.tag }}
- uses: nais/deploy/actions/deploy@v2
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-gcp
RESOURCE: deploy/dev.yml
# Konstruere image-navn selv, for å unngå at imaget som er tagget med sha-en til HEAD på den branchen
# workflowen ble startet fra blir deployet. Det bugde imaget har to tags.
IMAGE: ${{ steps.login.outputs.registry }}/${{ github.event.repository.name }}:${{ needs.lag_tag.outputs.tag }}
fjern_tag:
name: Fjern deploy-tag
permissions:
contents: write
needs: [ lag_tag, deployDev ]
if: ${{ needs.lag_tag.outputs.tag != '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
git push --delete origin refs/tags/${{ needs.lag_tag.outputs.tag }}