Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
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 }}
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@v4

- 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:
runs-on: ${{ matrix.build.runner }}
strategy:
fail-fast: false
matrix:
build:
- os: al2023
runner: ubuntu-latest
lambda_arch: x86_64
- os: al2023-arm
dockerfile: al2023
runner: ubuntu-24.04-arm
lambda_arch: arm64
- os: ubuntu
runner: ubuntu-latest
lambda_arch: x86_64
- os: alpine
runner: ubuntu-latest
lambda_arch: x86_64
- os: 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:
# Alpine uses musl which doesn't provide backtrace()
- build:
os: alpine
test:
name: crash_backtrace

steps:
- uses: actions/checkout@v4

- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
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@v2

- 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 || matrix.build.os }}
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
uses: aws-actions/aws-lambda-deploy@v1.1.0
with:
function-name: ${{ env.FUNCTION_PREFIX }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}
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 Lambda function
env:
PAYLOAD: ${{ matrix.test.payload }}
run: ./ci/integ/invoke.sh "${{ env.FUNCTION_PREFIX }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}" "$PAYLOAD"

- name: Assert result
run: ./ci/integ/assert.sh ${{ matrix.test.assertion }} ${{ matrix.test.name }}

- name: Cleanup Lambda function
if: always()
run: aws lambda delete-function --function-name "${{ env.FUNCTION_PREFIX }}-${{ matrix.build.os }}-${{ matrix.test.name }}-${{ github.run_id }}" 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
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:
- uses: actions/checkout@v3

- name: Check Formatting
run: ./ci/codebuild/format-check.sh
run: ./ci/format-check.sh
14 changes: 0 additions & 14 deletions ci/README.md

This file was deleted.

Loading
Loading