-
Notifications
You must be signed in to change notification settings - Fork 97
316 lines (287 loc) · 11 KB
/
Copy pathtests.yml
File metadata and controls
316 lines (287 loc) · 11 KB
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
316
name: Tests
on:
push:
branches: [master]
pull_request:
branches: [master]
permissions:
id-token: write
contents: read
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
FUNCTION_PREFIX: lambda-cpp-integ
jobs:
unit-test:
runs-on: ${{ matrix.runner }}
timeout-minutes: 10
container: ${{ matrix.container }}
strategy:
fail-fast: false
matrix:
include:
- os: al2023
container: public.ecr.aws/amazonlinux/amazonlinux:2023
runner: ubuntu-latest
- os: al2023-arm
container: public.ecr.aws/amazonlinux/amazonlinux:2023
runner: ubuntu-24.04-arm
- os: ubuntu
container: public.ecr.aws/ubuntu/ubuntu:24.04
runner: ubuntu-latest
- os: alpine
container: public.ecr.aws/docker/library/alpine:3.23
runner: ubuntu-latest
- os: arch
container: public.ecr.aws/docker/library/archlinux:latest
runner: ubuntu-latest
steps:
- name: Install checkout prerequisites
shell: sh
run: |
if command -v dnf > /dev/null 2>&1; then
dnf install -y tar gzip git
elif command -v apk > /dev/null 2>&1; then
apk add --no-cache bash tar git
fi
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Install dependencies
shell: bash
run: ./ci/integ/install-deps.sh ${{ matrix.os }}
- name: Build and run unit tests
shell: bash
run: ./ci/integ/unit-test.sh ${{ matrix.os }}
integration-test-oci:
runs-on: ${{ matrix.build.runner }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
build:
- os: al2023
dockerfile: al2023
runner: ubuntu-latest
lambda_arch: x86_64
- os: al2023-arm
dockerfile: al2023
runner: ubuntu-24.04-arm
lambda_arch: arm64
- os: ubuntu
dockerfile: ubuntu
runner: ubuntu-latest
lambda_arch: x86_64
- os: alpine
dockerfile: alpine
runner: ubuntu-latest
lambda_arch: x86_64
- os: arch
dockerfile: arch
runner: ubuntu-latest
lambda_arch: x86_64
test:
- name: echo_success
handler: echo_success
payload: '{"barbaz":"Hello, Lambda!"}'
assertion: snapshot
- name: echo_unicode
handler: echo_success
payload: '{"UnicodeText":"画像は1000語の価値がある"}'
assertion: snapshot
- name: echo_failure
handler: echo_failure
payload: ""
assertion: snapshot
- name: binary_response
handler: binary_response
payload: ""
assertion: length
- name: crash_backtrace
handler: crash_backtrace
payload: ""
assertion: contains
exclude:
- build:
os: alpine
test:
name: crash_backtrace
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@254c19bd240aabef8777f48595e9d2d7b972184b # v6.2.1
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@d539f0932e70871a027e9d5a9d8fc38589180a64 # v2.1.6
- name: Ensure ECR repository exists
env:
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
run: |
aws ecr describe-repositories --repository-names "$ECR_REPOSITORY" 2>/dev/null || \
aws ecr create-repository --repository-name "$ECR_REPOSITORY"
aws ecr set-repository-policy --repository-name "$ECR_REPOSITORY" --policy-text '{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "LambdaECRImageRetrievalPolicy",
"Effect": "Allow",
"Principal": { "Service": "lambda.amazonaws.com" },
"Action": ["ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer"]
}
]
}'
- name: Build and push Docker image
env:
ECR_REGISTRY: ${{ steps.ecr-login.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
DOCKERFILE: ${{ matrix.build.dockerfile }}
run: |
docker build \
-f ci/integ/docker/Dockerfile.$DOCKERFILE \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
.
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image_uri=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> "$GITHUB_ENV"
- name: Deploy Lambda function
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-oci-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
uses: aws-actions/aws-lambda-deploy@d496277188b89f0be02d7a2216fc912c0427702a # v1.1.2
with:
function-name: ${{ env.FUNCTION_NAME }}
package-type: Image
image-uri: ${{ env.image_uri }}
architectures: ${{ matrix.build.lambda_arch }}
timeout: 30
role: ${{ secrets.LAMBDA_EXECUTION_ROLE_ARN }}
environment: '{"HANDLER":"${{ matrix.test.handler }}"}'
- name: Invoke and assert
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-oci-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
PAYLOAD: ${{ matrix.test.payload }}
run: ./ci/integ/invoke-and-assert.sh "$FUNCTION_NAME" "$PAYLOAD" "${{ matrix.test.assertion }}" "${{ matrix.test.name }}"
- name: Cleanup Lambda function
if: always()
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-oci-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
run: aws lambda delete-function --function-name "$FUNCTION_NAME" 2>/dev/null || true
- name: Cleanup ECR image
if: always()
env:
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
run: aws ecr batch-delete-image --repository-name "$ECR_REPOSITORY" --image-ids imageTag="$IMAGE_TAG" 2>/dev/null || true
integration-test-zip:
runs-on: ${{ matrix.build.runner }}
timeout-minutes: 10
container: ${{ matrix.build.container }}
strategy:
fail-fast: false
matrix:
build:
- os: al2023
container: public.ecr.aws/amazonlinux/amazonlinux:2023
runner: ubuntu-latest
lambda_arch: x86_64
- os: al2023-arm
container: public.ecr.aws/amazonlinux/amazonlinux:2023
runner: ubuntu-24.04-arm
lambda_arch: arm64
- os: ubuntu
container: public.ecr.aws/ubuntu/ubuntu:24.04
runner: ubuntu-latest
lambda_arch: x86_64
- os: arch
container: public.ecr.aws/docker/library/archlinux:latest
runner: ubuntu-latest
lambda_arch: x86_64
packaging:
- mode: default
id: default
- mode: no-glibc
id: noglibc
test:
- name: echo_success
handler: echo_success
payload: '{"barbaz":"Hello, Lambda!"}'
assertion: snapshot
- name: echo_unicode
handler: echo_success
payload: '{"UnicodeText":"画像は1000語の価値がある"}'
assertion: snapshot
- name: echo_failure
handler: echo_failure
payload: ""
assertion: snapshot
- name: binary_response
handler: binary_response
payload: ""
assertion: length
- name: crash_backtrace
handler: crash_backtrace
payload: ""
assertion: contains
exclude:
- packaging:
mode: no-glibc
build:
os: ubuntu
- packaging:
mode: no-glibc
build:
os: arch
steps:
- name: Install checkout prerequisites
shell: sh
run: |
if command -v dnf > /dev/null 2>&1; then
dnf install -y tar gzip git
elif command -v pacman > /dev/null 2>&1; then
pacman -Syu --noconfirm tar git
fi
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Install dependencies
shell: bash
run: ./ci/integ/install-deps.sh ${{ matrix.build.os }}
- name: Install AWS CLI
shell: bash
run: |
curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o /tmp/awscli.zip
unzip -q /tmp/awscli.zip -d /tmp
/tmp/aws/install
rm -rf /tmp/awscli.zip /tmp/aws
- name: Build and package zip
shell: bash
run: ./ci/integ/package-zip.sh ${{ matrix.build.os }} ${{ matrix.packaging.mode }}
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@254c19bd240aabef8777f48595e9d2d7b972184b # v6.2.1
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Deploy Lambda function
shell: bash
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-${{ matrix.packaging.id }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
run: |
aws lambda create-function \
--function-name "$FUNCTION_NAME" \
--runtime provided.al2023 \
--handler "${{ matrix.test.handler }}" \
--architectures ${{ matrix.build.lambda_arch }} \
--role "${{ secrets.LAMBDA_EXECUTION_ROLE_ARN }}" \
--timeout 30 \
--zip-file fileb://build/tests/resources/lambda-test-fun.zip \
--environment "Variables={HANDLER=${{ matrix.test.handler }}}"
timeout 60 aws lambda wait function-active-v2 --function-name "$FUNCTION_NAME"
- name: Invoke and assert
shell: bash
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-${{ matrix.packaging.id }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
PAYLOAD: ${{ matrix.test.payload }}
run: ./ci/integ/invoke-and-assert.sh "$FUNCTION_NAME" "$PAYLOAD" "${{ matrix.test.assertion }}" "${{ matrix.test.name }}"
- name: Cleanup Lambda function
if: always()
shell: bash
env:
FUNCTION_NAME: ${{ env.FUNCTION_PREFIX }}-${{ matrix.packaging.id }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
run: aws lambda delete-function --function-name "$FUNCTION_NAME" 2>/dev/null || true