Skip to content

Commit

Permalink
improve examples (#292)
Browse files Browse the repository at this point in the history
motivation: examples can be confusing since they use relative path to the library for CI purposes

changes:
* update examples to use the library URL, expect when env variable is set for CI purposes
* rename docker compose job to test-examples since it is more accurate
  • Loading branch information
tomerd committed Mar 12, 2023
1 parent fb86060 commit 3b72f6a
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 45 deletions.
13 changes: 9 additions & 4 deletions Examples/Benchmark/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import class Foundation.ProcessInfo // needed for CI to test the local version of the library
import PackageDescription

let package = Package(
Expand All @@ -11,10 +12,7 @@ let package = Package(
.executable(name: "MyLambda", targets: ["MyLambda"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(name: "swift-aws-lambda-runtime", path: "../.."),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
],
targets: [
.executableTarget(
Expand All @@ -26,3 +24,10 @@ let package = Package(
),
]
)

// for CI to test the local version of the library
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
package.dependencies = [
.package(name: "swift-aws-lambda-runtime", path: "../.."),
]
}
13 changes: 9 additions & 4 deletions Examples/Deployment/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import class Foundation.ProcessInfo // needed for CI to test the local version of the library
import PackageDescription

let package = Package(
Expand All @@ -15,10 +16,7 @@ let package = Package(
// demonstrate different types of error handling
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(name: "swift-aws-lambda-runtime", path: "../.."),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
],
targets: [
.executableTarget(name: "Benchmark", dependencies: [
Expand All @@ -29,3 +27,10 @@ let package = Package(
]),
]
)

// for CI to test the local version of the library
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
package.dependencies = [
.package(name: "swift-aws-lambda-runtime", path: "../.."),
]
}
13 changes: 9 additions & 4 deletions Examples/Echo/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import class Foundation.ProcessInfo // needed for CI to test the local version of the library
import PackageDescription

let package = Package(
Expand All @@ -11,10 +12,7 @@ let package = Package(
.executable(name: "MyLambda", targets: ["MyLambda"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(name: "swift-aws-lambda-runtime", path: "../.."),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
],
targets: [
.executableTarget(
Expand All @@ -26,3 +24,10 @@ let package = Package(
),
]
)

// for CI to test the local version of the library
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
package.dependencies = [
.package(name: "swift-aws-lambda-runtime", path: "../.."),
]
}
13 changes: 9 additions & 4 deletions Examples/ErrorHandling/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import class Foundation.ProcessInfo // needed for CI to test the local version of the library
import PackageDescription

let package = Package(
Expand All @@ -11,10 +12,7 @@ let package = Package(
.executable(name: "MyLambda", targets: ["MyLambda"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(name: "swift-aws-lambda-runtime", path: "../.."),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
],
targets: [
.executableTarget(
Expand All @@ -26,3 +24,10 @@ let package = Package(
),
]
)

// for CI to test the local version of the library
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
package.dependencies = [
.package(name: "swift-aws-lambda-runtime", path: "../.."),
]
}
13 changes: 9 additions & 4 deletions Examples/Foundation/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import class Foundation.ProcessInfo // needed for CI to test the local version of the library
import PackageDescription

let package = Package(
Expand All @@ -11,10 +12,7 @@ let package = Package(
.executable(name: "MyLambda", targets: ["MyLambda"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(name: "swift-aws-lambda-runtime", path: "../.."),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
],
targets: [
.executableTarget(
Expand All @@ -26,3 +24,10 @@ let package = Package(
),
]
)

// for CI to test the local version of the library
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
package.dependencies = [
.package(name: "swift-aws-lambda-runtime", path: "../.."),
]
}
13 changes: 9 additions & 4 deletions Examples/JSON/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import class Foundation.ProcessInfo // needed for CI to test the local version of the library
import PackageDescription

let package = Package(
Expand All @@ -11,10 +12,7 @@ let package = Package(
.executable(name: "MyLambda", targets: ["MyLambda"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(name: "swift-aws-lambda-runtime", path: "../.."),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
],
targets: [
.executableTarget(
Expand All @@ -26,3 +24,10 @@ let package = Package(
),
]
)

// for CI to test the local version of the library
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
package.dependencies = [
.package(name: "swift-aws-lambda-runtime", path: "../.."),
]
}
17 changes: 12 additions & 5 deletions Examples/LocalDebugging/MyLambda/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import class Foundation.ProcessInfo // needed for CI to test the local version of the library
import PackageDescription

let package = Package(
Expand All @@ -11,10 +12,7 @@ let package = Package(
.executable(name: "MyLambda", targets: ["MyLambda"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(name: "swift-aws-lambda-runtime", path: "../../.."),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
.package(name: "Shared", path: "../Shared"),
],
targets: [
Expand All @@ -24,7 +22,16 @@ let package = Package(
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "Shared", package: "Shared"),
],
path: "."
path: ".",
exclude: ["scripts/", "Dockerfile"]
),
]
)

// for CI to test the local version of the library
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
package.dependencies = [
.package(name: "swift-aws-lambda-runtime", path: "../../.."),
.package(name: "Shared", path: "../Shared"),
]
}
13 changes: 9 additions & 4 deletions Examples/Testing/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import class Foundation.ProcessInfo // needed for CI to test the local version of the library
import PackageDescription

let package = Package(
Expand All @@ -11,10 +12,7 @@ let package = Package(
.executable(name: "MyLambda", targets: ["MyLambda"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(name: "swift-aws-lambda-runtime", path: "../.."),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
],
targets: [
.executableTarget(
Expand All @@ -28,3 +26,10 @@ let package = Package(
.testTarget(name: "MyLambdaTests", dependencies: ["MyLambda"], path: "Tests"),
]
)

// for CI to test the local version of the library
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
package.dependencies = [
.package(name: "swift-aws-lambda-runtime", path: "../.."),
]
}
2 changes: 1 addition & 1 deletion docker/docker-compose.al2.57.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
test:
image: swift-aws-lambda:al2-5.7

test-samples:
test-examples:
image: swift-aws-lambda:al2-5.7

shell:
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.al2.58.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
test:
image: swift-aws-lambda:al2-5.8

test-samples:
test-examples:
image: swift-aws-lambda:al2-5.8

shell:
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.al2.main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
test:
image: swift-aws-lambda:al2-main

test-samples:
test-examples:
image: swift-aws-lambda:al2-main

shell:
Expand Down
18 changes: 9 additions & 9 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ services:
<<: *common
command: /bin/bash -cl "swift test -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"

test-samples:
test-examples:
<<: *common
command: >-
/bin/bash -clx "
swift build --package-path Examples/Benchmark &&
swift build --package-path Examples/Deployment &&
swift build --package-path Examples/Echo &&
swift build --package-path Examples/ErrorHandling &&
swift build --package-path Examples/Foundation &&
swift build --package-path Examples/JSON &&
swift build --package-path Examples/LocalDebugging/MyLambda &&
swift test --package-path Examples/Testing
LAMBDA_USE_LOCAL_DEPS=true swift build --package-path Examples/Benchmark &&
LAMBDA_USE_LOCAL_DEPS=true swift build --package-path Examples/Deployment &&
LAMBDA_USE_LOCAL_DEPS=true swift build --package-path Examples/Echo &&
LAMBDA_USE_LOCAL_DEPS=true swift build --package-path Examples/ErrorHandling &&
LAMBDA_USE_LOCAL_DEPS=true swift build --package-path Examples/Foundation &&
LAMBDA_USE_LOCAL_DEPS=true swift build --package-path Examples/JSON &&
LAMBDA_USE_LOCAL_DEPS=true swift build --package-path Examples/LocalDebugging/MyLambda &&
LAMBDA_USE_LOCAL_DEPS=true swift test --package-path Examples/Testing
"
# util
Expand Down

0 comments on commit 3b72f6a

Please sign in to comment.