-
Notifications
You must be signed in to change notification settings - Fork 2
146 lines (141 loc) · 5.42 KB
/
common.workflow.backend.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
on:
workflow_call:
inputs:
cluster:
type: string
description: "The cluster to deploy to, e.g. dev-fss."
required: false
default: "dev-gcp"
working-directory:
type: string
description: "The working directory for the job, e.g. apps/dolly-backend (without leading/trailing slash)."
required: true
image-suffix:
type: string
description: "The Docker image suffix used for this particular workflow, e.g. dolly-backend. Defaults to the workflow name."
required: false
default: ${{ github.workflow }}
nais-manifest:
type: string
description: "The NAIS manifest file. Make sure it exists in the working-directory. Defaults to config.yml."
required: false
default: "config.yml"
deploy-tag:
type: string
description: "The commit message tag that will trigger a deployment on a commit to a non-master branch, e.g. #deploy-dolly-backend. Make sure it is not a substring of other deploy tags."
required: true
deploy-tag-test:
type: string
description: "The commit message tag that will trigger a deployment to the test environment on a commit to a non-master branch, e.g. #deploy-test-dolly-backend."
required: false
force-deploy-test:
type: boolean
description: "Used to force deployment to test. Will override any #nodeploy tag. Make sure the working-directory contains a config.test.yml!"
required: false
default: false
force-deploy:
type: boolean
description: "Used to force deployment. Will override any #nodeploy tag."
required: false
default: false
sonar-enabled:
type: boolean
description: "Whether to run SonarQube analysis or not."
required: false
default: true
secrets:
NAIS_WORKLOAD_IDENTITY_PROVIDER:
required: true
NAV_TOKEN:
required: true
SONAR_TOKEN:
required: true
jobs:
start:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: "Logging"
run: |
echo "branch: ${{ github.ref }}"
echo "inputs: ${{ toJSON(inputs) }}"
echo "env: ${{ toJSON(env) }}"
echo "commit: ${{ github.event.head.commit_message }}"
outputs:
do-deploy-test: ${{ inputs.force-deploy-test || (!contains(github.event.head_commit.message, '#nodeploy') && (inputs.deploy-tag-test != '') && (github.ref == 'refs/heads/master' || contains(github.event.head_commit.message, inputs.deploy-tag-test))) }}
do-deploy: ${{ inputs.force-deploy || (!contains(github.event.head_commit.message, '#nodeploy') && (inputs.deploy-tag != '') && (github.ref == 'refs/heads/master' || contains(github.event.head_commit.message, inputs.deploy-tag))) }}
artifact: ${{ github.run_id }}-failure
build:
needs: start
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Setup"
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: "Gradle"
id: gradle
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
- name: "Build"
working-directory: ${{ inputs.working-directory }}
run: ./gradlew build ${{ inputs.sonar-enabled && 'jacocoTestReport sonar -Dsonar.gradle.skipCompile=true' || ''}} --scan
env:
NAV_TOKEN: ${{ secrets.NAV_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: "Reporting"
if: failure() && steps.gradle.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: ${{ needs.start.outputs.artifact}}
path: ${{ inputs.working-directory }}/build/reports
retention-days: 7
- name: "Docker"
id: docker-build-push
if: |
needs.start.outputs.do-deploy == 'true' ||
needs.start.outputs.do-deploy-test == 'true'
uses: nais/docker-build-push@v0
with:
team: dolly
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
docker_context: ${{ inputs.working-directory }}
image_suffix: ${{ inputs.image-suffix }}
outputs:
image: ${{ steps.docker-build-push.outputs.image }}
deploy:
needs: [ start, build ]
if: needs.start.outputs.do-deploy == 'true'
concurrency: ${{ inputs.image-suffix }}
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Deploy"
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: ${{ inputs.cluster }}
RESOURCE: "${{ inputs.working-directory }}/${{ inputs.nais-manifest }}"
VAR: image=${{ needs.build.outputs.image }}
deploy-test:
needs: [ start, build ]
if: needs.start.outputs.do-deploy-test == 'true'
concurrency: ${{ inputs.image-suffix }}-test
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Deploy (test)"
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: ${{ inputs.cluster }}
RESOURCE: "${{ inputs.working-directory }}/config.test.yml"
VAR: image=${{ needs.build.outputs.image }}