Automatic batch-mode activation in popular CI environments

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatic batch-mode activation in popular CI environments

Martin Kanters
Hi all,

When setting up GitHub Actions for Maven (core) two weeks ago, I initially
forgot to enable the -B/--batch-mode flag.
While this gave no issues and was easy to fix, it could be avoided by
detecting if Maven is executed on popular CI environments and in that case
automatically enabling batch mode.
Popular CI tools such as GitHub Actions [1] and GitLab CI [2] provide
predefined environment variables, which could be used for this purpose.
When this would automatically activate, we log this on INFO level. We would
also need an option to turn batch-mode off to override this automatic
behavior.

The reason why I haven't created a JIRA issue yet is because I realize I do
not know if this fits the usual workings for Maven.
Based on best guesses (de-)activating certain functionality can in my
vision be a quality-of-life improvement for our users.
On the other hand I have the feeling currently Maven does favor users to
explicitly set their CLI flags.
Just wanted to know your opinion. If I get positive feedback I will create
a JIRA issue.
Otherwise we can consider alternatives (only log a hint: "CI run detected,
did you want to run in --batch-mode?") or leave it like it is.

Thanks,
Martin

[1]
https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
[2] https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
Reply | Threaded
Open this post in threaded view
|

Re: Automatic batch-mode activation in popular CI environments

michaelo
Am 2020-07-12 um 17:42 schrieb Martin Kanters:

> Hi all,
>
> When setting up GitHub Actions for Maven (core) two weeks ago, I initially
> forgot to enable the -B/--batch-mode flag.
> While this gave no issues and was easy to fix, it could be avoided by
> detecting if Maven is executed on popular CI environments and in that case
> automatically enabling batch mode.
> Popular CI tools such as GitHub Actions [1] and GitLab CI [2] provide
> predefined environment variables, which could be used for this purpose.
> When this would automatically activate, we log this on INFO level. We would
> also need an option to turn batch-mode off to override this automatic
> behavior.
>
> The reason why I haven't created a JIRA issue yet is because I realize I do
> not know if this fits the usual workings for Maven.
> Based on best guesses (de-)activating certain functionality can in my
> vision be a quality-of-life improvement for our users.
> On the other hand I have the feeling currently Maven does favor users to
> explicitly set their CLI flags.
> Just wanted to know your opinion. If I get positive feedback I will create
> a JIRA issue.
> Otherwise we can consider alternatives (only log a hint: "CI run detected,
> did you want to run in --batch-mode?") or leave it like it is.

So, I consider explicitly adding zillions of CI support is the wrong way
to go. We need to be agnostic just like we are IDE-agnostic.
What you are basically looking for is just like in Subversion:
>   --non-interactive        : do no interactive prompting (default is to prompt
>                              only if standard input is a terminal device)
>   --force-interactive      : do interactive prompting even if standard input
>                              is not a terminal device

by default Subversion will try to determine both. You need native code
here to determine whether stdout/stdin is attached to a terminal. There
you will have your auto detection. Java's Console is supposed to do
this, but is is too limited.
Luckily, we do have Jansi in tree which provides use with:
POSIX:
https://github.com/fusesource/jansi-native/blob/master/src/main/java/org/fusesource/jansi/internal/CLibrary.java#L74-L76
Windows:
https://github.com/fusesource/jansi-native/blob/master/src/main/java/org/fusesource/jansi/internal/WindowsSupport.java#L49-L57

This is what you are looking for.

Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Automatic batch-mode activation in popular CI environments

michaelo
Am 2020-07-12 um 21:35 schrieb Maarten Mulders:
> Although no formal standards, many cloud-based CI environments agreed
> upon setting CI=true, and I think also Jenkins does that. It might be a
> relatively simple way to detect most CI environments.
>
> The next question is what Maven should do with that information. I feel
> like informing the user is more in the Maven spirit (just as the fact
> that 3.7.0 warns when plugin versions aren't locked). Something like
> "you typically want to set -B in this case". Setting flags the user
> isn't aware of feels a bit odd to me.

Don't limit your mind to CI only, please.
Here is the most basic use case for isatty() detection:
$ mvn ... > out
$ mvn ... | grep foo

If nothing passed, the system shall assume --non-interactive.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]