Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Dynamic Versioning SCM plugin #1082

Conversation

jimisola
Copy link
Contributor

@jimisola jimisola commented May 27, 2024

Adds dynamic versioning based on SCM tag (git supported for now). This plugin goal differs from other Versions Maven Plugin goals since it does not change the pom.xml but simply updates project.version in-memory during execution.

Closes: #1071

@jimisola jimisola force-pushed the feature/add_maven_ci_friendly_versions_goal branch from d2fad86 to bb1bbea Compare May 27, 2024 23:04
@jimisola
Copy link
Contributor Author

@slawekjaranowski I suddenly keep getting:

$mvn verify -P run-its -pl versions-maven-plugin -DskipTests -Dinvoker.test=it-ci-friendly-versions-001

 [INFO] --- animal-sniffer:1.23:check (check-java18) @ versions-maven-plugin ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java18:1.0
[ERROR] /home/jimisola/cloud/dev/clones/jimisola/github/versions/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java: Field ruleSet: Undefined reference: RuleSet
[ERROR] /home/jimisola/cloud/dev/clones/jimisola/github/versions/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java: Field ruleSet: Undefined reference: RuleSet

Not sure how this build is setup but tried rebuilding all the modules from root with a simple mvn clean install.
However, the RuleSet is missing. Must a do something separate to create the RuleSet class using MODELLO?

@lfvjimisola
Copy link
Contributor

Fully implemented and it pass with:

mvn verify -P run-its -pl versions-maven-plugin -DskipTests -Dinvoker.test=it-ci-friendly-versions-*

Will squash commits later and change to ready.

@slawekjaranowski How does it look?

@jimisola jimisola force-pushed the feature/add_maven_ci_friendly_versions_goal branch 4 times, most recently from 382164d to 90ac453 Compare May 28, 2024 22:01
@jimisola jimisola marked this pull request as ready for review May 28, 2024 22:05
@jimisola jimisola changed the title feat: Add maven ci friendly versions goal feat: Add Dynamic Versioning SCM plugin May 28, 2024
@jimisola jimisola marked this pull request as draft May 28, 2024 22:15
@jimisola jimisola force-pushed the feature/add_maven_ci_friendly_versions_goal branch from be1810a to 149dcad Compare May 28, 2024 22:40
@jimisola jimisola marked this pull request as ready for review May 28, 2024 22:40
Comment on lines 46 to 52
* Maven plugin that uses SCM/VCS to enable dynamic versioning based on your
* version control system.
*
* @author Jimisola Laursen
* @since 2.17.0
*/
@Mojo(name = "set-version-from-scm-tag", defaultPhase = LifecyclePhase.INITIALIZE)
Copy link
Member

Choose a reason for hiding this comment

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

This goal only discover version based on SCM and set project property with it ...

Most of goals of this plugin manipulate project pom to update it according to goal.

We need to think about name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I'm all ears about the name of the goal as long as the functionality is there. What are your thoughts about the name?

Copy link
Contributor

Choose a reason for hiding this comment

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

@slawekjaranowski Do you have a suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Brainstorming here, but the key elements to get in the goal are at least:

  1. updates project.version in-memory (dynamic)
  2. sets version based on tag in scm

Is there another word that set that would indicate that the pom.xml itself is left untouched?

The best I can come up with now are:

  • use-dynamic-version-from-scm: execution will use but not set version
  • impersonate-dynamic-version-from-scm: sadly, inversionate is not a word ;)

Copy link
Member

Choose a reason for hiding this comment

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

use-dynamic-version-from-scm look ok for me 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Let's go with use-dynamic-version-from-scm then.

@lfvjimisola
Copy link
Contributor

@slawekjaranowski Would it be possible for us to get this moving so that it can be merged to main before the next release?

@slawekjaranowski slawekjaranowski self-assigned this Jun 11, 2024
@slawekjaranowski
Copy link
Member

please:

  • check output of build
  • rebase with current master branch

