Skip to content

[example] Group all examples under one project #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
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
29 changes: 2 additions & 27 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ on:
type: string
description: "The name of the workflow used for the concurrency group."
required: true
# We pass the list of examples here, but we can't pass an array as argument
# Instead, we pass a String with a valid JSON array.
# The workaround is mentioned here https://github.com/orgs/community/discussions/11692
examples:
type: string
description: "The list of examples to run. Pass a String with a valid JSON array such as \"[ 'HelloWorld', 'APIGateway' ]\""
required: true
default: ""
examples_enabled:
type: boolean
description: "Boolean to enable the compilation of examples. Defaults to true."
Expand All @@ -32,10 +24,6 @@ on:
type: boolean
description: "Boolean to enable the check for Foundation dependency. Defaults to true."
default: true
matrix_linux_command:
type: string
description: "The command of the current Swift version linux matrix job to execute."
required: true
matrix_linux_swift_container_image:
type: string
description: "Container image for the matrix job. Defaults to matching latest Swift 6.1 Amazon Linux 2 image."
Expand All @@ -48,19 +36,9 @@ concurrency:

jobs:
test-examples:
name: Test Examples/${{ matrix.examples }} on ${{ matrix.swift.swift_version }}
name: Test Examples
if: ${{ inputs.examples_enabled }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
examples: ${{ fromJson(inputs.examples) }}

# We are using only one Swift version
swift:
- image: ${{ inputs.matrix_linux_swift_container_image }}
container:
image: ${{ matrix.swift.image }}
steps:
# GitHub checkout action has a dep on NodeJS 20 which is not running on Amazonlinux2
# workaround is to manually checkout the repository
Expand Down Expand Up @@ -89,11 +67,8 @@ jobs:
# https://github.com/actions/checkout/issues/766
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}

- name: Run matrix job
- name: Run build for all examples
working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4
env:
COMMAND: ${{ inputs.matrix_linux_command }}
EXAMPLE: ${{ matrix.examples }}
run: |
.github/workflows/scripts/integration_tests.sh

Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ jobs:
with:
name: "Integration tests"
examples_enabled: true
matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=../.. swift build"
# We pass the list of examples here, but we can't pass an array as argument
# We pass the list of examples targets here, but we can't pass an array as argument
# Instead, we pass a String with a valid JSON array.
# The workaround is mentioned here https://github.com/orgs/community/discussions/11692
examples: "[ 'APIGateway', 'APIGateway+LambdaAuthorizer', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'ResourcesPackaging', 'S3EventNotifier', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Testing', 'Tutorial' ]"
archive_plugin_examples: "[ 'HelloWorld', 'ResourcesPackaging' ]"
archive_plugin_enabled: true

Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/scripts/check-archive-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,30 @@ fatal() { error "$@"; exit 1; }
test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset"

OUTPUT_DIR=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager
OUTPUT_FILE=${OUTPUT_DIR}/MyLambda/bootstrap
ZIP_FILE=${OUTPUT_DIR}/MyLambda/MyLambda.zip

pushd "Examples/${EXAMPLE}" || exit 1
pushd "Examples" || exit 1

# package the example (docker and swift toolchain are installed on the GH runner)
LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker || exit 1
LAMBDA_USE_LOCAL_DEPS=.. swift package archive --product "${EXAMPLE}" --allow-network-connections docker || exit 1

# find the zip file in the OUTPUT_FILE directory
ZIP_FILE=$(find "${OUTPUT_DIR}" -type f -name "*.zip" | head -n 1)
OUTPUT_FILE=$(find "${OUTPUT_DIR}" -type f -name "bootstrap" | head -n 1)

# did the plugin generated a Linux binary?
[ -f "${OUTPUT_FILE}" ]
file "${OUTPUT_FILE}" | grep --silent ELF
[ -f "${OUTPUT_FILE}" ] || exit 1
file "${OUTPUT_FILE}" | grep --silent ELF || exit 1

# did the plugin created a ZIP file?
[ -f "${ZIP_FILE}" ]
[ -f "${ZIP_FILE}" ] || exit 1

# does the ZIP file contain the bootstrap?
unzip -l "${ZIP_FILE}" | grep --silent bootstrap
unzip -l "${ZIP_FILE}" | grep --silent bootstrap || exit 1

# if EXAMPLE is ResourcesPackaging, check if the ZIP file contains hello.txt
if [ "$EXAMPLE" == "ResourcesPackaging" ]; then
echo "Checking if resource was added to the ZIP file"
unzip -l "${ZIP_FILE}" | grep --silent hello.txt
unzip -l "${ZIP_FILE}" | grep --silent hello.txt
SUCCESS=$?
if [ "$SUCCESS" -eq 1 ]; then
log "❌ Resource not found." && exit 1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/scripts/check-link-foundation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ fatal() { error "$@"; exit 1; }

