-
Notifications
You must be signed in to change notification settings - Fork 3
315 lines (268 loc) · 10.3 KB
/
test-ci.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
name: LCFS 0.2.0 Test CI
on:
workflow_dispatch:
env:
VERSION: 0.2.0
GIT_URL: https://github.com/bcgov/lcfs.git
DEV_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev
TEST_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-test
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
install-oc:
runs-on: ubuntu-latest
outputs:
cache-hit: ${{ steps.cache.outputs.cache-hit }}
steps:
- name: Set up cache for OpenShift CLI
id: cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc # Path where the `oc` binary will be installed
key: oc-cli-${{ runner.os }}
- name: Install OpenShift CLI (if not cached)
if: steps.cache.outputs.cache-hit != 'true'
run: |
curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz
tar -xvf openshift-client-linux.tar.gz
sudo mv oc /usr/local/bin/
oc version --client
- name: Confirm OpenShift CLI is Available
run: oc version --client
run-tests:
name: Run Tests
runs-on: ubuntu-latest
needs: [install-oc]
steps:
- uses: actions/checkout@v3
with:
repository: bcgov/lcfs
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10.13"
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Cache Poetry dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Poetry
run: pip install poetry==1.6.1
- name: Install backend dependencies
run: |
cd backend
poetry config virtualenvs.create false
poetry install
pip install pytest-github-actions-annotate-failures typing_extensions
- name: Install frontend dependencies
run: |
cd frontend
npm ci
- name: Fix docker-compose.yml
run: |
sed -i 's/: true/: "true"/g; s/: false/: "false"/g' docker-compose.yml
- name: Build and start services
run: |
docker-compose build
docker-compose up -d
- name: Run backend tests
id: backend_tests
continue-on-error: true
run: |
cd backend
poetry run pytest --junitxml=pytest-results.xml
env:
LCFS_DB_HOST: localhost
LCFS_DB_PORT: 5432
LCFS_DB_USER: lcfs
LCFS_DB_PASS: development_only
LCFS_DB_BASE: lcfs
LCFS_REDIS_HOST: localhost
LCFS_REDIS_PORT: 6379
LCFS_REDIS_PASSWORD: development_only
APP_ENVIRONMENT: dev
LCFS_CHES_CLIENT_ID: mock_client_id
LCFS_CHES_CLIENT_SECRET: mock_client_secret
LCFS_CHES_AUTH_URL: http://mock_auth_url
LCFS_CHES_SENDER_EMAIL: [email protected]
LCFS_CHES_SENDER_NAME: Mock Notification System
LCFS_CHES_EMAIL_URL: http://mock_email_url
- name: Run frontend tests
id: frontend_tests
continue-on-error: true
run: |
cd frontend
npm run test:run -- --reporter=junit --outputFile=vitest-results.xml
env:
CI: true
# Comment until all cypress tests are fixed for success.
# - name: Create cypress.env.json
# run: |
# echo '{
# "admin_idir_username": "${{ secrets.ADMIN_IDIR_USERNAME }}",
# "admin_idir_password": "${{ secrets.ADMIN_IDIR_PASSWORD }}",
# "org1_bceid_username": "${{ secrets.ORG1_BCEID_USERNAME }}",
# "org1_bceid_password": "${{ secrets.ORG1_BCEID_PASSWORD }}",
# "org1_bceid_id": "${{ secrets.ORG1_BCEID_ID }}",
# "org1_bceid_userId": "${{ secrets.ORG1_BCEID_USERID }}",
# "org2_bceid_username": "${{ secrets.ORG2_BCEID_USERNAME }}",
# "org2_bceid_password": "${{ secrets.ORG2_BCEID_PASSWORD }}",
# "org2_bceid_id": "${{ secrets.ORG2_BCEID_ID }}",
# "org2_bceid_userId": "${{ secrets.ORG2_BCEID_USERID }}"
# }' > frontend/cypress.env.json
# - name: Run Cypress tests
# id: cypress_tests
# continue-on-error: true
# uses: cypress-io/github-action@v6
# with:
# command: npm run cypress:run
# wait-on: 'http://localhost:3000'
# working-directory: frontend
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
backend/pytest-results.xml
frontend/vitest-results.xml
# frontend/cypress/reports/
# frontend/cypress/screenshots/
- name: Stop services
if: always()
run: docker-compose down
- name: Check test results
if: always()
run: |
if [ "${{ steps.backend_tests.outcome }}" == "failure" ] || \
[ "${{ steps.frontend_tests.outcome }}" == "failure" ]; then
echo "One or more tests failed"
exit 1
fi
set-pre-release:
name: Find Dev deployment pre-release number
needs: run-tests
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.set-pre-release.outputs.PRE_RELEASE }}
steps:
- name: Restore oc command from Cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc
key: oc-cli-${{ runner.os }}
- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.DEV_NAMESPACE }}
- id: set-pre-release
run: |
check_string() {
local string="$1"
if [ ${#string} -ne 14 ]; then
echo "String length must be 14 characters"
return 1
fi
if ! [[ $string =~ ^[0-9]+$ ]]; then
echo "String can only contain numbers"
return 1
fi
local year="${string:0:4}"
local month="${string:4:2}"
local day="${string:6:2}"
local hour="${string:8:2}"
local minute="${string:10:2}"
local second="${string:12:2}"
if ! date -d "$year-$month-$day $hour:$minute:$second" &> /dev/null; then
echo "String format must be yyyymmddhhmmss"
return 1
fi
return 0
}
input_string=$(oc -n ${{ env.DEV_NAMESPACE }} describe deployment/lcfs-frontend-dev | grep Image | awk -F '-' '{print $NF}')
echo "The retrieved pre-release number on Dev is $input_string "
if check_string "$input_string"; then
echo "It is valid"
echo "PRE_RELEASE=$input_string" >> $GITHUB_OUTPUT
else
echo "It is not valid"
exit 1
fi
deploy-on-test:
name: Deploy LCFS on Test
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [set-pre-release]
env:
PRE_RELEASE: ${{ needs.set-pre-release.outputs.output1 }}
steps:
- id: get-current-time
run: |
echo "CURRENT_TIME=$(TZ='America/Vancouver' date '+%Y-%m-%d %H:%M:%S %Z')" >> $GITHUB_OUTPUT
- name: Ask for approval for LCFS release-${{ env.VERSION }} Test deployment
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,kuanfandevops,hamed-valiollahi,airinggov,areyeslo,dhaselhan,Grulin,kevin-hashimoto
minimum-approvals: 1
issue-title: "LCFS ${{ env.VERSION }}-${{ env.PRE_RELEASE }} Test Deployment at ${{ steps.get-current-time.outputs.CURRENT_TIME }}"
- name: Restore oc command from Cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc
key: oc-cli-${{ runner.os }}
- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.DEV_NAMESPACE }}
- name: Tag LCFS images to Test
run: |
oc tag ${{ env.DEV_NAMESPACE }}/lcfs-backend:${{ env.VERSION }}-$PRE_RELEASE ${{ env.TEST_NAMESPACE }}/lcfs-backend:${{ env.VERSION }}-$PRE_RELEASE
oc tag ${{ env.DEV_NAMESPACE }}/lcfs-frontend:${{ env.VERSION }}-$PRE_RELEASE ${{ env.TEST_NAMESPACE }}/lcfs-frontend:${{ env.VERSION }}-$PRE_RELEASE
- name: Checkout Manifest repository
uses: actions/checkout@v3
with:
repository: bcgov-c/tenant-gitops-d2bd59
ref: main
ssh-key: ${{ secrets.MANIFEST_REPO_DEPLOY_KEY }}
- name: Update frontend tag
uses: mikefarah/[email protected]
with:
cmd: yq -i '.image.tag = "${{ env.VERSION }}-${{ env.PRE_RELEASE }}"' lcfs/charts/lcfs-frontend/values-test.yaml
- name: Update backend tag
uses: mikefarah/[email protected]
with:
cmd: yq -i '.image.tag = "${{ env.VERSION }}-${{ env.PRE_RELEASE }}"' lcfs/charts/lcfs-backend/values-test.yaml
- name: GitHub Commit & Push
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add lcfs/charts/lcfs-frontend/values-test.yaml
git add lcfs/charts/lcfs-backend/values-test.yaml
git commit -m "Update the image tag to ${{ env.VERSION }}-${{ env.PRE_RELEASE }} on LCFS Test Environment"
git push