-
-
Notifications
You must be signed in to change notification settings - Fork 4
284 lines (235 loc) · 8.6 KB
/
build.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
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
name: build
on:
push:
branches: [ main ]
paths-ignore:
- '**/*.md'
- '**/*.gitignore'
- '**/*.gitattributes'
pull_request:
branches:
- main
- dotnet-vnext
- dotnet-nightly
workflow_dispatch:
env:
ARTIFACT_NAME: 'lambda'
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ vars.AWS_REGION }}
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
DOTNET_MULTILEVEL_LOOKUP: 0
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1
LAMBDA_ARCHITECTURES: 'arm64'
LAMBDA_DESCRIPTION: 'Deploy build ${{ github.run_number }} to AWS Lambda via GitHub Actions'
LAMBDA_FUNCTION: 'alexa-london-travel'
LAMBDA_HANDLER: 'LondonTravel.Skill::MartinCostello.LondonTravel.Skill.AlexaFunctionHandler::HandleAsync'
LAMBDA_MEMORY: 256
LAMBDA_ROLE: ${{ vars.AWS_LAMBDA_ROLE }}
LAMBDA_RUNTIME: 'provided.al2'
LAMBDA_TIMEOUT: 10
NUGET_XMLDOC_MODE: skip
TERM: xterm
permissions:
contents: read
jobs:
build:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
include:
- os: macos-latest
os_name: macos
- os: ubuntu-latest
os_name: linux
- os: windows-latest
os_name: windows
steps:
- name: Checkout code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Setup .NET SDK
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
- name: Build, Test and Package
shell: pwsh
run: ./build.ps1
- name: Upload coverage to Codecov
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
with:
file: ./artifacts/coverage/coverage.cobertura.xml
flags: ${{ matrix.os_name }}
- name: Publish artifacts
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: artifacts-${{ matrix.os_name }}
path: ./artifacts
- name: Create Lambda ZIP file
if: runner.os == 'Linux'
run: |
cd "./artifacts/publish" || exit
if [ -f "./bootstrap" ]
then
chmod +x ./bootstrap
fi
zip -r "../${{ env.LAMBDA_FUNCTION }}.zip" . || exit 1
- name: Publish deployment package
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
if: runner.os == 'Linux' && success()
with:
name: ${{ env.ARTIFACT_NAME }}
path: ./artifacts/${{ env.LAMBDA_FUNCTION }}.zip
if-no-files-found: error
deploy-dev:
if: |
github.event.repository.fork == false &&
github.ref_name == github.event.repository.default_branch
name: dev
needs: build
concurrency: dev_environment
runs-on: ubuntu-latest
environment:
name: dev
permissions:
id-token: write
steps:
- name: Set function name
run: |
echo "FUNCTION_NAME=${{ env.LAMBDA_FUNCTION }}-dev" >> "$GITHUB_ENV"
- name: Download artifacts
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: ${{ env.ARTIFACT_NAME }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-deploy
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}-deploy-dev
aws-region: ${{ env.AWS_REGION }}
- name: Update function code
run: |
aws lambda update-function-code \
--function-name "${FUNCTION_NAME}" \
--architectures "${LAMBDA_ARCHITECTURES}" \
--zip-file fileb://./${{ env.LAMBDA_FUNCTION }}.zip \
> /dev/null
- name: Wait for function code update
run: |
aws lambda wait function-updated-v2 \
--function-name "${FUNCTION_NAME}" \
> /dev/null
- name: Update function configuration
run: |
aws lambda update-function-configuration \
--function-name "${FUNCTION_NAME}" \
--description "${LAMBDA_DESCRIPTION}" \
--handler ${{ env.LAMBDA_HANDLER }} \
--memory-size ${{ env.LAMBDA_MEMORY }} \
--role ${{ env.LAMBDA_ROLE }} \
--runtime ${{ env.LAMBDA_RUNTIME }} \
--timeout ${{ env.LAMBDA_TIMEOUT }} \
> /dev/null
- name: Wait for function configuration update
run: |
aws lambda wait function-updated-v2 \
--function-name "${FUNCTION_NAME}" \
> /dev/null
tests-dev:
name: tests-dev
needs: deploy-dev
runs-on: ubuntu-latest
concurrency: dev_environment
permissions:
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Setup .NET SDK
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-test
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}-tests-dev
aws-region: ${{ env.AWS_REGION }}
- name: Run end-to-end tests
shell: pwsh
run: dotnet test ./test/LondonTravel.Skill.EndToEndTests --configuration Release --logger "GitHubActions;report-warnings=false"
env:
LAMBDA_FUNCTION_NAME: ${{ env.LAMBDA_FUNCTION }}-dev
deploy-prod:
name: production
needs: tests-dev
runs-on: ubuntu-latest
concurrency: production_environment
environment:
name: production
permissions:
id-token: write
steps:
- name: Set function name
run: |
echo "FUNCTION_NAME=${{ env.LAMBDA_FUNCTION }}" >> "$GITHUB_ENV"
- name: Download artifacts
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: lambda
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-deploy
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}-deploy-production
aws-region: ${{ env.AWS_REGION }}
- name: Update function code
run: |
aws lambda update-function-code \
--function-name "${FUNCTION_NAME}" \
--architectures "${LAMBDA_ARCHITECTURES}" \
--zip-file fileb://./${{ env.LAMBDA_FUNCTION }}.zip \
> /dev/null
- name: Wait for function code update
run: |
aws lambda wait function-updated-v2 \
--function-name "${FUNCTION_NAME}" \
> /dev/null
- name: Update function configuration
run: |
aws lambda update-function-configuration \
--function-name "${FUNCTION_NAME}" \
--description "${LAMBDA_DESCRIPTION}" \
--handler ${{ env.LAMBDA_HANDLER }} \
--memory-size ${{ env.LAMBDA_MEMORY }} \
--role ${{ env.LAMBDA_ROLE }} \
--runtime ${{ env.LAMBDA_RUNTIME }} \
--timeout ${{ env.LAMBDA_TIMEOUT }} \
> /dev/null
- name: Wait for function configuration update
run: |
aws lambda wait function-updated-v2 \
--function-name "${FUNCTION_NAME}" \
> /dev/null
tests-prod:
needs: deploy-prod
runs-on: ubuntu-latest
concurrency: production_environment
permissions:
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Setup .NET SDK
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-test
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}-tests-production
aws-region: ${{ env.AWS_REGION }}
- name: Run end-to-end tests
shell: pwsh
run: dotnet test ./test/LondonTravel.Skill.EndToEndTests --configuration Release --logger "GitHubActions;report-warnings=false"
env:
LAMBDA_FUNCTION_NAME: ${{ env.LAMBDA_FUNCTION }}