-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (201 loc) Β· 9.27 KB
/
test-deploy-to-staging.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
216
217
218
219
220
221
222
223
######################################################################
# Build, test & deploy the Azure Function app on pushes to master.
######################################################################
name: Staging build, test & deploy app
on:
workflow_dispatch:
push:
branches:
- master
- development
paths-ignore:
- '**/**.md'
env:
NODE_VERSION: '14.x'
# all Azure Functions are at the root of the project
AZURE_FUNCTION_APP_PACKAGE_PATH: ''
# function app settings
# AZURE_FUNCTIONAPP_SUBSCRIPTIONID: <secret>
# AZURE_FUNCTIONAPP_RESOURCEGROUP: <secret>
# AZURE_FUNCTIONAPP_NAME: <secret>
AZURE_FUNCTION_APP_DEPLOYMENT_SLOT: staging
# credentials for bot with contributor rights on resource group
# PLAYGROUND_BOT_AZURE_TENANTID: <secret>
# PLAYGROUND_BOT_AZURE_CLIENTID: <secret>
# PLAYGROUND_BOT_AZURE_CLIENTSECRET: <secret>
jobs:
test:
if: "!contains(github.event.head_commit.message,'[skip-ci]')"
name: Run all tests
runs-on: ubuntu-latest
steps:
######################################################################
# checkout full codebase
######################################################################
- name: Checkout repo codebase
uses: actions/checkout@master
with:
fetch-depth: 1
clean: true
submodules: false
######################################################################
# configure Node.js
######################################################################
- name: π§ Setup Node ${{ env.NODE_VERSION }} environment
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
######################################################################
# restore cached dependencies
######################################################################
- name: β»οΈ Restore cached dependencies
uses: actions/cache@v2
id: node_module_cache
with:
path: node_modules
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-node_modules-${{ hashFiles('package-lock.json') }}
######################################################################
# install dependencies (if restore cached deps failed)
######################################################################
- name: β¬οΈ Install dependencies
if: steps.node_module_cache.outputs.cache-hit != 'true'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}'
npm install
popd
######################################################################
# build project
######################################################################
- name: π Build project
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}'
npm run build --if-present
popd
######################################################################
# run tests
######################################################################
- name: π§ͺ Run all tests
run: |
pushd './${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}'
npm run prep --if-present
npm test --verbose
popd
######################################################################
# save test output
######################################################################
- name: π Save code coverage results (report)
uses: actions/upload-artifact@v1
with:
name: COVERAGE_REPORT
path: temp/lcov-report
deploy:
if: "!contains(github.event.head_commit.message,'[skip-cd]')"
name: Deploy to Azure Function app staging slot
runs-on: ubuntu-latest
needs: test
steps:
######################################################################
# checkout full codebase
######################################################################
- name: Checkout repo codebase
uses: actions/checkout@master
with:
fetch-depth: 1
clean: true
submodules: false
######################################################################
# configure Node.js
######################################################################
- name: π§ Setup Node ${{ env.NODE_VERSION }} environment
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
######################################################################
# restore cached dependencies
######################################################################
- name: β»οΈ Restore cached dependencies
uses: actions/cache@v2
id: node_module_cache
with:
path: node_modules
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-node_modules-${{ hashFiles('package-lock.json') }}
######################################################################
# install dependencies (if restore cached deps failed)
######################################################################
- name: β¬οΈ Install dependencies
if: steps.node_module_cache.outputs.cache-hit != 'true'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}'
npm install
popd
env:
APP_PACAKGE_PATH: ${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}
######################################################################
# build project
######################################################################
- name: π Build project
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}'
npm run build --if-present
popd
env:
APP_PACAKGE_PATH: ${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}
######################################################################
# purge all non-production dependencies
######################################################################
- name: π Purge non-production dependencies
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}'
npm prune --production
popd
env:
APP_PACAKGE_PATH: ${{ env.AZURE_FUNCTION_APP_PACKAGE_PATH }}
######################################################################
# login to Azure CLI via service principal
######################################################################
- name: π Login to Azure
run: az login --service-principal --tenant $BOT_TENANT_ID --username $BOT_CLIENT_ID --password $BOT_CLIENT_SECRET
env:
BOT_TENANT_ID: ${{ secrets.PLAYGROUND_BOT_AZURE_TENANTID }}
BOT_CLIENT_ID: ${{ secrets.PLAYGROUND_BOT_AZURE_CLIENTID }}
BOT_CLIENT_SECRET: ${{ secrets.PLAYGROUND_BOT_AZURE_CLIENTSECRET }}
######################################################################
# acquire publish profile for Azure Functions App
######################################################################
- name: β¬οΈ Download Azure Function app publishing profile
id: az_funcapp_publishing_profile
run: |
CMD_PUB_PROFILE=$(az functionapp deployment list-publishing-profiles --subscription $AZURE_SUBSCRIPTION_ID --resource-group $FUNCTION_APP_RESOURCE_GROUP --name $FUNCTION_APP_NAME --slot $FUNCTION_APP_DEPLOYMENT_SLOT --xml)
echo "::set-output name=slot_pub_profile::${CMD_PUB_PROFILE}"
env:
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_FUNCTIONAPP_SUBSCRIPTIONID }}
FUNCTION_APP_RESOURCE_GROUP: ${{ secrets.AZURE_FUNCTIONAPP_RESOURCEGROUP }}
FUNCTION_APP_NAME: ${{ secrets.AZURE_FUNCTIONAPP_NAME }}
FUNCTION_APP_DEPLOYMENT_SLOT: ${{ env.AZURE_FUNCTION_APP_DEPLOYMENT_SLOT }}
######################################################################
# deploy function app
######################################################################
- name: π Deploy Azure Functions app
uses: Azure/functions-action@v1
with:
app-name: ${{ secrets.AZURE_FUNCTIONAPP_NAME }}
package: '.'
publish-profile: ${{ steps.az_funcapp_publishing_profile.outputs.slot_pub_profile }}
respect-funcignore: true
######################################################################
# update azure function app setting to commit hash
######################################################################
- name: π Set Azure Function app's app setting "APP_VERSION" & "COMMIT_HASH"
run: |
az functionapp config appsettings set --resource-group $FUNCTION_APP_RESOURCE_GROUP --name $FUNCTION_APP_NAME --slot $FUNCTION_APP_DEPLOYMENT_SLOT --slot-settings "APP_VERSION=$SLOT_SETTING__APP_VERSION" "COMMIT_HASH=$SLOT_SETTING__COMMIT_HASH"
env:
FUNCTION_APP_RESOURCE_GROUP: ${{ secrets.AZURE_FUNCTIONAPP_RESOURCEGROUP }}
FUNCTION_APP_NAME: ${{ secrets.AZURE_FUNCTIONAPP_NAME }}
FUNCTION_APP_DEPLOYMENT_SLOT: ${{ env.AZURE_FUNCTION_APP_DEPLOYMENT_SLOT }}
SLOT_SETTING__APP_VERSION: staging
SLOT_SETTING__COMMIT_HASH: ${{ github.sha }}