Skip to content

Commit a9ce7be

Browse files
chore(ci): Run unit tests for GraalVM as well during build. (#2047)
* chore(ci): Run unit tests for GraalVM as well during build. * Test GraalVM unit tests on Mockito 5.16.0. * Fix native tests in powertools-serialization. Remove mockito dependency there. * Remove mockito from powertools-common. * Remove mockito from powertools-metrics and re-use TestLamdaContext from powertools-common. * Remove mockito from powertools-serialization. * Remove mockito from powertools-logging. * Remove mockito from powertools-logging-log4j. * Add --initialize-at-build-time=org.junit.platform.launcher.core.DiscoveryIssueNotifier * Remove mockito from powertools-logging-logback. * Remove mockito from powertools-tracing. * Build project first to make sure test-jar dependencies are available for graalvm unit tests. * Enable maven quite mode and search recursively for graalvm profiles to make sure sub-sub-modules are also covered. * Add back Mockito to powertools-common. * Simplify graalvm config for logback and log4j modules. * Simplify graalvm config in powertools-logging. * Cleanup GRM files for logback module. * Simplify GraalVM config for powertools-metrics, powertools-serialization, powertools-tracing. * Remove <! or newer version --> comment. * Simplify powertools-parameters-tests GraalVM config and fix issues in unit tests. * Simplify powertools-parameters-ssm GraalVM config and fix issues in unit tests. * Simplify powertools-parameters-secrets GraalVM config and fix issues in unit tests. * Simplify powertools-parameters-dynamodb GraalVM config and fix issues in unit tests. * Simplify powertools-parameters-appconfig GraalVM config and fix issues in unit tests. * Fix SonarCube finding. * Allowlist UPL-1.0 license. * Add TT ID to UPL license. * Enable Maven Central snapshot repo temporarily. * Potential fix for code scanning alert no. 54: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Disable verbose resource registration logs. --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent cbdf81f commit a9ce7be

File tree

37 files changed

+544
-1011
lines changed

37 files changed

+544
-1011
lines changed

.github/dependency-review-config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ allow-licenses:
2727
- 'BSD-3-Clause-No-Nuclear-License-2014'
2828
- 'BSD-3-Clause-No-Nuclear-Warranty'
2929
- 'BSD-3-Clause-Open-MPI'
30-
comment-summary-in-pr: on-failure
30+
# TT: D290816995
31+
- 'UPL-1.0'
32+
comment-summary-in-pr: on-failure

.github/workflows/check-build.yml

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
#
33
# Description:
44
# Runs the build for every java version we support
5-
#
5+
#
66
# Triggers:
77
# - pull_request: when a PR is sent to us
88
# - push: when code is pushed to a specified branch
99
#
1010
# Notes:
11-
# The matrix build for this workflow is unusual, we need to make it dyanmic since
12-
# we need to change java versions we build for depending on the branch.
13-
11+
# Builds against Java 11, 17, and 21 which are the supported versions.
1412

1513
on:
1614
workflow_dispatch:
@@ -38,7 +36,7 @@ on:
3836
push:
3937
branches:
4038
- main
41-
paths: # add other modules when there are under e2e tests
39+
paths:
4240
- 'powertools-batch/**'
4341
- 'powertools-core/**'
4442
- 'powertools-cloudformation/**'
@@ -60,34 +58,16 @@ on:
6058
- '.github/workflows/**'
6159

6260
name: Build
61+
permissions:
62+
contents: read
6363
run-name: Build - ${{ github.event_name }}
6464

6565
jobs:
66-
setup:
67-
runs-on: ubuntu-latest
68-
outputs:
69-
build_matrix: ${{ format('{0}{1}', steps.build_matrix_v1.outputs.build_matrix, steps.build_matrix_v1.outputs.build_matrix) }}
70-
steps:
71-
- id: base
72-
name: Base
73-
run: |
74-
echo build_version=$(test ${{ github.ref }} == "v2" && echo "v2" || echo "v1") >> $GITHUB_OUTPUT
75-
- id: build_matrix_v1
76-
name: Build matrix (v1)
77-
if: ${{ steps.base.outputs.build_version == 'v1' }}
78-
run: |
79-
echo build_matrix='["8", "11", "17", "21"]' >> "$GITHUB_OUTPUT"
80-
- id: build_matrix_v2
81-
name: Build matrix (v2)
82-
if: ${{ steps.base.outputs.build_version == 'v2' }}
83-
run: |
84-
echo build_matrix='["11", "17", "21"]'>> "$GITHUB_OUTPUT"
85-
build:
66+
java-build:
8667
runs-on: ubuntu-latest
8768
strategy:
8869
matrix:
8970
java:
90-
- 8
9171
- 11
9272
- 17
9373
- 21
@@ -103,6 +83,35 @@ jobs:
10383
cache: maven
10484
- id: build-maven
10585
name: Build (Maven)
106-
if: ${{ matrix.java != '8' }}
10786
run: |
108-
mvn -B install --file pom.xml
87+
mvn -B -q install --file pom.xml
88+
89+
graalvm-build:
90+
runs-on: ubuntu-latest
91+
steps:
92+
- id: checkout
93+
name: Checkout repository
94+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
95+
- name: Setup GraalVM
96+
uses: graalvm/setup-graalvm@7f488cf82a3629ee755e4e97342c01d6bed318fa # v1.3.5
97+
with:
98+
java-version: "21"
99+
distribution: "graalvm"
100+
cache: maven
101+
- id: graalvm-native-test
102+
name: GraalVM Native Test
103+
run: |
104+
# Build the entire project first to ensure test-jar dependencies are available
105+
mvn -B -q install -DskipTests
106+
107+
# Find modules with graalvm-native profile and run tests recursively.
108+
# This will make sure to discover new GraalVM supported modules automatically in the future.
109+
find . -name "pom.xml" -path "./powertools-*" | while read module; do
110+
if grep -q "<id>graalvm-native</id>" "$module"; then
111+
module_dir=$(dirname "$module")
112+
echo "Regenerating GraalVM metadata for $module_dir"
113+
mvn -B -q -f "$module" -Pgenerate-graalvm-files clean test
114+
echo "Running GraalVM native tests for $module_dir"
115+
mvn -B -q -f "$module" -Pgraalvm-native test
116+
fi
117+
done

pom.xml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
<maven-javadoc-plugin.version>3.11.3</maven-javadoc-plugin.version>
102102
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
103103
<maven-gpg-plugin.version>3.2.1</maven-gpg-plugin.version>
104-
<junit.version>5.10.0</junit.version>
105104
<aspectj-maven-plugin.version>1.14.1</aspectj-maven-plugin.version>
106105
<maven-surefire-plugin.version>3.5.3</maven-surefire-plugin.version>
107106
<jacoco-maven-plugin.version>0.8.13</jacoco-maven-plugin.version>
@@ -115,8 +114,8 @@
115114
<aws.sdk.v1.version>1.12.781</aws.sdk.v1.version>
116115
<versions-maven-plugin.version>2.18.0</versions-maven-plugin.version>
117116
<elastic.version>1.7.0</elastic.version>
118-
<mockito.version>5.18.0</mockito.version>
119-
<mockito-junit-jupiter.version>5.18.0</mockito-junit-jupiter.version>
117+
<mockito.version>5.19.1-SNAPSHOT</mockito.version>
118+
<mockito-junit-jupiter.version>5.19.1-SNAPSHOT</mockito-junit-jupiter.version>
120119
<junit-pioneer.version>2.3.0</junit-pioneer.version>
121120
<crac.version>1.5.0</crac.version>
122121

@@ -132,6 +131,21 @@
132131
</snapshotRepository>
133132
</distributionManagement>
134133

134+
<!-- https://central.sonatype.org/publish/publish-portal-snapshots/#consuming-via-maven -->
135+
<repositories>
136+
<repository>
137+
<name>Central Portal Snapshots</name>
138+
<id>central-portal-snapshots</id>
139+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
140+
<releases>
141+
<enabled>false</enabled>
142+
</releases>
143+
<snapshots>
144+
<enabled>true</enabled>
145+
</snapshots>
146+
</repository>
147+
</repositories>
148+
135149
<dependencyManagement>
136150
<dependencies>
137151
<dependency>
@@ -323,7 +337,7 @@
323337
<dependency>
324338
<groupId>org.junit-pioneer</groupId>
325339
<artifactId>junit-pioneer</artifactId>
326-
<version>2.0.0</version>
340+
<version>${junit-pioneer.version}</version>
327341
<scope>test</scope>
328342
</dependency>
329343
<dependency>

powertools-common/pom.xml

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
-->
1515

1616
<project xmlns="http://maven.apache.org/POM/4.0.0"
17-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
17+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1919
<modelVersion>4.0.0</modelVersion>
2020

2121
<artifactId>powertools-common</artifactId>
@@ -77,13 +77,13 @@
7777
<scope>test</scope>
7878
</dependency>
7979
<dependency>
80-
<groupId>org.mockito</groupId>
81-
<artifactId>mockito-core</artifactId>
80+
<groupId>org.slf4j</groupId>
81+
<artifactId>slf4j-simple</artifactId>
8282
<scope>test</scope>
8383
</dependency>
8484
<dependency>
85-
<groupId>org.slf4j</groupId>
86-
<artifactId>slf4j-simple</artifactId>
85+
<groupId>org.mockito</groupId>
86+
<artifactId>mockito-core</artifactId>
8787
<scope>test</scope>
8888
</dependency>
8989
</dependencies>
@@ -94,7 +94,6 @@
9494
<dependency>
9595
<groupId>org.mockito</groupId>
9696
<artifactId>mockito-subclass</artifactId>
97-
<version>5.18.0</version>
9897
<scope>test</scope>
9998
</dependency>
10099
</dependencies>
@@ -105,7 +104,9 @@
105104
<artifactId>maven-surefire-plugin</artifactId>
106105
<version>3.5.3</version>
107106
<configuration>
108-
<argLine>-Dmockito.mock.maker=subclass -Dorg.graalvm.nativeimage.imagecode=agent -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image/software.amazon.lambda/powertools-common,experimental-class-define-support
107+
<argLine>
108+
-Dorg.graalvm.nativeimage.imagecode=agent
109+
-agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image/software.amazon.lambda/powertools-common,experimental-class-define-support
109110
--add-opens java.base/java.util=ALL-UNNAMED
110111
--add-opens java.base/java.lang=ALL-UNNAMED
111112
</argLine>
@@ -120,7 +121,6 @@
120121
<dependency>
121122
<groupId>org.mockito</groupId>
122123
<artifactId>mockito-subclass</artifactId>
123-
<version>5.18.0</version>
124124
<scope>test</scope>
125125
</dependency>
126126
</dependencies>
@@ -129,7 +129,7 @@
129129
<plugin>
130130
<groupId>org.graalvm.buildtools</groupId>
131131
<artifactId>native-maven-plugin</artifactId>
132-
<version>0.11.0</version> <!-- or newer version -->
132+
<version>0.11.0</version>
133133
<extensions>true</extensions>
134134
<executions>
135135
<execution>
@@ -146,33 +146,10 @@
146146
<buildArg>--add-opens java.base/java.util=ALL-UNNAMED</buildArg>
147147
<buildArg>--add-opens java.base/java.lang=ALL-UNNAMED</buildArg>
148148
<buildArg>--no-fallback</buildArg>
149-
<buildArg>-Dorg.graalvm.nativeimage.imagecode=agent</buildArg>
150-
<buildArg>-H:ClassInitialization=net.bytebuddy.ClassFileVersion:rerun</buildArg>
151-
<buildArg>-H:ClassInitialization=net.bytebuddy.utility.dispatcher.JavaDispatcher:rerun</buildArg>
152-
<buildArg>-H:ClassInitialization=net.bytebuddy.utility.Invoker$Dispatcher:rerun</buildArg>
153-
<buildArg>-H:ClassInitialization=net.bytebuddy.utility.GraalImageCode:rerun</buildArg>
154-
<buildArg>--initialize-at-build-time=org.slf4j.simple.SimpleLogger</buildArg>
155-
<buildArg>--initialize-at-build-time=org.slf4j.LoggerFactory</buildArg>
156-
<buildArg>--initialize-at-build-time=org.junit.Ignore</buildArg>
157-
<buildArg>--initialize-at-build-time=java.lang.annotation.Annotation</buildArg>
158-
<buildArg>--initialize-at-build-time=org.junit.runners.model.FrameworkField</buildArg>
159-
<buildArg>--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$AbstractBase</buildArg>
160-
<buildArg>--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic</buildArg>
161-
<buildArg>--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1</buildArg>
162-
<buildArg>--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2</buildArg>
163-
<buildArg>--initialize-at-build-time=net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader</buildArg>
164-
<buildArg>--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable</buildArg>
165-
<buildArg>--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$AbstractBase</buildArg>
166-
<buildArg>--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$ForLoadedType</buildArg>
167-
<buildArg>--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$ForLoadedMethod</buildArg>
168-
<buildArg>--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2</buildArg>
169-
<buildArg>
170-
--trace-class-initialization=net.bytebuddy.description.type.TypeDescription$ForLoadedType,net.bytebuddy.description.method.MethodDescription$ForLoadedMethod,net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable
171-
</buildArg>
172149
<buildArg>--verbose</buildArg>
173150
<buildArg>--native-image-info</buildArg>
174151
<buildArg>-H:+UnlockExperimentalVMOptions</buildArg>
175-
<buildArg>-H:Log=registerResource:5</buildArg>
152+
<buildArg>-H:+ReportExceptionStackTraces</buildArg>
176153
</buildArgs>
177154
</configuration>
178155
</plugin>
@@ -192,5 +169,18 @@
192169
<directory>src/main/resources</directory>
193170
</resource>
194171
</resources>
172+
<plugins>
173+
<plugin>
174+
<groupId>org.apache.maven.plugins</groupId>
175+
<artifactId>maven-jar-plugin</artifactId>
176+
<executions>
177+
<execution>
178+
<goals>
179+
<goal>test-jar</goal>
180+
</goals>
181+
</execution>
182+
</executions>
183+
</plugin>
184+
</plugins>
195185
</build>
196186
</project>

0 commit comments

Comments
 (0)