Skip to content

Commit 040f184

Browse files
committed
Merge branch 'main' into sebsto/tutorial
2 parents f059809 + 38cc01a commit 040f184

File tree

86 files changed

+3791
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3791
-430
lines changed

.devcontainer/devcontainer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "Swift",
3+
"image": "swift:6.0",
4+
"features": {
5+
"ghcr.io/devcontainers/features/common-utils:2": {
6+
"installZsh": "false",
7+
"username": "vscode",
8+
"upgradePackages": "false"
9+
},
10+
"ghcr.io/devcontainers/features/git:1": {
11+
"version": "os-provided",
12+
"ppa": "false"
13+
}
14+
},
15+
"runArgs": [
16+
"--cap-add=SYS_PTRACE",
17+
"--security-opt",
18+
"seccomp=unconfined"
19+
],
20+
// Configure tool-specific properties.
21+
"customizations": {
22+
// Configure properties specific to VS Code.
23+
"vscode": {
24+
// Set *default* container specific settings.json values on container create.
25+
"settings": {
26+
"lldb.library": "/usr/lib/liblldb.so"
27+
},
28+
// Add the IDs of extensions you want installed when the container is created.
29+
"extensions": [
30+
"sswg.swift-lang"
31+
]
32+
}
33+
},
34+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
35+
// "forwardPorts": [],
36+
37+
// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
38+
"remoteUser": "vscode"
39+
}

.github/release.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ changelog:
55
- ⚠️ semver/major
66
- title: SemVer Minor
77
labels:
8-
- semver/minor
8+
- 🆕 semver/minor
99
- title: SemVer Patch
1010
labels:
11-
- semver/patch
11+
- 🔨 semver/patch
1212
- title: Other Changes
1313
labels:
1414
- semver/none
15-
- "*"

.github/workflows/integration_tests.yml

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ExamplesMatrix
1+
name: IntegrationTests
22

33
on:
44
workflow_call:
@@ -23,6 +23,10 @@ on:
2323
type: boolean
2424
description: "Boolean to enable the test of the archive plugin. Defaults to true."
2525
default: true
26+
check_foundation_enabled:
27+
type: boolean
28+
description: "Boolean to enable the check for Foundation dependency. Defaults to true."
29+
default: true
2630
matrix_linux_command:
2731
type: string
2832
description: "The command of the current Swift version linux matrix job to execute."
@@ -88,15 +92,12 @@ jobs:
8892
COMMAND: ${{ inputs.matrix_linux_command }}
8993
EXAMPLE: ${{ matrix.examples }}
9094
run: |
91-
./scripts/integration_tests.sh
92-
echo "✅ The examples compile correctly"
95+
.github/workflows/scripts/integration_tests.sh
9396
9497
test-archive-plugin:
9598
name: Test archive plugin
9699
if: ${{ inputs.archive_plugin_enabled }}
97100
runs-on: ubuntu-latest
98-
strategy:
99-
fail-fast: false
100101
steps:
101102
- name: Checkout repository
102103
uses: actions/checkout@v4
@@ -106,25 +107,21 @@ jobs:
106107
# https://github.com/actions/checkout/issues/766
107108
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
108109
- name: Test the archive plugin
109-
env:
110-
EXAMPLE: HelloWorld
111-
OUTPUT_FILE: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/bootstrap
112-
ZIP_FILE: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip
113110
run: |
114-
pushd Examples/${EXAMPLE}
111+
.github/workflows/scripts/check-archive-plugin.sh
115112
116-
# package the example (docker and swift toolchain are installed on the GH runner)
117-
echo yes | swift package archive --allow-network-connections docker
118-
119-
# did the plugin generated a Linux binary?
120-
[ -f ${OUTPUT_FILE} ]
121-
file ${OUTPUT_FILE} | grep --silent ELF
122-
123-
# did the plugin created a ZIP file?
124-
[ -f ${ZIP_FILE} ]
125-
126-
# does the ZIP file contain the bootstrap?
127-
unzip -l ${ZIP_FILE} | grep --silent bootstrap
128-
129-
echo "✅ The archive plugin is OK"
130-
popd
113+
check-foundation:
114+
name: No dependencies on Foundation
115+
if: ${{ inputs.check_foundation_enabled }}
116+
runs-on: ubuntu-latest
117+
steps:
118+
- name: Checkout repository
119+
uses: actions/checkout@v4
120+
with:
121+
persist-credentials: false
122+
- name: Mark the workspace as safe
123+
# https://github.com/actions/checkout/issues/766
124+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
125+
- name: Check for Foundation or ICU dependency
126+
run: |
127+
.github/workflows/scripts/check-link-foundation.sh

