Skip to content

Commit b1010b3

Browse files
committed
add github action for e2e
1 parent 5d13fc2 commit b1010b3

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ jobs:
4545
java: [8, 8.0.192, 11.0.x, 11.0.3, 12, 13, 15, 16, 17 ]
4646
name: Java ${{ matrix.java }}
4747
env:
48-
OS: ${{ matrix.os }}
49-
JAVA: ${{ matrix.java-version }}
48+
JAVA: ${{ matrix.java }}
5049
AWS_REGION: eu-west-1
5150
steps:
5251
- uses: actions/checkout@v3

.github/workflows/run-e2e-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Run end-to-end tests
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
branches: [master]
8+
paths: # add other modules when there are under e2e tests
9+
- 'powertools-e2e-tests/**'
10+
- 'powertools-core/**'
11+
- 'powertools-serialization/**'
12+
- 'powertools-logging/**'
13+
- 'powertools-tracing/**'
14+
- 'powertools-idempotency/**'
15+
- 'powertools-metrics/**'
16+
- 'pom.xml'
17+
- '.github/workflows/**'
18+
19+
jobs:
20+
e2e:
21+
runs-on: ubuntu-latest
22+
strategy:
23+
max-parallel: 2
24+
matrix:
25+
java: [ 8, 11 ]
26+
name: End-to-end tests ${{ matrix.java }}
27+
env:
28+
JAVA_VERSION: ${{ matrix.java }}
29+
AWS_DEFAULT_REGION: eu-west-1
30+
permissions:
31+
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
32+
contents: read
33+
steps:
34+
- uses: actions/checkout@v3
35+
- name: Setup java
36+
uses: actions/setup-java@v2
37+
with:
38+
distribution: 'corretto'
39+
java-version: ${{ matrix.java }}
40+
- name: Setup AWS credentials
41+
uses: aws-actions/[email protected]
42+
with:
43+
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }}
44+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
45+
- name: Run e2e test with Maven
46+
run: mvn -Pe2e -B verify --file powertools-e2e-tests/pom.xml

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333

3434
import java.io.File;
3535
import java.io.IOException;
36+
import java.io.InputStream;
3637
import java.nio.file.Path;
3738
import java.util.*;
39+
import java.util.stream.Collectors;
3840

3941
import static java.util.Collections.singletonList;
4042

@@ -92,7 +94,7 @@ private Infrastructure(Builder builder) {
9294

9395
public String deploy() {
9496
uploadAssets();
95-
LOG.debug("Deploying '" + stackName + "' on account " + account);
97+
LOG.info("Deploying '" + stackName + "' on account " + account);
9698
cfn.createStack(CreateStackRequest.builder()
9799
.stackName(stackName)
98100
.templateBody(new Yaml().dump(cfnTemplate))
@@ -102,15 +104,15 @@ public String deploy() {
102104
.build());
103105
WaiterResponse<DescribeStacksResponse> waiterResponse = cfn.waiter().waitUntilStackCreateComplete(DescribeStacksRequest.builder().stackName(stackName).build());
104106
if (waiterResponse.matched().response().isPresent()) {
105-
LOG.debug("Stack " + waiterResponse.matched().response().get().stacks().get(0).stackName() + " successfully deployed");
107+
LOG.info("Stack " + waiterResponse.matched().response().get().stacks().get(0).stackName() + " successfully deployed");
106108
} else {
107109
throw new RuntimeException("Failed to create stack");
108110
}
109111
return functionName;
110112
}
111113

112114
public void destroy() {
113-
LOG.debug("Deleting '" + stackName + "' on account " + account);
115+
LOG.info("Deleting '" + stackName + "' on account " + account);
114116
cfn.deleteStack(DeleteStackRequest.builder().stackName(stackName).build());
115117
}
116118

@@ -124,10 +126,32 @@ public static class Builder {
124126
public String testName;
125127
private String stackName;
126128
private boolean tracing = false;
127-
private JavaRuntime runtime = JavaRuntime.JAVA11;
129+
private JavaRuntime runtime;
128130
private Map<String, String> environmentVariables = new HashMap<>();
129131
private String idemPotencyTable;
130132

133+
private Builder() {
134+
getJavaRuntime();
135+
}
136+
137+
/**
138+
* Retrieve the java runtime to use for the lambda function.
139+
*/
140+
private void getJavaRuntime() {
141+
String javaVersion = System.getenv("JAVA_VERSION"); // must be set in GitHub actions
142+
if (javaVersion == null) {
143+
throw new IllegalArgumentException("JAVA_VERSION is not set");
144+
}
145+
if (javaVersion.startsWith("8")) {
146+
runtime = JavaRuntime.JAVA8AL2;
147+
} else if (javaVersion.startsWith("11")) {
148+
runtime = JavaRuntime.JAVA11;
149+
} else {
150+
throw new IllegalArgumentException("Unsupported Java version " + javaVersion);
151+
}
152+
LOG.debug("Java Version set to {}, using runtime {}", javaVersion, runtime.getRuntime());
153+
}
154+
131155
public Infrastructure build() {
132156
Objects.requireNonNull(testName, "testName must not be null");
133157

@@ -153,11 +177,6 @@ public Builder tracing(boolean tracing) {
153177
return this;
154178
}
155179

156-
public Builder runtime(JavaRuntime runtime) {
157-
this.runtime = runtime;
158-
return this;
159-
}
160-
161180
public Builder idempotencyTable(String tableName) {
162181
this.idemPotencyTable = tableName;
163182
return this;
@@ -203,6 +222,7 @@ private Stack createStackWithLambda() {
203222

204223
functionName = stackName + "-function";
205224

225+
LOG.debug("Building Lambda function with command "+ packagingInstruction.stream().collect(Collectors.joining(" ", "[", "]")));
206226
Function function = Function.Builder
207227
.create(stack, functionName)
208228
.code(Code.fromAsset("handlers/", AssetOptions.builder()
@@ -255,10 +275,10 @@ private void uploadAssets() {
255275
}
256276
ListObjectsV2Response objects = s3.listObjectsV2(ListObjectsV2Request.builder().bucket(asset.bucketName).build());
257277
if (objects.contents().stream().anyMatch(o -> o.key().equals(objectKey))) {
258-
System.out.println("Asset already exists, skipping");
278+
LOG.debug("Asset already exists, skipping");
259279
return;
260280
}
261-
System.out.println("Uploading asset " + objectKey + " to " + asset.bucketName);
281+
LOG.info("Uploading asset " + objectKey + " to " + asset.bucketName);
262282
s3.putObject(PutObjectRequest.builder().bucket(asset.bucketName).key(objectKey).build(), Path.of(cfnAssetDirectory, asset.assetPath));
263283
});
264284
}

0 commit comments

Comments
 (0)