@jimisola jimisola force-pushed the feature/add_maven_ci_friendly_versions_goal branch from a450087 to 72cc356 Compare June 15, 2024 12:16
@jimisola
Copy link
Contributor Author

please:

  • check output of build

Not sure that I'm following. After rebase, I ran mvn verify -P run-its -pl versions-maven-plugin with BUILD SUCCESS - if that was it. Can you please explain further if that is not what you where asking?

  • rebase with current master branch

Should be done now.

@slawekjaranowski
Copy link
Member

please:

  • check output of build

Not sure that I'm following. After rebase, I ran mvn verify -P run-its -pl versions-maven-plugin with BUILD SUCCESS - if that was it. Can you please explain further if that is not what you where asking?

Pleas look at https://github.com/mojohaus/versions/actions/runs/9527983742/job/26266186230

Please also rebuild whole project mvn verify -P run-its to be sure

@lfvjimisola lfvjimisola force-pushed the feature/add_maven_ci_friendly_versions_goal branch 5 times, most recently from 61bf8ee to db8fd01 Compare June 17, 2024 14:33
@jimisola
Copy link
Contributor Author

mvn verify -P run-its

Fixed.

@slawekjaranowski
Copy link
Member

On CI we don't have a git configuration for user

from build log:

Running post-build script: /home/runner/work/versions/versions/versions-maven-plugin/target/it/it-dynamic-versioning-scm-tag-latest-commit/verify.groovy
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

So pease set git user in verify scripts ... without --global, or add env GIT_AUTHOR_NAME , GIT_AUTHOR_EMAIL to invoker.properties
https://maven.apache.org/plugins/maven-invoker-plugin/run-mojo.html#invokerPropertiesFile

@lfvjimisola
Copy link
Contributor

I can't get it to work with neither environment variables in invoker.properties or git config commands in setup script (you wrote verify, but you meant setup right?). I could have understood if the environment variables were set in a different shell (scope) and not available later on but even when I set git config locally and see that they're set it's not picked up by git .

If is set it globally then it works.

Any ideas?

invoker.environmentVariables.GIT_AUTHOR_NAME=User Example
invoker.environmentVariables.GIT_AUTHOR_EMAIL=user@example.com
invoker.environmentVariables.GIT_DEFAULT_BRANCH=main
[...]
exec('git config init.defaultBranch "main"')
exec('git config user.email "user@example.com"')
exec('git config user.name "User Example"')

exec('git config --list --local')

exec('git init')
exec('git add test.txt')
exec('git commit -m initial-commit')

[...]

As you can see below default branch, email and name are shown using git config --list --local, but git init does not pick it up and nor does git commit....

Running selector script: /home/u30576/dev/clones/github/jimisola/versions/versions-maven-plugin/target/it/it-dynamic-versioning-scm-tag-4-commits-1-vtag/selector.groovy
git version 2.45.2
Finished selector script: /home/u30576/dev/clones/github/jimisola/versions/versions-maven-plugin/target/it/it-dynamic-versioning-scm-tag-4-commits-1-vtag/selector.groovy
Running pre-build script: /home/u30576/dev/clones/github/jimisola/versions/versions-maven-plugin/target/it/it-dynamic-versioning-scm-tag-4-commits-1-vtag/setup.groovy
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/jimisola/versions.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
remote.upstream.url=https://github.com/mojohaus/versions.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
branch.feature/add_maven_ci_friendly_versions_goal.remote=origin
branch.feature/add_maven_ci_friendly_versions_goal.merge=refs/heads/feature/add_maven_ci_friendly_versions_goal
branch.feature/add_maven_ci_friendly_versions_goal.github-pr-owner-number=mojohaus#versions#1082
init.defaultbranch=main[user]
init.email=user@example.com
init.name=User Example
hint: Using 'master' as the name for the initial branch. This default branch name
Initialized empty Git repository in /home/u30576/dev/clones/github/jimisola/versions/versions-maven-plugin/target/it/it-dynamic-versioning-scm-tag-4-commits-1-vtag/.git/
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m <name>
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'name@hostname.(none)')
java.lang.AssertionError: Command 'git commit -m initial-commit' returned status: 128. Expression: (proc.exitValue() == 0)

