This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
183 lines (152 loc) · 5.72 KB
/
test-and-release.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
name: Test and Release
on:
workflow_dispatch:
push:
paths-ignore:
- Dockerfile
- .github/workflows/test-docker.yaml
- .github/workflows/publish-docker.yaml
- .github/workflows/cd.yaml
permissions:
id-token: write
contents: write
issues: write
jobs:
tests:
runs-on: ubuntu-22.04
# Running CI in clean environment is currently not possible: https://github.com/NordicSemiconductor/asset-tracker-cloud-azure-js/issues/1
environment:
name: ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APP_NAME: ${{ secrets.APP_NAME }}
B2C_TENANT: ${{ secrets.B2C_TENANT }}
LOCATION: ${{ secrets.LOCATION }}
APP_REG_CLIENT_ID: ${{ secrets.APP_REG_CLIENT_ID }}
B2C_CLIENT_SECRET: ${{ secrets.B2C_CLIENT_SECRET }}
B2C_TENANT_ID: ${{ secrets.B2C_TENANT_ID }}
B2C_USER_FLOW_NAME: B2C_1_developer
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
MOCK_HTTP_API_STORAGE_ACCOUNT_NAME: mockhttpapi
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- name: Print azure CLI version
uses: azure/CLI@v2
with:
inlineScript: az --version
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: List Azure accounts
uses: azure/CLI@v2
with:
inlineScript: |
az account list --output table
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "npm"
- name: Install dependencies
run: npm ci --no-audit
- run: npx tsc
- name: Check source code with eslint
run: npx eslint ./
- name: Check if source code is properly formatted
run: npx prettier -c ./
- name: Run Unit Tests
run: npm test
- name: Deploy Mock HTTP API
uses: azure/CLI@v2
with:
inlineScript: |
az deployment group create \
--resource-group ${RESOURCE_GROUP:-nrfassettrackerci} \
--mode Incremental \
--name test-mock-http-api-${{ github.sha }} \
--template-file mock-http-api.json \
--parameters \
storageAccountName=${MOCK_HTTP_API_STORAGE_ACCOUNT_NAME:-mockhttpapi}
- name: Determine Mock API endpoint
uses: azure/CLI@v2
with:
inlineScript: |
echo "MOCK_HTTP_API_ENDPOINT=`az functionapp show -g ${RESOURCE_GROUP:-nrfassettrackerci} -n ${MOCK_HTTP_API_STORAGE_ACCOUNT_NAME:-mockhttpapi}Functions | jq -r '.defaultHostName'`" >> $GITHUB_ENV
- name: Pack mock functions
run: node scripts/pack-mock-http-api-app.js
- name: Deploy mock functions
uses: azure/CLI@v2
with:
inlineScript: |
az functionapp deployment source config-zip -g ${RESOURCE_GROUP:-nrfassettrackerci} -n ${MOCK_HTTP_API_STORAGE_ACCOUNT_NAME:-mockhttpapi}Functions --src dist/mock-http-api.zip
- name: Set random nRF Cloud Team ID
run: |
echo "NRF_CLOUD_TEAM_ID=`uuidgen`" >> $GITHUB_ENV
- name: Set Key Vault name
run: |
echo "keyVaultName=${APP_NAME:-nrfassettrackerci}" >> $GITHUB_ENV
- name: Create nRF Cloud Location Services service key
run: openssl ecparam -name prime256v1 -genkey > nrfcloudservice.key
- name: Set secrets for nRF Cloud API
uses: azure/CLI@v2
with:
inlineScript: |
az keyvault secret set --vault-name ${keyVaultName} --name nrfCloudServiceKey --file nrfcloudservice.key
- name: Deploy solution
uses: azure/CLI@v2
with:
inlineScript: |
az deployment group create \
--resource-group ${RESOURCE_GROUP:-nrfassettrackerci} \
--mode Incremental \
--name test-${{ github.sha }} \
--template-file azuredeploy.json \
--parameters \
appName=${APP_NAME:-nrfassettrackerci} \
appRegistrationClientId=${APP_REG_CLIENT_ID} \
b2cTenant=${B2C_TENANT} \
b2cFlowName=B2C_1_developer \
nrfCloudTeamId=${NRF_CLOUD_TEAM_ID} \
nrfCloudApiEndpoint=https://${MOCK_HTTP_API_ENDPOINT}/api/api.nrfcloud.com/ \
keyVaultName=${keyVaultName}
- name: Pack functions
run: node scripts/pack-app.js
- name: Deploy Function App
uses: azure/CLI@v2
with:
inlineScript: |
az functionapp deployment source config-zip -g ${RESOURCE_GROUP:-nrfassettrackerci} -n ${APP_NAME:-nrfassettrackerci}api --src dist/functionapp.zip
- uses: actions/upload-artifact@v4
if: always()
with:
if-no-files-found: error
name: functionapp-${{ github.sha }}
path: dist/functionapp.zip
- name: Cache certificates
uses: actions/cache@v4
id: certs-cache
with:
path: ./certificates
key: certificates
- name: Create Intermediate CA certificate
if: steps.certs-cache.outputs.cache-hit != 'true'
run: |
./cli.sh create-ca-root
./cli.sh create-ca-intermediate
- name: Run End-to-End Tests
uses: nick-invision/retry@v2
env:
FORCE_COLOR: 3
with:
timeout_minutes: 10
max_attempts: 3
command: npm run test:e2e
- name: Delete device certificates
run: rm ./certificates/*/device-*
- name: Semantic release
if: success()
continue-on-error: true
run: npx semantic-release