.github/workflows/pull_request.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ jobs:
1010
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
1111
with:
1212
license_header_check_project_name: "SwiftAWSLambdaRuntime"
13-
shell_check_enabled: false
14-
python_lint_check_enabled: false
13+
shell_check_enabled: true
14+
python_lint_check_enabled: true
1515
api_breakage_check_container_image: "swift:6.0-noble"
1616
docs_check_container_image: "swift:6.0-noble"
1717
format_check_container_image: "swiftlang/swift:nightly-6.0-jammy"
18+
yamllint_check_enabled: true
1819

1920
unit-tests:
2021
name: Unit tests
@@ -35,14 +36,26 @@ jobs:
3536
# We pass the list of examples here, but we can't pass an array as argument
3637
# Instead, we pass a String with a valid JSON array.
3738
# The workaround is mentioned here https://github.com/orgs/community/discussions/11692
38-
examples: "[ 'APIGateway', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'S3_AWSSDK', 'S3_Soto', 'Streaming' ]"
39+
examples: "[ 'APIGateway', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Testing' ]"
3940

4041
archive_plugin_enabled: true
4142

4243
swift-6-language-mode:
4344
name: Swift 6 Language Mode
4445
uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main
4546

47+
semver-label-check:
48+
name: Semantic Version label check
49+
runs-on: ubuntu-latest
50+
timeout-minutes: 1
51+
steps:
52+
- name: Checkout repository
53+
uses: actions/checkout@v4
54+
with:
55+
persist-credentials: false
56+
- name: Check for Semantic Version label
57+
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main
58+
4659
# until there is a support for musl in swiftlang/github-workflows
4760
# https://github.com/swiftlang/github-workflows/issues/34
4861
musl:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftAWSLambdaRuntime open source project
5+
##
6+
## Copyright (c) 2017-2024 Apple Inc. and the SwiftAWSLambdaRuntime project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
EXAMPLE=HelloWorld
17+
OUTPUT_DIR=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager
18+
OUTPUT_FILE=${OUTPUT_DIR}/MyLambda/bootstrap
19+
ZIP_FILE=${OUTPUT_DIR}/MyLambda/MyLambda.zip
20+
21+
pushd Examples/${EXAMPLE} || exit 1
22+
23+
# package the example (docker and swift toolchain are installed on the GH runner)
24+
LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker || exit 1
25+
26+
# did the plugin generated a Linux binary?
27+
[ -f "${OUTPUT_FILE}" ]
28+
file "${OUTPUT_FILE}" | grep --silent ELF
29+
30+
# did the plugin created a ZIP file?
31+
[ -f "${ZIP_FILE}" ]
32+
33+
# does the ZIP file contain the bootstrap?
34+
unzip -l "${ZIP_FILE}" | grep --silent bootstrap
35+
36+
echo "✅ The archive plugin is OK"
37+
popd || exit 1
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftAWSLambdaRuntime open source project
5+
##
6+
## Copyright (c) 2017-2024 Apple Inc. and the SwiftAWSLambdaRuntime project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
EXAMPLE=APIGateway
21+
OUTPUT_DIR=.build/release
22+
OUTPUT_FILE=${OUTPUT_DIR}/APIGatewayLambda
23+
LIBS_TO_CHECK="libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so"
24+
25+
pushd Examples/${EXAMPLE} || fatal "Failed to change directory to Examples/${EXAMPLE}."
26+
27+
# recompile the example without the --static-swift-stdlib flag
28+
LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s || fatal "Failed to build the example."
29+
30+
# check if the binary exists
31+
if [ ! -f "${OUTPUT_FILE}" ]; then
32+
error "${OUTPUT_FILE} does not exist."
33+
fi
34+
35+
# Checking for Foundation or ICU dependencies
36+
echo "Checking for Foundation or ICU dependencies in ${OUTPUT_DIR}/${OUTPUT_FILE}."
37+
LIBRARIES=$(ldd ${OUTPUT_FILE} | awk '{print $1}')
38+
for LIB in ${LIBS_TO_CHECK}; do
39+
echo -n "Checking for ${LIB}... "
40+
41+
# check if the binary has a dependency on Foundation or ICU
42+
echo "${LIBRARIES}" | grep "${LIB}" # return 1 if not found
43+
44+
# 1 is success (grep failed to find the lib), 0 is failure (grep successly found the lib)
45+
SUCCESS=$?
46+
if [ "$SUCCESS" -eq 0 ]; then
47+
log "${LIB} found." && break
48+
else
49+
log "${LIB} not found."
50+
fi
51+
done
52+
53+
popd || fatal "Failed to change directory back to the root directory."
54+
55+
# exit code is the opposite of the grep exit code
56+
if [ "$SUCCESS" -eq 0 ]; then
57+
fatal "❌ At least one foundation lib was found, reporting the error."
58+
else
59+
log "✅ No foundation lib found, congrats!" && exit 0
60+
fi