EXAMPLE=APIGateway
OUTPUT_DIR=.build/release
OUTPUT_FILE=${OUTPUT_DIR}/APIGatewayLambda
OUTPUT_FILE=${OUTPUT_DIR}/APIGateway
LIBS_TO_CHECK="libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so"

pushd Examples/${EXAMPLE} || fatal "Failed to change directory to Examples/${EXAMPLE}."
pushd Examples || fatal "Failed to change directory to Examples."

# recompile the example without the --static-swift-stdlib flag
LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s || fatal "Failed to build the example."
LAMBDA_USE_LOCAL_DEPS=.. swift build --target "${EXAMPLE}" -c release -Xlinker -s || fatal "Failed to build the example."

# check if the binary exists
if [ ! -f "${OUTPUT_FILE}" ]; then
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/scripts/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ fatal() { error "$@"; exit 1; }

SWIFT_VERSION=$(swift --version)
test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset"
test -n "${COMMAND:-}" || fatal "COMMAND unset"
test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset"

pushd Examples/"$EXAMPLE" > /dev/null
pushd Examples > /dev/null

log "Running command with Swift $SWIFT_VERSION"
eval "$COMMAND"
eval "swift build && swift test"

popd
File renamed without changes.
63 changes: 0 additions & 63 deletions Examples/APIGateway+LambdaAuthorizer/Package.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Examples/APIGateway+LambdaAuthorizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ This example uses an authorizer that returns the simple response. The authorizer
To build the package, type the following commands.

```bash
swift build
swift package archive --allow-network-connections docker
swift build --target APIGatewayLambda --target AuthorizerLambda
swift package archive --products APIGatewayLambda --products AuthorizerLambda --allow-network-connections docker
```

If there is no error, there are two ZIP files ready to deploy, one for the authorizer function and one for the business function.
Expand Down
2 changes: 0 additions & 2 deletions Examples/APIGateway/.gitignore

This file was deleted.

56 changes: 0 additions & 56 deletions Examples/APIGateway/Package.swift

This file was deleted.

6 changes: 3 additions & 3 deletions Examples/APIGateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ The function must return a `APIGatewayV2Response`.
To build the package, type the following commands.

```bash
swift build
swift package archive --allow-network-connections docker
swift build --target APIGateway
swift package archive --products APIGateway --allow-network-connections docker
```

If there is no error, there is a ZIP file ready to deploy.
The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip`
The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGateway/APIGateway.zip`

## Deploy

Expand Down
69 changes: 69 additions & 0 deletions Examples/APIGateway/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"version": "2.0",
"routeKey": "$default",
"rawPath": "/my/path",
"rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value",
"cookies": [
"cookie1",
"cookie2"
],
"headers": {
"header1": "value1",
"header2": "value1,value2"
},
"queryStringParameters": {
"parameter1": "value1,value2",
"parameter2": "value"
},
"requestContext": {
"accountId": "123456789012",
"apiId": "api-id",
"authentication": {
"clientCert": {
"clientCertPem": "CERT_CONTENT",
"subjectDN": "www.example.com",
"issuerDN": "Example issuer",
"serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1",
"validity": {
"notBefore": "May 28 12:30:02 2019 GMT",
"notAfter": "Aug 5 09:36:04 2021 GMT"
}
}
},
"authorizer": {
"jwt": {
"claims": {
"claim1": "value1",
"claim2": "value2"
},
"scopes": [
"scope1",
"scope2"
]
}
},
"domainName": "id.execute-api.us-east-1.amazonaws.com",
"domainPrefix": "id",
"http": {
"method": "POST",
"path": "/my/path",
"protocol": "HTTP/1.1",
"sourceIp": "192.0.2.1",
"userAgent": "agent"
},
"requestId": "id",
"routeKey": "$default",
"stage": "$default",
"time": "12/Mar/2020:19:03:58 +0000",
"timeEpoch": 1583348638390
},
"body": "Hello from Lambda",
"pathParameters": {
"parameter1": "value1"
},
"isBase64Encoded": false,
"stageVariables": {
"stageVariable1": "value1",
"stageVariable2": "value2"
}
}
2 changes: 1 addition & 1 deletion Examples/APIGateway/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Resources:
APIGatewayLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip
CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGateway/APIGateway.zip
Timeout: 60
Handler: swift.bootstrap # ignored by the Swift runtime
Runtime: provided.al2
Expand Down
8 changes: 0 additions & 8 deletions Examples/BackgroundTasks/.gitignore

This file was deleted.

Loading