-
Notifications
You must be signed in to change notification settings - Fork 2
215 lines (208 loc) · 8.58 KB
/
common.workflow.frontend.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
on:
workflow_call:
inputs:
cluster:
type: string
description: "The cluster to deploy to, e.g. dev-gcp."
required: false
default: "dev-gcp"
working-directory:
type: string
description: "The working directory for the job, e.g. apps/dolly-frontend (without leading/trailing slash)."
required: true
image-suffix:
type: string
description: "The Docker image suffix used for this particular workflow, e.g. dolly-frontend. Defaults to the workflow name."
required: false
default: ${{ github.workflow }}
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-frontend. 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-frontend."
required: false
deploy-tag-idporten:
type: string
description: "The commit message tag that will trigger a deployment to the 'idporten' environment on a commit to a non-master branch, e.g. #deploy-idporten-frontend."
required: false
deploy-tag-unstable:
type: string
description: "The commit message tag that will trigger a deployment to the 'unstable' environment on a commit to a non-master branch, e.g. #deploy-unstable-frontend."
required: false
force-deploy:
type: boolean
description: "Used to force deployment."
required: false
default: false
force-deploy-test:
type: boolean
description: "Used to force deployment to test. Make sure the working-directory contains a config.test.yml!"
required: false
default: false
force-deploy-idporten:
type: boolean
description: "Used to force deployment to idporten, only relevant for dolly-frontend. Make sure the working-directory contains a config.idporten.yml!"
required: false
default: false
force-deploy-unstable:
type: boolean
description: "Used to force deployment to unstable, only relevant for dolly-frontend. Make sure the working-directory contains a config.unstable.yml!"
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
READER_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: ${{ 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))) }}
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-idporten: ${{ inputs.force-deploy-idporten || (!contains(github.event.head_commit.message, '#nodeploy') && inputs.deploy-tag-idporten != '' && (github.ref == 'refs/heads/master' || contains(github.event.head_commit.message, inputs.deploy-tag-idporten))) }}
do-deploy-unstable: ${{ inputs.force-deploy-unstable || (!contains(github.event.head_commit.message, '#nodeploy') && (inputs.deploy-tag-unstable != '') && (github.ref == 'refs/heads/master' || contains(github.event.head_commit.message, inputs.deploy-tag-unstable))) }}
artifact: ${{ github.run_id }}-failure
build:
needs: start
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Setup (Node)"
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@navikt'
- name: "Install (Node)"
working-directory: ${{ inputs.working-directory }}/src/main/js
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }}
- name: "Build (Node)"
working-directory: ${{ inputs.working-directory }}/src/main/js
run: npm run build
- name: "Move (Node)"
working-directory: ${{ inputs.working-directory }}/src/main/js
run: mv build ../resources/static
- name: "Java"
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
env:
NAV_TOKEN: ${{ secrets.NAV_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- 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-unstable == 'true' ||
needs.start.outputs.do-deploy-idporten == 'true' ||
needs.start.outputs.do-deploy-test == 'true' ||
needs.start.outputs.do-deploy == '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 }}/config.yml"
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 }}
# Only used by dolly-frontend.
deploy-idporten:
needs: [ start, build ]
if: needs.start.outputs.do-deploy-idporten == 'true'
concurrency: ${{ inputs.image-suffix }}-idporten
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Deploy (idporten)"
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: ${{ inputs.cluster }}
RESOURCE: "${{ inputs.working-directory }}/config.idporten.yml"
VAR: image=${{ needs.build.outputs.image }}
# Only used by dolly-frontend.
deploy-unstable:
needs: [ start, build ]
if: needs.start.outputs.do-deploy-unstable == 'true'
concurrency: ${{ inputs.image-suffix }}-unstable
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Deploy (unstable)"
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: ${{ inputs.cluster }}
RESOURCE: "${{ inputs.working-directory }}/config.unstable.yml"
VAR: image=${{ needs.build.outputs.image }}