Skip to content

[MNG-8685] Better support for CI systems#2254

Merged
cstamas merged 25 commits intoapache:masterfrom
cstamas:MNG-8685
Apr 13, 2025
Merged

[MNG-8685] Better support for CI systems#2254
cstamas merged 25 commits intoapache:masterfrom
cstamas:MNG-8685

Conversation

@cstamas
Copy link
Member

@cstamas cstamas commented Apr 11, 2025

Improve CI detection of Maven, make possible to propagate some options from CI to Maven.

Changes:

  • InvokerRequest carries new info: Optional<CIInfo>: if present, we run on CI, if empty, not.
  • Parser (creating InvokerRequest) already inspects env and assembles invoker request, so make it detect CI as well
  • CIDetector is a Java Service (this all happens early, no DI yet) that can be extended (like adding CI specific detectors). Core had one implementation that became the "generic" that is what Maven 4 had so far.
  • Added "jenkins", "github", "teamcity", "circle" and "travis" support.

https://issues.apache.org/jira/browse/MNG-8685

@cstamas
Copy link
Member Author

cstamas commented Apr 11, 2025

Fun fact: all 3 failing ITs tries to "escape" from CI env by setting CI=false, but alas, it does not work anymore, as GithubCIDetector kicks in.

@cstamas cstamas marked this pull request as ready for review April 11, 2025 19:02
@cstamas cstamas requested a review from pzygielo April 11, 2025 19:03
@cstamas cstamas added this to the 4.0.0-rc-4 milestone Apr 11, 2025
public static List<CIInfo> detectCI() {
List<CIDetector> detectors = ServiceLoader.load(CIDetector.class).stream()
.map(ServiceLoader.Provider::get)
.toList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not continue with this stream to get List<CIInfo> and get rid of the loop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

.map(CIDetector::detectCI)
.filter(Optional::isPresent)
.map(Optional::get)
.toList());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Stream.html#toList():

The returned List is unmodifiable

so not sure about removeIf later.

Maybe Collectors.toCollection(ArrayList::new)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is fine, this happens "on boot", is not some sort of "hot" spot. The reason why I remove "generic" if there are 2 or more is that I assume there is more specific hit (like GH, sets CI=true but also sets GITHUB_RUNNER=true)... we can refine this later anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, to keep things simple I don't want to fiddle with order, as other solution would be to test all, and THEN as last, if no hit, "generic"... but that would assume there is no (and never will be) overlap between all CI systems, which IMO we never know and cannot know (future wise).

@cstamas cstamas merged commit b1466d8 into apache:master Apr 13, 2025
1 check passed
@cstamas cstamas deleted the MNG-8685 branch April 13, 2025 18:50
@ledoyen
Copy link

ledoyen commented Apr 15, 2025

Hello @cstamas, thank you for your great work on this 🙏.

I am not familiar with the release process of Maven, is this change planned for Maven 3.10 and Maven 4, or solely for Maven 4?

In case of the later, is it ok if I backport your work on maven-3.x-next (I think this is the one)?

@cstamas
Copy link
Member Author

cstamas commented Apr 15, 2025

This change went into the master cli module, so will be out as 4.0.0-rc-4 (next planned release). You can try backport it if you want, and I can help with that, but it will not be a simple thing (like just apply patches). The whole cli was redone in 4...

@cstamas
Copy link
Member Author

cstamas commented Apr 16, 2025

In short, for mvn3 I'd envision some PR that is more close to your original PR (and adds verbose support for those that support it: GH and Travis IIRC?)

@jira-importer
Copy link

Resolve #9622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants