Skip to content

Commit cc96311

Browse files
Use workflow artifacts to resolve latest Maven version in instrumentation tests (#11650)
feat: read latest maven version from workflow artifacts nit: comment Co-authored-by: daniel.mohedano <daniel.mohedano@datadoghq.com>
1 parent 1b4d0ee commit cc96311

3 files changed

Lines changed: 35 additions & 40 deletions

File tree

.github/workflows/update-smoke-test-latest-versions.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ jobs:
110110
"maven-surefire.latest=${SUREFIRE_VERSION}" \
111111
> dd-smoke-tests/maven/src/test/resources/latest-tool-versions.properties
112112
113+
printf '%s\n' \
114+
"# Pinned latest eligible stable version (>=${MIN_DEPENDENCY_AGE_HOURS}h old) for the Maven instrumentation latestDepTest." \
115+
"# Updated automatically by the update-smoke-test-latest-versions workflow." \
116+
"maven-surefire.latest=${SUREFIRE_VERSION}" \
117+
> dd-java-agent/instrumentation/maven/maven-3.2.1/src/test/resources/latest-tool-versions.properties
118+
113119
- name: Check for changes
114120
id: check-changes
115121
run: |
@@ -135,7 +141,8 @@ jobs:
135141
if: steps.check-changes.outputs.has_changes == 'true'
136142
run: |
137143
git add dd-smoke-tests/gradle/src/test/resources/latest-tool-versions.properties \
138-
dd-smoke-tests/maven/src/test/resources/latest-tool-versions.properties
144+
dd-smoke-tests/maven/src/test/resources/latest-tool-versions.properties \
145+
dd-java-agent/instrumentation/maven/maven-3.2.1/src/test/resources/latest-tool-versions.properties
139146
git commit -m "chore: Update smoke test latest tool versions"
140147
141148
- name: Push changes
@@ -161,7 +168,8 @@ jobs:
161168
--body "$(cat <<'EOF'
162169
# What Does This Do
163170
164-
This PR updates the pinned latest eligible stable tool versions used by CI Visibility smoke tests.
171+
This PR updates the pinned latest eligible stable tool versions used by CI Visibility smoke tests
172+
and by the Maven instrumentation latestDepTest.
165173
Only releases at least ${{ env.MIN_DEPENDENCY_AGE_HOURS }} hours old are eligible.
166174
167175
- Gradle: ${{ steps.update.outputs.gradle_line }}

dd-java-agent/instrumentation/maven/maven-3.2.1/src/test/java/datadog/trace/instrumentation/maven3/MavenUtilsTest.java

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@
1515
import java.io.File;
1616
import java.io.FileWriter;
1717
import java.io.IOException;
18+
import java.io.InputStream;
1819
import java.net.URISyntaxException;
1920
import java.nio.file.Path;
2021
import java.util.Collection;
2122
import java.util.Collections;
2223
import java.util.List;
2324
import java.util.Map;
25+
import java.util.Properties;
2426
import java.util.stream.Stream;
25-
import javax.xml.parsers.DocumentBuilder;
26-
import javax.xml.parsers.DocumentBuilderFactory;
27-
import okhttp3.OkHttpClient;
28-
import okhttp3.Request;
29-
import okhttp3.Response;
3027
import org.apache.maven.artifact.versioning.ComparableVersion;
3128
import org.apache.maven.execution.ExecutionEvent;
3229
import org.apache.maven.execution.MavenSession;
@@ -38,8 +35,6 @@
3835
import org.junit.jupiter.params.provider.MethodSource;
3936
import org.slf4j.Logger;
4037
import org.slf4j.LoggerFactory;
41-
import org.w3c.dom.Document;
42-
import org.w3c.dom.NodeList;
4338

4439
public class MavenUtilsTest extends AbstractMavenTest {
4540

@@ -481,38 +476,27 @@ private boolean assertGetContainer(ExecutionEvent executionEvent) {
481476
}
482477

483478
private static String getLatestMavenSurefireVersion() {
484-
OkHttpClient client = new OkHttpClient();
485-
Request request =
486-
new Request.Builder()
487-
.url(
488-
"https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/maven-metadata.xml")
489-
.build();
490-
try (Response response = client.newCall(request).execute()) {
491-
if (response.isSuccessful()) {
492-
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
493-
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
494-
Document doc = dBuilder.parse(response.body().byteStream());
495-
doc.getDocumentElement().normalize();
496-
497-
NodeList versionList = doc.getElementsByTagName("latest");
498-
if (versionList.getLength() > 0) {
499-
String version = versionList.item(0).getTextContent();
500-
if (!version.contains("alpha") && !version.contains("beta")) {
501-
LOGGER.info("Will run the 'latest' tests with version {}", version);
502-
return version;
503-
}
504-
}
505-
} else {
506-
LOGGER.warn(
507-
"Could not get latest Maven Surefire version, response from repo.maven.apache.org is {}:{}",
508-
response.code(),
509-
response.body().string());
479+
// The pinned value is bumped on a schedule by the update-smoke-test-latest-versions workflow.
480+
// See latest-tool-versions.properties.
481+
String version = loadLatestToolVersions().getProperty("maven-surefire.latest");
482+
LOGGER.info("Will run the 'latest' tests with Maven Surefire version {}", version);
483+
return version;
484+
}
485+
486+
private static Properties loadLatestToolVersions() {
487+
Properties properties = new Properties();
488+
try (InputStream stream =
489+
MavenUtilsTest.class
490+
.getClassLoader()
491+
.getResourceAsStream("latest-tool-versions.properties")) {
492+
if (stream == null) {
493+
throw new IllegalStateException(
494+
"Could not find latest-tool-versions.properties on classpath");
510495
}
511-
} catch (Exception e) {
512-
LOGGER.warn("Could not get latest Maven Surefire version", e);
496+
properties.load(stream);
497+
} catch (IOException e) {
498+
throw new RuntimeException(e);
513499
}
514-
String hardcodedLatestVersion = "3.5.0"; // latest version that is known to work
515-
LOGGER.info("Will run the 'latest' tests with hard-coded version {}", hardcodedLatestVersion);
516-
return hardcodedLatestVersion;
500+
return properties;
517501
}
518502
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Pinned latest eligible stable version (>=48h old) for the Maven instrumentation latestDepTest.
2+
# Updated automatically by the update-smoke-test-latest-versions workflow.
3+
maven-surefire.latest=3.5.5

0 commit comments

Comments
 (0)