@lfvjimisola
Copy link
Contributor

lfvjimisola commented Jun 18, 2024

Running relevant git commands in setup.py as follows works:

exec('git -c user.email="user@example.com" -c user.name="User" commit -m initial-commit')

but it's really annoying having to submit it for each command.

Please advise if that is a workaround we can use.

@slawekjaranowski
Copy link
Member

@lfvjimisola - ups ... my fault environment set in invoker.properties are available during test plugin execution
scripts like setup, verify are execute in context of current Maven session build
so we need to add in setup.groovy

git config user.email "you@example.com"

@lfvjimisola
Copy link
Contributor

@lfvjimisola - ups ... my fault environment set in invoker.properties are available during test plugin execution scripts like setup, verify are execute in context of current Maven session build so we need to add in setup.groovy

git config user.email "you@example.com"

I wrote above you reply that it does not work for me in setup.groovy with exec('git config user.name "User Example"').

It works if:

  1. -global is used with git config
  2. user email and password is set explicitly with each command, i.e. exec('git -c user.email="user@example.com" -c user.name="User" commit -m initial-commit')

@jimisola
Copy link
Contributor Author

I just realized when I saw your commits that I might have executed git config prior to git init 🙄

Copy link
Member

@slawekjaranowski slawekjaranowski left a comment

Choose a reason for hiding this comment

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

We should add goal to list at page: https://www.mojohaus.org/versions/versions-maven-plugin/index.html

We can also add en example page with examples - what version will be set according to git repo content.

@slawekjaranowski slawekjaranowski added this to the 2.17.0 milestone Jun 21, 2024
@slawekjaranowski slawekjaranowski force-pushed the feature/add_maven_ci_friendly_versions_goal branch from 74909ce to 8fb2a24 Compare June 22, 2024 10:46
@slawekjaranowski
Copy link
Member

ok, looks good enough

open questions:

  • goal name
  • documentation - for it I will accept a separate PR

@jimisola jimisola force-pushed the feature/add_maven_ci_friendly_versions_goal branch from 5eee8dc to 49ef3f7 Compare June 22, 2024 17:15
@jimisola jimisola force-pushed the feature/add_maven_ci_friendly_versions_goal branch from 9fa2645 to 3dc48bf Compare June 22, 2024 18:20
@jimisola
Copy link
Contributor Author

  • Renamed goal to use-dynamic-version-from-scm
  • Added docs

FYI, there is a discrepancy between the goals listed in

https://www.mojohaus.org/versions/versions-maven-plugin/#goals-overview and https://www.mojohaus.org/versions/versions-maven-plugin/plugin-info.html

Is there a reason why Single Source of Truth (SSOT) and only the auto-generated list is used?
I understand that there a normal goals and reporting goals, but does there have to be a manually generated list to list them? Wouldn't it be enough to just refer to Goals page and clarify that there are different types of goals ("normal" and reporting)?

@slawekjaranowski
Copy link
Member

Is there a reason why Single Source of Truth (SSOT) and only the auto-generated list is used? I understand that there a normal goals and reporting goals, but does there have to be a manually generated list to list them? Wouldn't it be enough to just refer to Goals page and clarify that there are different types of goals ("normal" and reporting)?

You right you can think about to drop manual docs at all in order to use generated one.

@slawekjaranowski slawekjaranowski merged commit d2550ba into mojohaus:master Jun 25, 2024
20 checks passed
@lfvjimisola
Copy link
Contributor

Thank you @slawekjaranowski

@slawekjaranowski
Copy link
Member

@lfvjimisola thanks also for contributing - I will release next version in a few days

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.

Add goal that works with Maven CI Friendly Versions and set property (revision) based on git tag
3 participants