Skip to content

Commit

Permalink
ci dep checker: filter pre-releases and sort by version
Browse files Browse the repository at this point in the history
  • Loading branch information
mbien committed Feb 1, 2024
1 parent 805b153 commit a2fbe0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions .github/scripts/BinariesListUpdates.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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<Record> 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();
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<pre>" >> $GITHUB_STEP_SUMMARY
java --enable-preview --source 22 -cp "lib/*" .github/scripts/BinariesListUpdates.java ./ | tee -a $GITHUB_STEP_SUMMARY
echo "</pre>" >> $GITHUB_STEP_SUMMARY
Expand Down

0 comments on commit a2fbe0d

Please sign in to comment.