From a2fbe0d50facd3497a7c4f55a4df055b8246258b Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Thu, 1 Feb 2024 20:39:38 +0100 Subject: [PATCH] ci dep checker: filter pre-releases and sort by version --- .github/scripts/BinariesListUpdates.java | 24 +++++++++++++++++++----- .github/workflows/dependency-checks.yml | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/scripts/BinariesListUpdates.java b/.github/scripts/BinariesListUpdates.java index 5b1b209fa814..6a64515f5ee3 100644 --- a/.github/scripts/BinariesListUpdates.java +++ b/.github/scripts/BinariesListUpdates.java @@ -20,13 +20,13 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.List; import java.util.concurrent.Semaphore; +import java.util.concurrent.atomic.LongAdder; import java.util.stream.Stream; -import org.apache.maven.search.api.Record; import org.apache.maven.search.api.SearchRequest; import org.apache.maven.search.backend.smo.SmoSearchBackend; import org.apache.maven.search.backend.smo.SmoSearchBackendFactory; +import org.apache.maven.artifact.versioning.ComparableVersion; import static java.util.FormatProcessor.FMT; import static org.apache.maven.search.api.MAVEN.ARTIFACT_ID; @@ -45,6 +45,10 @@ */ public class BinariesListUpdates { + private static final LongAdder updates = new LongAdder(); + private static final LongAdder checks = new LongAdder(); + private static final LongAdder skips = new LongAdder(); + // java --enable-preview --source 22 --class-path "lib/*" BinariesListUpdates.java /path/to/netbeans/project public static void main(String[] args) throws IOException, InterruptedException { @@ -63,6 +67,8 @@ public static void main(String[] args) throws IOException, InterruptedException } }); } + + System.out.println(STR."checked \{checks.sum()} dependencies, found \{updates.sum()} updates, skipped \{skips.sum()}." ); } private static void checkDependencies(Path path, SmoSearchBackend backend) throws IOException, InterruptedException { @@ -91,15 +97,18 @@ private static void checkDependencies(Path path, SmoSearchBackend backend) throw latest = queryLatestVersion(backend, gid, aid, classifier.split("@")[0]); gac = String.join(":", gid, aid, classifier); } - if (!version.equals(latest)) { + if (latest != null && !version.equals(latest)) { System.out.println(FMT." %-50s\{gac} \{version} -> \{latest}"); + updates.increment(); } } catch (IOException | InterruptedException ex) { throw new RuntimeException(ex); } } else { System.out.println(" skip: '"+l+"'"); + skips.increment(); } + checks.increment(); }); } System.out.println(); @@ -119,8 +128,13 @@ private static String queryLatestVersion(SmoSearchBackend backend, String gid, S private static String queryLatestVersion(SmoSearchBackend backend, SearchRequest request) throws IOException, InterruptedException { requests.acquire(); try { - List result = backend.search(request).getPage(); - return !result.isEmpty() ? result.getFirst().getValue(VERSION) : null; + return backend.search(request).getPage().stream() + .map(r -> r.getValue(VERSION)) + .filter(v -> !v.contains("alpha") && !v.contains("beta")) + .filter(v -> !v.contains("M") && !v.contains("m") && !v.contains("B") && !v.contains("b") && !v.contains("ea")) + .limit(5) + .max((v1, v2) -> new ComparableVersion(v1).compareTo(new ComparableVersion(v2))) + .orElse(null); } finally { requests.release(); } diff --git a/.github/workflows/dependency-checks.yml b/.github/workflows/dependency-checks.yml index 9f0c4d1efffb..dcf5fdc41ac1 100644 --- a/.github/workflows/dependency-checks.yml +++ b/.github/workflows/dependency-checks.yml @@ -54,10 +54,10 @@ jobs: - name: Check Dependencies run: | - mvn -q dependency:get -Dartifact=org.apache.maven.indexer:search-backend-smo:7.1.1 mvn -q dependency:copy -Dartifact=org.apache.maven.indexer:search-backend-smo:7.1.1 -DoutputDirectory=./lib mvn -q dependency:copy -Dartifact=org.apache.maven.indexer:search-api:7.1.1 -DoutputDirectory=./lib mvn -q dependency:copy -Dartifact=com.google.code.gson:gson:2.10.1 -DoutputDirectory=./lib + mvn -q dependency:copy -Dartifact=org.apache.maven:maven-artifact:3.9.6 -DoutputDirectory=./lib echo "
" >> $GITHUB_STEP_SUMMARY
           java --enable-preview --source 22 -cp "lib/*" .github/scripts/BinariesListUpdates.java ./ | tee -a $GITHUB_STEP_SUMMARY
           echo "
" >> $GITHUB_STEP_SUMMARY