From 4cdd4bbbc86e18117e27d5f342549f2c6eb3069c Mon Sep 17 00:00:00 2001 From: Sebastien Stormacq Date: Sun, 30 Nov 2025 12:15:22 +0100 Subject: [PATCH 1/3] simplify local dependency injection for examples --- .github/workflows/pull_request.yml | 2 +- .../workflows/scripts/check-archive-plugin.sh | 2 +- .../scripts/check-link-foundation.sh | 2 +- Examples/APIGatewayV1/Package.swift | 38 +++-------------- .../Package.swift | 38 +++-------------- Examples/APIGatewayV2/Package.swift | 38 +++-------------- Examples/BackgroundTasks/Package.swift | 37 +++-------------- Examples/CDK/Package.swift | 38 +++-------------- Examples/HelloJSON/Package.swift | 40 +++--------------- Examples/HelloWorld/Package.swift | 37 +++-------------- Examples/HelloWorldNoTraits/Package.swift | 37 +++-------------- Examples/HummingbirdLambda/Package.swift | 40 +++--------------- Examples/MultiSourceAPI/Package.swift | 37 +++-------------- Examples/MultiTenant/Package.swift | 38 +++-------------- Examples/ResourcesPackaging/Package.swift | 36 +++------------- Examples/S3EventNotifier/Package.swift | 39 ++++-------------- Examples/S3_AWSSDK/Package.swift | 40 ++++-------------- Examples/S3_Soto/Package.swift | 41 ++++--------------- .../ServiceLifecycle+Postgres/Package.swift | 39 ++++-------------- Examples/Streaming+Codable/Package.swift | 40 ++++-------------- Examples/Streaming/Package.swift | 37 +++-------------- Examples/Testing/Package.swift | 38 +++-------------- Examples/Tutorial/Package.swift | 35 +++------------- Plugins/AWSLambdaPackager/Plugin.swift | 32 ++++----------- scripts/local_performance_test.sh | 4 +- scripts/ubuntu-test-plugin.sh | 2 +- 26 files changed, 132 insertions(+), 675 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6c3dbde8..05ba8061 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -35,7 +35,7 @@ jobs: with: name: "Integration tests" examples_enabled: true - matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=../.. swift build" + matrix_linux_command: "swift build" # 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 diff --git a/.github/workflows/scripts/check-archive-plugin.sh b/.github/workflows/scripts/check-archive-plugin.sh index 218ee79a..05d5c2f9 100755 --- a/.github/workflows/scripts/check-archive-plugin.sh +++ b/.github/workflows/scripts/check-archive-plugin.sh @@ -26,7 +26,7 @@ ZIP_FILE=${OUTPUT_DIR}/MyLambda/MyLambda.zip pushd "Examples/${EXAMPLE}" || 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 +swift package archive --allow-network-connections docker || exit 1 # did the plugin generated a Linux binary? [ -f "${OUTPUT_FILE}" ] diff --git a/.github/workflows/scripts/check-link-foundation.sh b/.github/workflows/scripts/check-link-foundation.sh index d62e3cc5..594781c9 100755 --- a/.github/workflows/scripts/check-link-foundation.sh +++ b/.github/workflows/scripts/check-link-foundation.sh @@ -25,7 +25,7 @@ LIBS_TO_CHECK="libFoundation.so libFoundationInternationalization.so lib_Foundat pushd Examples/${EXAMPLE} || fatal "Failed to change directory to Examples/${EXAMPLE}." # recompile the example without the --static-swift-stdlib flag -LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release || fatal "Failed to build the example." +swift build -c release || fatal "Failed to build the example." # check if the binary exists if [ ! -f "${OUTPUT_FILE}" ]; then diff --git a/Examples/APIGatewayV1/Package.swift b/Examples/APIGatewayV1/Package.swift index d28df7bf..7334a328 100644 --- a/Examples/APIGatewayV1/Package.swift +++ b/Examples/APIGatewayV1/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,8 +9,12 @@ let package = Package( .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ @@ -27,30 +28,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/APIGatewayV2+LambdaAuthorizer/Package.swift b/Examples/APIGatewayV2+LambdaAuthorizer/Package.swift index fdb6cd73..0874ed56 100644 --- a/Examples/APIGatewayV2+LambdaAuthorizer/Package.swift +++ b/Examples/APIGatewayV2+LambdaAuthorizer/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -13,8 +10,12 @@ let package = Package( .executable(name: "AuthorizerLambda", targets: ["AuthorizerLambda"]), ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ @@ -34,30 +35,3 @@ let package = Package( ), ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/APIGatewayV2/Package.swift b/Examples/APIGatewayV2/Package.swift index d28df7bf..7334a328 100644 --- a/Examples/APIGatewayV2/Package.swift +++ b/Examples/APIGatewayV2/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,8 +9,12 @@ let package = Package( .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ @@ -27,30 +28,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/BackgroundTasks/Package.swift b/Examples/BackgroundTasks/Package.swift index 713f8bb9..ecc659d0 100644 --- a/Examples/BackgroundTasks/Package.swift +++ b/Examples/BackgroundTasks/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,8 +9,11 @@ let package = Package( .executable(name: "BackgroundTasks", targets: ["BackgroundTasks"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0") + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../..") + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), ], targets: [ .executableTarget( @@ -25,30 +25,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/CDK/Package.swift b/Examples/CDK/Package.swift index d28df7bf..7334a328 100644 --- a/Examples/CDK/Package.swift +++ b/Examples/CDK/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,8 +9,12 @@ let package = Package( .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ @@ -27,30 +28,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/HelloJSON/Package.swift b/Examples/HelloJSON/Package.swift index b8b75c58..37466648 100644 --- a/Examples/HelloJSON/Package.swift +++ b/Examples/HelloJSON/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,11 +9,11 @@ let package = Package( .executable(name: "HelloJSON", targets: ["HelloJSON"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package( - url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - from: "2.0.0" - ) + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../..") + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), ], targets: [ .executableTarget( @@ -27,30 +24,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/HelloWorld/Package.swift b/Examples/HelloWorld/Package.swift index c3729536..975fef8c 100644 --- a/Examples/HelloWorld/Package.swift +++ b/Examples/HelloWorld/Package.swift @@ -7,9 +7,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -17,8 +14,11 @@ let package = Package( .executable(name: "MyLambda", targets: ["MyLambda"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0") + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../..") + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), ], targets: [ .executableTarget( @@ -30,30 +30,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/HelloWorldNoTraits/Package.swift b/Examples/HelloWorldNoTraits/Package.swift index 37d8e8d6..07d45f83 100644 --- a/Examples/HelloWorldNoTraits/Package.swift +++ b/Examples/HelloWorldNoTraits/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,8 +9,11 @@ let package = Package( .executable(name: "MyLambda", targets: ["MyLambda"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0", traits: []) + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../..") + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), ], targets: [ .executableTarget( @@ -25,30 +25,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath, traits: []) - ] -} diff --git a/Examples/HummingbirdLambda/Package.swift b/Examples/HummingbirdLambda/Package.swift index 879d448a..776db88f 100644 --- a/Examples/HummingbirdLambda/Package.swift +++ b/Examples/HummingbirdLambda/Package.swift @@ -3,17 +3,16 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "HBLambda", platforms: [.macOS(.v15)], dependencies: [ - .package( - url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - from: "2.0.0" - ), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package( url: "https://github.com/hummingbird-project/hummingbird-lambda.git", branch: "main" @@ -30,30 +29,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/MultiSourceAPI/Package.swift b/Examples/MultiSourceAPI/Package.swift index 83ec9e02..5661777e 100644 --- a/Examples/MultiSourceAPI/Package.swift +++ b/Examples/MultiSourceAPI/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "MultiSourceAPI", platforms: [.macOS(.v15)], @@ -12,7 +9,12 @@ let package = Package( .executable(name: "MultiSourceAPI", targets: ["MultiSourceAPI"]) ], dependencies: [ - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ @@ -26,30 +28,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - let indexToRemove = package.dependencies.firstIndex { dependency in - switch dependency.kind { - case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ): - return true - default: - return false - } - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/MultiTenant/Package.swift b/Examples/MultiTenant/Package.swift index c22dd399..6051738f 100644 --- a/Examples/MultiTenant/Package.swift +++ b/Examples/MultiTenant/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,8 +9,12 @@ let package = Package( .executable(name: "MultiTenant", targets: ["MultiTenant"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ @@ -26,30 +27,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/ResourcesPackaging/Package.swift b/Examples/ResourcesPackaging/Package.swift index de70b4e5..ce041e04 100644 --- a/Examples/ResourcesPackaging/Package.swift +++ b/Examples/ResourcesPackaging/Package.swift @@ -7,9 +7,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "ResourcesPackaging", platforms: [.macOS(.v15)], @@ -17,7 +14,11 @@ let package = Package( .executable(name: "MyLambda", targets: ["MyLambda"]) ], dependencies: [ - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0") + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../..") + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), ], targets: [ .executableTarget( @@ -32,30 +33,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/S3EventNotifier/Package.swift b/Examples/S3EventNotifier/Package.swift index 59eee0f4..f2d81b75 100644 --- a/Examples/S3EventNotifier/Package.swift +++ b/Examples/S3EventNotifier/Package.swift @@ -1,15 +1,17 @@ // swift-tools-version: 6.2 import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "S3EventNotifier", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), - .package(url: "https://github.com/awslabs/swift-aws-lambda-events", from: "1.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ .executableTarget( @@ -21,30 +23,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/S3_AWSSDK/Package.swift b/Examples/S3_AWSSDK/Package.swift index 68a73153..f04ee235 100644 --- a/Examples/S3_AWSSDK/Package.swift +++ b/Examples/S3_AWSSDK/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "AWSSDKExample", platforms: [.macOS(.v15)], @@ -12,9 +9,13 @@ let package = Package( .executable(name: "AWSSDKExample", targets: ["AWSSDKExample"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), - .package(url: "https://github.com/awslabs/swift-aws-lambda-events", from: "1.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), .package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"), ], targets: [ @@ -28,30 +29,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/S3_Soto/Package.swift b/Examples/S3_Soto/Package.swift index eb06b915..8e8d6816 100644 --- a/Examples/S3_Soto/Package.swift +++ b/Examples/S3_Soto/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "SotoExample", platforms: [.macOS(.v15)], @@ -12,11 +9,14 @@ let package = Package( .executable(name: "SotoExample", targets: ["SotoExample"]) ], dependencies: [ - .package(url: "https://github.com/soto-project/soto.git", from: "7.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), - .package(url: "https://github.com/awslabs/swift-aws-lambda-events", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"), ], targets: [ .executableTarget( @@ -29,30 +29,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/ServiceLifecycle+Postgres/Package.swift b/Examples/ServiceLifecycle+Postgres/Package.swift index aeea0613..de3ef51e 100644 --- a/Examples/ServiceLifecycle+Postgres/Package.swift +++ b/Examples/ServiceLifecycle+Postgres/Package.swift @@ -3,18 +3,20 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "LambdaWithServiceLifecycle", platforms: [ .macOS(.v15) ], dependencies: [ - .package(url: "https://github.com/vapor/postgres-nio.git", from: "1.26.0"), - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), + .package(url: "https://github.com/vapor/postgres-nio.git", from: "1.26.0"), .package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.3"), ], targets: [ @@ -29,30 +31,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/Streaming+Codable/Package.swift b/Examples/Streaming+Codable/Package.swift index 77e2f45b..7e6fdf2a 100644 --- a/Examples/Streaming+Codable/Package.swift +++ b/Examples/Streaming+Codable/Package.swift @@ -2,16 +2,17 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "StreamingCodable", platforms: [.macOS(.v15)], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), - .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.2.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ .executableTarget( @@ -30,30 +31,3 @@ let package = Package( ), ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/Streaming/Package.swift b/Examples/Streaming/Package.swift index 49bb3373..267668a9 100644 --- a/Examples/Streaming/Package.swift +++ b/Examples/Streaming/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,8 +9,11 @@ let package = Package( .executable(name: "StreamingNumbers", targets: ["StreamingNumbers"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0") + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../..") + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), ], targets: [ .executableTarget( @@ -25,30 +25,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/Testing/Package.swift b/Examples/Testing/Package.swift index 62734553..02445450 100644 --- a/Examples/Testing/Package.swift +++ b/Examples/Testing/Package.swift @@ -2,9 +2,6 @@ import PackageDescription -// needed for CI to test the local version of the library -import struct Foundation.URL - let package = Package( name: "swift-aws-lambda-runtime-example", platforms: [.macOS(.v15)], @@ -12,8 +9,12 @@ let package = Package( .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) ], dependencies: [ - // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"), + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../.."), + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), ], targets: [ @@ -35,30 +36,3 @@ let package = Package( ), ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Examples/Tutorial/Package.swift b/Examples/Tutorial/Package.swift index 357db119..ab875419 100644 --- a/Examples/Tutorial/Package.swift +++ b/Examples/Tutorial/Package.swift @@ -3,13 +3,15 @@ import PackageDescription -import struct Foundation.URL - let package = Package( name: "Palindrome", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0") + // For local development (default) + .package(name: "swift-aws-lambda-runtime", path: "../..") + + // For standalone usage, comment the line above and uncomment below: + // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. @@ -22,30 +24,3 @@ let package = Package( ) ] ) - -if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], - localDepsPath != "", - let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - v.isDirectory == true -{ - // when we use the local runtime as deps, let's remove the dependency added above - let indexToRemove = package.dependencies.firstIndex { dependency in - if case .sourceControl( - name: _, - location: "https://github.com/awslabs/swift-aws-lambda-runtime.git", - requirement: _ - ) = dependency.kind { - return true - } - return false - } - if let indexToRemove { - package.dependencies.remove(at: indexToRemove) - } - - // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) - print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") - package.dependencies += [ - .package(name: "swift-aws-lambda-runtime", path: localDepsPath) - ] -} diff --git a/Plugins/AWSLambdaPackager/Plugin.swift b/Plugins/AWSLambdaPackager/Plugin.swift index ad7d820d..1194c803 100644 --- a/Plugins/AWSLambdaPackager/Plugin.swift +++ b/Plugins/AWSLambdaPackager/Plugin.swift @@ -129,30 +129,14 @@ struct AWSLambdaPackager: CommandPlugin { print("building \"\(product.name)\"") let buildCommand = "swift build -c \(buildConfiguration.rawValue) --product \(product.name) --static-swift-stdlib" - if let localPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] { - // when developing locally, we must have the full swift-aws-lambda-runtime project in the container - // because Examples' Package.swift have a dependency on ../.. - // just like Package.swift's examples assume ../.., we assume we are two levels below the root project - let slice = packageDirectory.pathComponents.suffix(2) - try Utils.execute( - executable: dockerToolPath, - arguments: [ - "run", "--rm", "--env", "LAMBDA_USE_LOCAL_DEPS=\(localPath)", "-v", - "\(packageDirectory.path())../..:/workspace", "-w", - "/workspace/\(slice.joined(separator: "/"))", baseImage, "bash", "-cl", buildCommand, - ], - logLevel: verboseLogging ? .debug : .output - ) - } else { - try Utils.execute( - executable: dockerToolPath, - arguments: [ - "run", "--rm", "-v", "\(packageDirectory.path()):/workspace", "-w", "/workspace", baseImage, - "bash", "-cl", buildCommand, - ], - logLevel: verboseLogging ? .debug : .output - ) - } + try Utils.execute( + executable: dockerToolPath, + arguments: [ + "run", "--rm", "-v", "\(packageDirectory.path()):/workspace", "-w", "/workspace", baseImage, + "bash", "-cl", buildCommand, + ], + logLevel: verboseLogging ? .debug : .output + ) let productPath = buildOutputPath.appending(path: product.name) guard FileManager.default.fileExists(atPath: productPath.path()) else { diff --git a/scripts/local_performance_test.sh b/scripts/local_performance_test.sh index 36029d0a..10fa6a93 100755 --- a/scripts/local_performance_test.sh +++ b/scripts/local_performance_test.sh @@ -41,8 +41,8 @@ fi echo "🏗️ Building library and test functions" swift build -c release -Xswiftc -g -LAMBDA_USE_LOCAL_DEPS=../.. swift build --package-path Examples/HelloWorld -c release -Xswiftc -g -LAMBDA_USE_LOCAL_DEPS=../.. swift build --package-path Examples/HelloJSON -c release -Xswiftc -g +swift build --package-path Examples/HelloWorld -c release -Xswiftc -g +swift build --package-path Examples/HelloJSON -c release -Xswiftc -g cleanup() { pkill -9 MockServer && echo "killed previous mock server" # ignore-unacceptable-language diff --git a/scripts/ubuntu-test-plugin.sh b/scripts/ubuntu-test-plugin.sh index 51bf79ac..8c69bf9c 100644 --- a/scripts/ubuntu-test-plugin.sh +++ b/scripts/ubuntu-test-plugin.sh @@ -26,4 +26,4 @@ git clone https://github.com/awslabs/swift-aws-lambda-runtime.git # build the project cd swift-aws-lambda-runtime/Examples/ResourcesPackaging/ || exit 1 -LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker +swift package archive --allow-network-connections docker From d244689c9018142bc661f6587f18c8a7f3459421 Mon Sep 17 00:00:00 2001 From: Sebastien Stormacq Date: Sun, 30 Nov 2025 12:26:44 +0100 Subject: [PATCH 2/3] fix soto example --- Examples/S3_Soto/Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/S3_Soto/Package.swift b/Examples/S3_Soto/Package.swift index 8e8d6816..c9d23760 100644 --- a/Examples/S3_Soto/Package.swift +++ b/Examples/S3_Soto/Package.swift @@ -16,7 +16,7 @@ let package = Package( // .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"), .package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"), - .package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"), + .package(url: "https://github.com/soto-project/soto.git", from: "7.0.0"), ], targets: [ .executableTarget( From 8c5dc7834adfce67ae7e4705d28957db50a1fe81 Mon Sep 17 00:00:00 2001 From: Sebastien Stormacq Date: Sun, 30 Nov 2025 12:48:35 +0100 Subject: [PATCH 3/3] Fix resource packaging examples in CI --- .../workflows/scripts/check-archive-plugin.sh | 2 +- Plugins/AWSLambdaPackager/Plugin.swift | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/scripts/check-archive-plugin.sh b/.github/workflows/scripts/check-archive-plugin.sh index 05d5c2f9..218ee79a 100755 --- a/.github/workflows/scripts/check-archive-plugin.sh +++ b/.github/workflows/scripts/check-archive-plugin.sh @@ -26,7 +26,7 @@ ZIP_FILE=${OUTPUT_DIR}/MyLambda/MyLambda.zip pushd "Examples/${EXAMPLE}" || exit 1 # package the example (docker and swift toolchain are installed on the GH runner) -swift package archive --allow-network-connections docker || exit 1 +LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker || exit 1 # did the plugin generated a Linux binary? [ -f "${OUTPUT_FILE}" ] diff --git a/Plugins/AWSLambdaPackager/Plugin.swift b/Plugins/AWSLambdaPackager/Plugin.swift index 1194c803..ad7d820d 100644 --- a/Plugins/AWSLambdaPackager/Plugin.swift +++ b/Plugins/AWSLambdaPackager/Plugin.swift @@ -129,14 +129,30 @@ struct AWSLambdaPackager: CommandPlugin { print("building \"\(product.name)\"") let buildCommand = "swift build -c \(buildConfiguration.rawValue) --product \(product.name) --static-swift-stdlib" - try Utils.execute( - executable: dockerToolPath, - arguments: [ - "run", "--rm", "-v", "\(packageDirectory.path()):/workspace", "-w", "/workspace", baseImage, - "bash", "-cl", buildCommand, - ], - logLevel: verboseLogging ? .debug : .output - ) + if let localPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] { + // when developing locally, we must have the full swift-aws-lambda-runtime project in the container + // because Examples' Package.swift have a dependency on ../.. + // just like Package.swift's examples assume ../.., we assume we are two levels below the root project + let slice = packageDirectory.pathComponents.suffix(2) + try Utils.execute( + executable: dockerToolPath, + arguments: [ + "run", "--rm", "--env", "LAMBDA_USE_LOCAL_DEPS=\(localPath)", "-v", + "\(packageDirectory.path())../..:/workspace", "-w", + "/workspace/\(slice.joined(separator: "/"))", baseImage, "bash", "-cl", buildCommand, + ], + logLevel: verboseLogging ? .debug : .output + ) + } else { + try Utils.execute( + executable: dockerToolPath, + arguments: [ + "run", "--rm", "-v", "\(packageDirectory.path()):/workspace", "-w", "/workspace", baseImage, + "bash", "-cl", buildCommand, + ], + logLevel: verboseLogging ? .debug : .output + ) + } let productPath = buildOutputPath.appending(path: product.name) guard FileManager.default.fileExists(atPath: productPath.path()) else {