mojohaus / versions

Versions Maven Plugin
https://www.mojohaus.org/versions/versions-maven-plugin/
Apache License 2.0
327 stars 265 forks source link

feat: Add Dynamic Versioning SCM plugin #1082

Closed jimisola closed 3 days ago

jimisola commented 1 month ago

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: https://github.com/mojohaus/versions/issues/1071

jimisola commented 1 month ago

@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 commented 1 month ago

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?

lfvjimisola commented 2 weeks ago

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

slawekjaranowski commented 2 weeks ago

please:

jimisola commented 2 weeks ago

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 commented 1 week ago

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

jimisola commented 1 week ago

mvn verify -P run-its

Fixed.

slawekjaranowski commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

@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 commented 1 week ago

@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 commented 1 week ago

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

slawekjaranowski commented 1 week ago

ok, looks good enough

open questions:

jimisola commented 6 days ago

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 commented 3 days ago

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.

lfvjimisola commented 3 days ago

Thank you @slawekjaranowski

slawekjaranowski commented 3 days ago

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