-
Notifications
You must be signed in to change notification settings - Fork 5
249 lines (207 loc) · 7.24 KB
/
pr-build.yaml
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: Build All - PR
on:
workflow_dispatch:
push:
# paths:
# - "workspace/**"
# - "backend/services.plr-intake/**"
# - "backend/services.plr-intake.tests/**"
# - "backend/webapi/**"
# - "backend/webapi.tests/**"
branches-ignore:
- 'develop'
- 'test'
- 'main'
pull_request:
types: [opened]
branches-ignore:
- 'test'
- 'master'
permissions: read-all
# This will terminate builds that are previously, but continuing to run. Saves GHA hours.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
get-pr-number:
runs-on: ubuntu-latest
defaults:
run:
working-directory: "./workspace"
outputs:
pr_number: ${{ steps.find-pr.outputs.pr }}
steps:
- name: "Checkout Code"
uses: actions/checkout@master
- name: find-pr
id: find-pr
uses: jwalton/gh-find-current-pr@v1
with:
state: open
- name: job1
id: job1
run: echo "Your PR is ${PR}"
if: success() && steps.find-pr.outputs.number
env:
PR: ${{ steps.find-pr.outputs.pr }}
Yarn-Lint:
name: Frontend Yarn Lint
runs-on: ubuntu-latest
needs: get-pr-number
if: ${{ always() && !cancelled() && needs.get-pr-number.outputs.pr_number != '' }}
defaults:
run:
working-directory: "./workspace"
steps:
- name: "Checkout Code"
uses: actions/checkout@master
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: YARN Install
run: yarn install
- name: YARN Lint
run: yarn lint:all
build-and-push-frontend:
name: Frontend Build & Push
runs-on: ubuntu-latest
needs: get-pr-number
if: ${{ always() && !cancelled() && needs.get-pr-number.outputs.pr_number != '' }}
defaults:
run:
working-directory: "./workspace"
permissions:
contents: read
id-token: write
steps:
- name: "Checkout Code"
uses: actions/checkout@master
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: YARN Install
run: yarn install
- name: YARN Build
run: yarn build
- name: YARN Test
run: |
yarn test:ci
- name: "Docker Build"
run: |
docker build -t image-registry.apps.silver.devops.gov.bc.ca/d8a8f9-tools/pidp-frontend:pr-${{ needs.get-pr-number.outputs.pr_number }} .
# Uses the builder service account token
- name: "Docker Login to Silver OCP"
uses: docker/login-action@v2
with:
registry: image-registry.apps.silver.devops.gov.bc.ca
username: builder
password: ${{ secrets.SILVER_TOOLS_BUILDER_TOKEN }}
- name: "Push image"
run: |
docker push image-registry.apps.silver.devops.gov.bc.ca/d8a8f9-tools/pidp-frontend:pr-${{ needs.get-pr-number.outputs.pr_number }}
unit-test-backend:
needs: get-pr-number
if: ${{ always() && !cancelled() && needs.get-pr-number.outputs.pr_number != '' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: "./backend"
permissions:
contents: read
id-token: write
steps:
- name: "Checkout Code"
uses: actions/checkout@master
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Build backend
run: dotnet build --configuration Release
- name: Run Tests
run: dotnet test --configuration Release
build-and-push-plr-intake:
name: PLR Intake Backend Build & Push
needs: [get-pr-number, unit-test-backend]
if: ${{ !(contains(needs.*.result, 'failure')) && needs.get-pr-number.outputs.pr_number != '' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: "./backend/services.plr-intake"
permissions:
contents: read
id-token: write
steps:
- name: "Checkout Code"
uses: actions/checkout@master
- name: "Docker Build"
run: |
docker build -t image-registry.apps.silver.devops.gov.bc.ca/d8a8f9-tools/pidp-plr-intake:pr-${{ needs.get-pr-number.outputs.pr_number }} .
# Uses the builder service account token
- name: "Docker Login to Silver OCP"
uses: docker/login-action@v2
with:
registry: image-registry.apps.silver.devops.gov.bc.ca
username: builder
password: ${{ secrets.SILVER_TOOLS_BUILDER_TOKEN }}
- name: "Push image"
run: |
docker push image-registry.apps.silver.devops.gov.bc.ca/d8a8f9-tools/pidp-plr-intake:pr-${{ needs.get-pr-number.outputs.pr_number }}
build-and-push-webapi:
name: WebAPI Backend Build & Push
needs: [get-pr-number, unit-test-backend]
if: ${{ !(contains(needs.*.result, 'failure')) && needs.get-pr-number.outputs.pr_number != '' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: "./backend/webapi"
permissions:
contents: read
id-token: write
steps:
- name: "Checkout Code"
uses: actions/checkout@master
- name: "Docker Build"
run: |
docker build -t image-registry.apps.silver.devops.gov.bc.ca/d8a8f9-tools/pidp-webapi:pr-${{ needs.get-pr-number.outputs.pr_number }} .
# Uses the builder service account token
- name: "Docker Login to Silver OCP"
uses: docker/login-action@v2
with:
registry: image-registry.apps.silver.devops.gov.bc.ca
username: builder
password: ${{ secrets.SILVER_TOOLS_BUILDER_TOKEN }}
- name: "Push image"
run: |
docker push image-registry.apps.silver.devops.gov.bc.ca/d8a8f9-tools/pidp-webapi:pr-${{ needs.get-pr-number.outputs.pr_number }}
helm-deployment:
needs: [build-and-push-webapi, build-and-push-plr-intake, build-and-push-frontend]
runs-on: 'ubuntu-latest'
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@master
- name: Authenticate and set context
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{secrets.OPENSHIFT_CLUSTER_URL}}
openshift_token: ${{secrets.OPENSHIFT_PIPELINE_SERVICE_ACCOUNT_TOKEN}}
- name: Get pr number from GH cli command (pushing to pr)
if: ${{ github.event.number == ''}}
run: echo "pr_number=$(gh pr view --json number -q .number || echo "")" >> "$GITHUB_ENV"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get pr number from github.event.number (opening a pr)
if: ${{ github.event.number != ''}}
run: echo "pr_number=${{ github.event.number }}" >> "$GITHUB_ENV"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Helm Deploy / install command
run: |
echo current installed helm releases
helm list --namespace d8a8f9-dev
echo installing helm chart...
helm upgrade --install --wait --values ./deploy/pr_values.yaml --namespace d8a8f9-dev pr-${{ env.pr_number }} charts/pidp --debug --set global.image.tag=pr-${{ env.pr_number }}