scripts/integration_tests.sh renamed to .github/workflows/scripts/integration_tests.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ fatal() { error "$@"; exit 1; }
2222
test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset"
2323
test -n "${COMMAND:-}" || fatal "COMMAND unset"
2424
test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset"
25-
swift_version="$SWIFT_VERSION"
26-
command="$COMMAND"
27-
example="$EXAMPLE"
2825

29-
pushd Examples/"$example" > /dev/null
26+
pushd Examples/"$EXAMPLE" > /dev/null
3027

3128
log "Running command with Swift $SWIFT_VERSION"
32-
eval "$command"
29+
eval "$COMMAND"
3330

3431
popd

.licenseignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ Package.resolved
3232
.swiftformat
3333
*.yaml
3434
*.yml
35+
**/.npmignore
36+
**/*.json

Examples/APIGateway/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let package = Package(
2929
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
3030
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
3131
],
32-
path: "."
32+
path: "Sources"
3333
)
3434
]
3535
)

Examples/APIGateway/Sources/main.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
import AWSLambdaEvents
1616
import AWSLambdaRuntime
1717

18-
#if canImport(FoundationEssentials)
19-
import FoundationEssentials
20-
#else
21-
import Foundation
22-
#endif
23-
24-
let encoder = JSONEncoder()
2518
let runtime = LambdaRuntime {
2619
(event: APIGatewayV2Request, context: LambdaContext) -> APIGatewayV2Response in
2720

@@ -31,10 +24,7 @@ let runtime = LambdaRuntime {
3124
header["content-type"] = "application/json"
3225

3326
// echo the request in the response
34-
let data = try encoder.encode(event)
35-
let response = String(decoding: data, as: Unicode.UTF8.self)
36-
37-
return APIGatewayV2Response(statusCode: .ok, headers: header, body: response)
27+
return try APIGatewayV2Response(statusCode: .ok, headers: header, encodableBody: event)
3828
}
3929

4030
try await runtime.run()

Examples/BackgroundTasks/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let package = Package(
2727
dependencies: [
2828
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime")
2929
],
30-
path: "."
30+
path: "Sources"
3131
)
3232
]
3333
)

Examples/BackgroundTasks/Sources/main.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import AWSLambdaRuntime
16+
17+
#if canImport(FoundationEssentials)
18+
import FoundationEssentials
19+
#else
1620
import Foundation
21+
#endif
1722

1823
struct BackgroundProcessingHandler: LambdaWithBackgroundProcessingHandler {
1924
struct Input: Decodable {

0 commit comments

Comments
 (0)