Coder Social home page Coder Social logo

jmongard / git.semversioning.gradle Goto Github PK

View Code? Open in Web Editor NEW
38.0 3.0 4.0 431 KB

Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages.

Home Page: https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin

License: Apache License 2.0

Kotlin 100.00%
semantic semver gradle conventional-commits versioning git change-log changelog

git.semversioning.gradle's People

Contributors

jmongard avatar sschuberth avatar tacascer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

git.semversioning.gradle's Issues

`-PnoDirtyCheck=true` no longer works

It seems that -PnoDirtyCheck=true is no longer being honored by the releaseVersion task.

A short investigation shows that the task defaults the property to false here.

The only manipulation of the field I can find is here.

It seems that the property is not being passed down from the settings object passed in.

Add support for a `FOOTER` section

Similar to HEADER, support for a free-text FOOTER (which is empty by default) would be nice, e.g. to add optional notes to a release.

Running Two Gradle Tasks Simultaneously on the Same Command Line

I am attempting to run two Gradle tasks on the same command line, using the following command:

./gradlew releaseVersion build

However, when executing the releaseVersion and build tasks together, I noticed that the build version does not reflect the version of the tag/commit generated by the releaseVersion task. I suspect this might be related to Gradle's lifecycle, where configuration tasks are executed only once. It seems the plugin calculates the version and assigns it to a lazy property.

I executed Gradle without parallel mode enabled and also tried applying the mustRunAfter configuration on the build task, specifying that it should run after releaseVersion.

Is this behavior expected? Shouldn't there be an update to the version property after the releaseVersion task execution?

I managed to synchronize the build version with what would be generated after the version tag/commit by including the parameter -PdefaultPreRelease=

semver {} config block does not work

since 0.12.0 the semver {} config block does not seem to work. I tested with the following and the settings had no effect. 0.11.0 works.

semver {
	defaultPreRelease = "PRE"
	noDirtyCheck = true
}

version = semver.version

How to get current release version?

Hello,

I'm trying to implement the following: all the commits into main branch should lead to a release and should be published into a maven repository with the correct version in its name, e.g. mylib-1.0.0.jar

Currently releaseVersion task seems to just create a tag and then all the accesses to semver.version will return next version and not the current/release one, even if HEAD points to a release commit.

Using this plugin I'd like to achieve the following

# show next version
./gradlew printVersion
Version: 1.0.0-SNAPSHOT+002.sha.7391461

# create a release tag and release commit
./gradlew releaseVersion 

# build an artifact
./gradlew build

# show an artifact and expect it to have released version 1.0.0
ls -l target/libs
total 248
-rw-r--r--  1 user  staff  33510 Nov 20 17:54 mylib-1.0.1-SNAPSHOT.jar

Could you please help me to understand how to use this plugin to be able to create artifacts with the release version in their names or could you please add an option so that semver.version returns release version in case HEAD points to a release commit?

Getting Stackoverflow with large multi-module repo

Getting stackoverflow in large multi-module repo:

Caused by: java.lang.StackOverflowError at org.eclipse.jgit.internal.storage.file.PackFile.readFully(PackFile.java:614) at org.eclipse.jgit.internal.storage.file.PackFile.load(PackFile.java:797) at org.eclipse.jgit.internal.storage.file.PackFile.get(PackFile.java:284) at org.eclipse.jgit.internal.storage.file.ObjectDirectory.openPackedObject(ObjectDirectory.java:455) at org.eclipse.jgit.internal.storage.file.ObjectDirectory.openPackedFromSelfOrAlternate(ObjectDirectory.java:413) at org.eclipse.jgit.internal.storage.file.ObjectDirectory.openObject(ObjectDirectory.java:404) at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:132) at org.eclipse.jgit.revwalk.RevWalk.getCachedBytes(RevWalk.java:961) at org.eclipse.jgit.revwalk.RevCommit.parseHeaders(RevCommit.java:126) at org.eclipse.jgit.revwalk.RevWalk.parseHeaders(RevWalk.java:1074) at git.semver.plugin.scm.GitProvider$getCommit$1.invokeSuspend(GitProvider.kt:117) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlin.sequences.SequenceBuilderIterator.hasNext(SequenceBuilder.kt:140) at kotlin.sequences.TransformingSequence$iterator$1.hasNext(Sequences.kt:214) at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:169) at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194) at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:752) at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:782) at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:773) at git.semver.plugin.semver.VersionFinder.getSemVersion(VersionFinder.kt:49) at git.semver.plugin.semver.VersionFinder.access$getSemVersion(VersionFinder.kt:7) at git.semver.plugin.semver.VersionFinder$getSemVersion$parentSemVersions$1.invoke(VersionFinder.kt:49) at git.semver.plugin.semver.VersionFinder$getSemVersion$parentSemVersions$1.invoke(VersionFinder.kt:7) at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210) at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:170) at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194) at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:752) at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:782) at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:773) at git.semver.plugin.semver.VersionFinder.getSemVersion(VersionFinder.kt:49) at git.semver.plugin.semver.VersionFinder.access$getSemVersion(VersionFinder.kt:7) at git.semver.plugin.semver.VersionFinder$getSemVersion$parentSemVersions$1.invoke(VersionFinder.kt:49) at git.semver.plugin.semver.VersionFinder$getSemVersion$parentSemVersions$1.invoke(VersionFinder.kt:7) at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210) at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:170) at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194) at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:752) at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:782) at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:773)

The setup:

build.gradle:

`plugins {
id 'java-platform'
id "org.sonarqube" version "3.1.1"
id "com.diffplug.spotless" version "5.11.0"
id "maven-publish"
id "com.jfrog.artifactory"
id "com.github.jmongard.git-semver-plugin" version "0.3.0"
}

apply from: "$rootDir/sonarqube.gradle"

javaPlatform {
allowDependencies()
}

dependencies {
api platform('com.amazonaws:aws-java-sdk-bom:1.11.534')
api platform('org.springframework:spring-framework-bom:3.2.17.RELEASE')

constraints {
    api projects.hscsGuidelines
    api projects.hscsAcres
    api projects.hscsAncillary
    api projects.hscsCommon
    api projects.hscsJournalMedlineMatch
    api projects.hscsMl
    api projects.hscsBooks
    api projects.hscsBooksandjournals
    api projects.hscsEdms
    api projects.hscsEsMt
    api projects.hscsFirstconsult
    api projects.hscsPg
    api projects.hscsNice
    api projects.hscsPeGoldStandard
    api projects.hscsPgec
    api projects.hscsPgsy
    api projects.hscsWorkflowManager
    api projects.hscsJournals
    api projects.hscsEwjournals
    api projects.hscsCt
    api projects.hscsDt
    api projects.hscsEpg
    api projects.hscsMosbyskills
    api projects.hscsHas
    api projects.hscsAuDmStatic
    api projects.hscsEmc
    api projects.hscsBnf
    api projects.hscsGenericIngestion
    api projects.hscsAuDm
    api projects.hscsYearBookMatch
    api projects.hscsEmrIngestionManager
    api projects.hscsCalculators
    api projects.hscsEabstract
    api projects.hscsFrDm
    api projects.hscsErrataMatch
    api projects.hscsEwbooks
    api projects.hscsIngestionManager
    api projects.hscsPgBreak
    api projects.hscsDcos
    api projects.hscsEw

    api 'cglib:cglib:2.2.2'

    api 'com.github.jsonld-java:jsonld-java:0.13.0'
    api 'com.github.stefanbirkner:fake-sftp-server-rule:2.0.1'
    api 'com.thoughtworks.xstream:xstream:1.4.2'
    api 'commons-beanutils:commons-beanutils:1.8.0'
    api 'commons-io:commons-io:2.6'
    api 'commons-lang:commons-lang:2.6'
    api 'commons-validator:commons-validator:1.4.0'
    api 'dom4j:dom4j:1.6.1'
    api 'net.sourceforge.collections:collections-generic:4.01'
    api 'org.apache.commons:commons-collections4:4.1'
    api 'commons-collections:commons-collections:3.2.2'
    api 'org.apache.commons:commons-compress:1.9'
    api 'org.apache.commons:commons-csv:1.2'
    api 'org.apache.commons:commons-lang3:3.4'
    api 'org.apache.hadoop:hadoop-core:1.0.3-mapr-4.0.2'
    api 'org.apache.lucene:lucene-analyzers:3.2.0'
    api 'org.apache.poi:poi-ooxml:3.9'
    api 'org.slf4j:slf4j-api:1.7.30'
    api 'org.codehaus.castor:castor-xml:1.4.1'

// api 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
api 'org.easymock:easymock:3.1'
api 'org.hamcrest:hamcrest-all:1.3'
api 'org.hsqldb:hsqldb-j5:2.2.4'
api 'org.hibernate:hibernate-core:4.1.4.Final'
api 'org.javassist:javassist:3.27.0-GA'
api 'org.jdom:jdom:1.1'
api 'org.jdom:jdom2:2.0.6'
api 'org.jsoup:jsoup:1.7.3'
api 'org.mockftpserver:MockFtpServer:2.3'
api 'org.powermock:powermock-api-mockito:1.4.9'
api 'org.powermock:powermock-module-junit4:1.4.9'
api 'org.springframework.ws:spring-ws-core:2.3.0.RELEASE'
api 'org.springframework.ws:spring-ws-test:2.3.0.RELEASE'
api 'xmlunit:xmlunit:1.3'

    runtime 'com.oracle.database.jdbc:ojdbc8:12.2.0.1'
    runtime 'commons-dbcp:commons-dbcp:1.4'
    runtime 'commons-httpclient:commons-httpclient:3.1'
    runtime 'jaxen:jaxen:1.1.6'
    runtime 'org.apache.httpcomponents:httpclient:4.5.9'
    runtime 'org.apache.ws.commons.axiom:axiom-api:1.2.19'
    runtime 'org.apache.ws.commons.axiom:axiom-impl:1.2.19'
    runtime 'org.aspectj:aspectjweaver:1.6.12'
}

}

// Delete sample/stale hooks
delete "$rootDir/.git/hooks"

// If non-CI build, copy fresh hooks in
if (!project.hasProperty("CI")) {
copy {
from "$rootDir/.hooks"
into "$rootDir/.git/hooks"
eachFile { hook ->
logger.info("Copying ${hook.name} to $rootDir/.git/hooks")
}
}
}

defaultTasks 'spotlessApply', 'build'

spotless {
// optional: limit format enforcement to just the files changed by this feature branch
ratchetFrom 'origin/master'

format 'misc', {
    target '*.md', '.gitignore', "*.gradle"
    trimTrailingWhitespace()
    indentWithSpaces()
    endWithNewline()
}
java {
    target '**/*.java'
    targetExclude 'buildSrc/**', '**/src/generated/java/** q'
    googleJavaFormat()
    removeUnusedImports()
}
groovy {
    target "*.groovy", "Jenkinsfile"
    greclipse()
}

}

publishing {
publications {
maven(MavenPublication) {
from components.javaPlatform
}
}
}

artifactory {
contextUrl =
publish {
repository {
repoKey = 'maven-clinicalkey-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
}
defaults {
publications('maven')
publishIvy = false
}
}
}

allprojects {
Need this to publish the correct version
version = semver.version
println "${it.name} --> $version"

releaseVersion.dependsOn build
artifactoryPublish.dependsOn releaseVersion

}
`

settings.gradle:
`
/*

  • This file was generated by the Gradle 'init' task.
    */
    enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

rootProject.name = 'hscs-ingestion'
include(':hscs-guidelines')
include(':hscs-acres')
include(':hscs-ancillary')
include(':hscs-common')
include(':hscs-journalMedlineMatch')
include(':hscs-ml')
include(':hscs-books')
include(':hscs-booksandjournals')
include(':hscs-edms')
include(':hscs-es-mt')
include(':hscs-firstconsult')
include(':hscs-pg')
include(':hscs-nice')
include(':hscs-peGoldStandard')
include(':hscs-pgec')
include(':hscs-pgsy')
include(':hscs-workflowManager')
include(':hscs-journals')
include(':hscs-ewjournals')
include(':hscs-ct')
include(':hscs-dt')
include(':hscs-epg')
include(':hscs-mosbyskills')
include(':hscs-has')
include(':hscs-au-dm-static')
include(':hscs-emc')
include(':hscs-bnf')
include(':hscs-genericIngestion')
include(':hscs-au-dm')
include(':hscs-yearBookMatch')
include(':hscs-emrIngestionManager')
include(':hscs-calculators')
include(':hscs-eabstract')
include(':hscs-fr-dm')
include(':hscs-errataMatch')
include(':hscs-ewbooks')
include(':hscs-ingestionManager')
include(':hscs-pgBreak')
include(':hscs-dcos')
include(':hscs-ew')

dependencyResolutionManagement {
repositories {
mavenLocal()
maven {
url = uri()
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
}
`

Ignore auto-version bumping on some commits

Hello,

Is it possible to configure the plugin somehow to ignore version bumping on some commit message patterns?
According to
image
it can be useful to prevent auto-bumping on certain commit types, like the following

docs(scope): improving readme.md
style(scope): reformatting the code

Incorrect versioning when merging between two branches

Assume default semver config and we have two branches: master and develop

master current version is 1.0.0 and develop is a copy of the master branch.

Example 1:

  1. In develop, commit feat: and merge develop into master via PR.
  2. In master, run releaseVersion which will release 1.1.0.
  3. Merge master into develop via PR.
  4. In develop, commit fix: and run printVersion which will show 1.2.0.

In step 4, shouldn't the version print out 1.1.1?

Example 2:

  1. In develop, commit feat!: and merge develop into master via PR.
  2. In master, run releaseVersion which will release 2.0.0.
  3. Merge master into develop via PR.
  4. In develop, commit fix: and run printVersion which will show 3.0.0.

In step 4, shouldn't the version print out 2.0.1?

Issue in pattern matching

I'm currently trying to get the following template to work to update the minor version

The configuration for semver is:

semver {
	defaultPreRelease = "snapshot"
	minorPattern = "^(\\s?)feat(?:\\(\\w+\\))?:"
	patchPattern = "^(\\s?)fix(?:\\(\\w+\\))?:"
}

The commit template I'm trying to match looks like:

TTLFLCT-1

feat: added git-semver-plugin for automatic semantic versioning

The testing:

When I pull your code and try this in the testCommits test in GitProviderTest, then the minor version updates correctly.
So it passes the unit test.

 val gitProvider = GitProvider(SemverSettings().apply {
         groupVersionIncrements = true
         minorPattern = "^(\\s?)feat(?:\\(\\w+\\))?:"
 })
 ...
 commit(it, "TTLFLCT-1\n\nfeat: a feature", gitProvider)

Screen Shot 2021-11-10 at 18 31 07

If I try this in my actual project, then the minor version does not update.

Screen Shot 2021-11-10 at 18 32 53

Screen Shot 2021-11-10 at 18 32 03

This was tested on Mac OS.

printChangeLog configuration causing error

Without printChangeLog configuration, the task is working fine. But with any kind of printChangeLog configuration, it is causing errors. I copied the exact printChangeLog configuration from the docs.

Using the latest plugin version: 0.12.6

Example 1:

build.gradle:

semver {
    groupVersionIncrements = false
}

semver {
    changeLogTexts = PlainChangeLogTexts
}

error:

A problem occurred evaluating root project 'semantic-test'.
> Could not get unknown property 'PlainChangeLogTexts' for extension 'semver' of type git.semver.plugin.gradle.GitSemverPluginExtension.

Example 2:

build.gradle:

semver {
    groupVersionIncrements = false
}

semver {
    changeLogTexts {
        headerTexts = mutableMapOf(
            "fix" to "### Bug Fixes \uD83D\uDC1E",
            "feat" to "### New Features \uD83C\uDF89",
            "test" to "### Tests ✅",
            "docs" to "### Documentation \uD83D\uDCD6",
            "deps" to "### Dependency Updates \uD83D\uDE80",
            "build" to "### Build \uD83D\uDC18 & CI ⚙\uFE0F",
            "ci" to "### Build \uD83D\uDC18 & CI ⚙\uFE0F",
            "chore" to "### Chores \uD83D\uDD27",
            "perf" to "### Performance Enhancements ⚡",
            "refactor" to "### Refactorings \uD83D\uDE9C"
        )
        header = "## What's Changed" // Set your custom header text
        breakingChange = "### Breaking Changes 🛠" // Set your custom breaking change text
        otherChange = "### Other Changes \uD83D\uDCA1" // Set your custom other change text
    }
}

error:

A problem occurred evaluating root project 'semantic-test'.
> No signature of method: java.lang.String.to() is applicable for argument types: (String, String) values: [### Bug Fixes ?, feat] 
  Possible solutions: tr(java.lang.CharSequence, java.lang.CharSequence), trim(), toURI(), md5(), toSet(), toURI()

Make the order of changelog entries configurable

Sometimes it's desirable to list more important changes (like breaking changes) first, before less important changes (like chroes). As such it would be nice to have control over the order of the header sections in the changelog. The easiest way to achieve this would probably be to simply maintain the order of the key in the headerTexts map. As mutableMapOf() creates a LinkedHashMap which maintains insertion-order, that should work.

Use releaseVersion in Github Actions

Hi,

I was wondering, how would you recommend using ./gradlew releaseVersion in a Github Actions worlflow?

I checked the workflow in your project, but it seems you are not using the plugin from the workflow to version the plugin itself.

I tried to define a workflow that would version automatically when a push to master is performed.

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
...
      - name: Retrieve current version number
        run: ./gradlew printVersion

      - name: Update release
        run: |
          ./gradlew releaseVersion

      - name: Push changes
        run: |
          git config --global user.name ${{env.GIT_COMMIT_AUTHOR_NAME}}
          git config --global user.email ${{env.GIT_COMMIT_AUTHOR_EMAIL}}
          git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
          git push origin --all --force
          git push origin --tags
          git tag
          git ls-remote --tags

      - name: Retrieve updated version number
        run: ./gradlew printVersion
...
  publish:
    needs: build
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
...
      - name: Retrieve current version number
        run: |
          ./gradlew printVersion
...

The output shows that before the releaseVersion the output is:

> Task :printVersion
--------------------
Version: 0.0.25-SNAPSHOT+006.sha.a6f4a84

BUILD SUCCESSFUL in 920ms
1 actionable task: 1 executed

And after running the releaseVersion the output is:

> Task :printVersion
--------------------
Version: 0.0.25+sha.1e11c21

BUILD SUCCESSFUL in 983ms
1 actionable task: 1 executed

The commit message release: v0.0.23 is pushed to master, and the release tag is created. Still when I fetch the repository in another job or workflow the printVersion shows the snapshot version with the changes:

> Task :printVersion
--------------------
Version: 0.0.25-SNAPSHOT+006.sha.a6f4a84

BUILD SUCCESSFUL in 10s
1 actionable task: 1 executed

I was hoping that there is a recipe available for using the plugin from within a Github Actions workflow.

Thanks

Incompatibility with Gradle's configuration cache

Since Gradle 8.1 the configuration cache is stable and can be enabled e.g. via --configuration-cache. Doing so with a project that uses this plugin results in

org.gradle.api.InvalidUserCodeException: Starting an external process '/usr/bin/git --version' during configuration time is unsupported.
	at org.gradle.configurationcache.problems.DefaultProblemFactory$problem$1$build$diagnostics$1.get(DefaultProblemFactory.kt:79)
	at org.gradle.configurationcache.problems.DefaultProblemFactory$problem$1$build$diagnostics$1.get(DefaultProblemFactory.kt:79)
	at org.gradle.internal.problems.DefaultProblemDiagnosticsFactory$DefaultProblemStream.getImplicitThrowable(DefaultProblemDiagnosticsFactory.java:147)
	at org.gradle.internal.problems.DefaultProblemDiagnosticsFactory$DefaultProblemStream.forCurrentCaller(DefaultProblemDiagnosticsFactory.java:136)
	at org.gradle.configurationcache.problems.DefaultProblemFactory$problem$1.build(DefaultProblemFactory.kt:79)
	at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onExternalProcessStarted(ConfigurationCacheProblemsListener.kt:98)
	at org.gradle.configurationcache.InstrumentedInputAccessListener.externalProcessStarted(InstrumentedInputAccessListener.kt:111)
	at org.gradle.internal.classpath.Instrumented.externalProcessStarted(Instrumented.java:457)
	at org.gradle.internal.classpath.Instrumented.externalProcessStarted(Instrumented.java:465)
	at org.gradle.internal.classpath.Instrumented.start(Instrumented.java:319)
	at org.eclipse.jgit.util.FS.readPipe(FS.java:1405)
	at org.eclipse.jgit.util.FS.readPipe(FS.java:1367)
	at org.eclipse.jgit.util.FS.discoverGitSystemConfig(FS.java:1556)
	at org.eclipse.jgit.util.FS.getGitSystemConfig(FS.java:1653)
	at org.eclipse.jgit.util.SystemReader$Default.openSystemConfig(SystemReader.java:107)
	at org.eclipse.jgit.util.SystemReader.getSystemConfig(SystemReader.java:379)
	at org.eclipse.jgit.util.SystemReader.getUserConfig(SystemReader.java:327)
	at org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:162)
	at org.eclipse.jgit.lib.BaseRepositoryBuilder.build(BaseRepositoryBuilder.java:627)
	at git.semver.plugin.scm.GitProvider.getRepository(GitProvider.kt:105)
	at git.semver.plugin.scm.GitProvider.getSemVersion$git_semver_plugin(GitProvider.kt:26)
	at git.semver.plugin.gradle.GitSemverPluginExtension$semVersion$2.invoke(GitSemverPluginExtension.kt:14)
	at git.semver.plugin.gradle.GitSemverPluginExtension$semVersion$2.invoke(GitSemverPluginExtension.kt:14)

So the culprit actually is JGit, which falls back to calling the git CLI to find the Git system configuration. This can be worked around by setting the GIT_CONFIG_NOSYSTEM environment variable, but this is a bit cumbersome to do from inside a Gradle build, see e.g. the solution at oss-review-toolkit/ort@9a0c0b1.

Another solution as mentioned in the commit linked above is to use a Gradle ValueSource. This is the approach I've implemented in the smae project as linked above later, see oss-review-toolkit/ort@855440d.

@jmongard any opinion about which approach to prefer?

Bullet items now have too much spacing

On the upgrade to version 0.8.0, there's now additional spacing between change log entries.

Before version 0.8.0:

image

With version 0.8.0:

image

This seems to be caused by blank lines between the bullet items in the Markdown source:

### Bug Fixes 🐞
- 2a301259513620fe2bbeef425eed9fef48f85c37 ClearlyDefinedStorage: Remove a `readInternal()` override

- 9dfa1982fce802169e3c67a7eadf8e48f4eee35a RequirementsCommand: Account for new scanner constructors

Please revert back to the original more compact representation.

Incorrect version build, when we have more than 1 feature branch

Hi, i return to test plugin:
config:

semver {
    releaseTagNameFormat = "v%s"
    noDirtyCheck = true
    groupVersionIncrements = false
    noAutoBumb = true
}
  1. I set tag v0.4.0 than created two branches from dev - test1 and test2.
[root@48d71aaecdaf app]# git checkout dev
Switched to branch 'dev'
[root@48d71aaecdaf app]# git tag v0.4.0
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Version: 0.4.0+sha.db9d0b8

Finished: Fri Jul 15 10:04:14 MSK 2022
[root@48d71aaecdaf app]# git checkout -b test1
Switched to a new branch 'test1'
[root@48d71aaecdaf app]# git checkout dev
Switched to branch 'dev'
[root@48d71aaecdaf app]# git checkout -b test2
Switched to a new branch 'test2'
  1. Set some commits first in branch test1 than test2 and watched to version
[root@48d71aaecdaf app]# git checkout test1
Switched to branch 'test1'
[root@48d71aaecdaf app]# git commit --allow-empty -m 'fix: test 11'
[test1 062df3f] fix: test 11
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Version: 0.4.1-SNAPSHOT+001.sha.062df3f

Finished: Fri Jul 15 10:05:18 MSK 2022

BUILD SUCCESSFUL in 579ms
1 actionable task: 1 executed
[root@48d71aaecdaf app]# git commit --allow-empty -m 'fix: test 12'
[test1 e9dffd6] fix: test 12
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Version: 0.4.2-SNAPSHOT+002.sha.e9dffd6

Finished: Fri Jul 15 10:05:25 MSK 2022

BUILD SUCCESSFUL in 597ms
1 actionable task: 1 executed
[root@48d71aaecdaf app]# git commit --allow-empty -m 'fix: test 13'
[test1 4f7fd3e] fix: test 13
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Merge branch 'test2' into dev
Version: 0.4.3-SNAPSHOT+003.sha.4f7fd3e

Finished: Fri Jul 15 10:05:31 MSK 2022

BUILD SUCCESSFUL in 599ms
1 actionable task: 1 executed
[root@48d71aaecdaf app]# git checkout test2
Switched to branch 'test2'
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Version: 0.4.0+sha.db9d0b8

Finished: Fri Jul 15 10:05:38 MSK 2022

BUILD SUCCESSFUL in 587ms
1 actionable task: 1 executed
[root@48d71aaecdaf app]# git commit --allow-empty -m 'fix: test 21'
[test2 26fc727] fix: test 21
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Version: 0.4.1-SNAPSHOT+001.sha.26fc727

Finished: Fri Jul 15 10:05:45 MSK 2022

BUILD SUCCESSFUL in 585ms
1 actionable task: 1 executed
[root@48d71aaecdaf app]# git commit --allow-empty -m 'fix: test 22'
[test2 824e7b0] fix: test 22
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Version: 0.4.2-SNAPSHOT+002.sha.824e7b0

Finished: Fri Jul 15 10:05:53 MSK 2022

BUILD SUCCESSFUL in 568ms
1 actionable task: 1 executed
  1. Than i merged test1 to dev and took correct version = 0.4.3-shapshot+003
[root@48d71aaecdaf app]# git branch
  dev
  master
  test1
* test2
[root@48d71aaecdaf app]# git checkout dev
Switched to branch 'dev'
[root@48d71aaecdaf app]# git merge test1
Updating db9d0b8..4f7fd3e
Fast-forward
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Version: 0.4.3-SNAPSHOT+003.sha.4f7fd3e

Finished: Fri Jul 15 10:07:06 MSK 2022

BUILD SUCCESSFUL in 577ms
1 actionable task: 1 executed

4.Than i merged test2 to dev and took incorrect version 0.4.2-shapshot+007

[root@48d71aaecdaf app]# git merge test2
Already up-to-date!
Merge made by the 'recursive' strategy.
[root@48d71aaecdaf app]# ./gradlew printversion

> Task :printVersion
--------------------
Version: 0.4.2-SNAPSHOT+007.sha.7420aca

Finished: Fri Jul 15 10:07:29 MSK 2022

BUILD SUCCESSFUL in 550ms
1 actionable task: 1 executed
  1. if i will look at 'git log', I'll see all commits
commit 7420aca507ebc8c85259a01adddc8548c215b6d3
Merge: 4f7fd3e 824e7b0
Author: Your Name <[email protected]>
Date:   Fri Jul 15 10:07:17 2022 +0300

    Merge branch 'test2' into dev

commit 824e7b0e86f62810f8e11dd3654b5aacd4bbaeb8
Author: Your Name <[email protected]>
Date:   Fri Jul 15 10:05:49 2022 +0300

    fix: test 22

commit 26fc72751be23b3c2247b3dbe526cf97b1a39058
Author: Your Name <[email protected]>
Date:   Fri Jul 15 10:05:43 2022 +0300

    fix: test 21

commit 4f7fd3e41ebc1fb9e03a3495888aefada601ab15
Author: Your Name <[email protected]>
Date:   Fri Jul 15 10:05:28 2022 +0300

    fix: test 13

commit e9dffd6bc0c31b5182aa69ec372d63a0bb29e3c1
Author: Your Name <[email protected]>
Date:   Fri Jul 15 10:05:22 2022 +0300

    fix: test 12

commit 062df3f03c56637a38a35c08af1044f844058163
Author: Your Name <[email protected]>
Date:   Fri Jul 15 10:05:11 2022 +0300

    fix: test 11

In graph it's lool like this:

* bc4b8e2 - (7 minutes ago) fix: test 31 - Your Name (HEAD, test3, dev)
*   7420aca - (22 minutes ago) Merge branch 'test2' into dev - Your Name
|\
| * 824e7b0 - (24 minutes ago) fix: test 22 - Your Name (test2)
| * 26fc727 - (24 minutes ago) fix: test 21 - Your Name
* | 4f7fd3e - (24 minutes ago) fix: test 13 - Your Name (test1)
* | e9dffd6 - (24 minutes ago) fix: test 12 - Your Name
* | 062df3f - (25 minutes ago) fix: test 11 - Your Name
|/
*   db9d0b8 - (2 weeks ago) Merge branch 'hotfix/jira-0000/xxxxx' into 'dev' - some (tag: v0.4.0, origin/dev, origin/HEAD)

Originally posted by @driftertest in #12 (comment)

Duplicate releases are created

I got every release is done twice when ./gradlew releaseVersion is executed. Configuration is default, plugin version is 0.4.2.
image
Any ideas?

Add a task to create "templatized" release notes

I'm not sure if this would be out of scope, but as the commits since the last tag are determined anyway, maybe grouping them by type as part of writing out a release notes files in Markdown format would make sense. Such a Markdown file could then be used for the notes as part of GitHub releases. This would avoid users of this plugin to additionally take something like https://github.com/requarks/changelog-action into use, and ensure that the interpretation of Conventinal Commits is exactly the same for bumping the version and creating the notes.

The `printVersion` should print `semver.version`

IMO it's misleading in the context of the releaseVersion task, which uses semver.version, that the printVersion task does not:

project.tasks.register("printVersion") { task ->
task.group = VERSIONING_GROUP;
task.description = "Prints the current project version";
task.doLast {
println("--------------------")
println("Version: ${settings.semVersion}")
}
}

I propose to introduce new tasks with the following mapping:

Task Variable Used
printVersion semver.version
printInfoVersion semver.infoVersion
printSemVersion semver.semVersion

Also, all of these tasks should really just print the version, without any "--------------------" separator or "Version: " prefix or similar. That way, e.g. ./gradlew -q printVersion could be used to pipe the calculated version to somewhere else (like a Docker image build).

noAutoBumb

Hi, I have some questions about the noAutoBumb section. When I create commits that don't look like "conventional commits" (like "test", "observation", etc.), I expect the version to stay the same. But for some reason the "-SNAPSHOT" is lost. Example:

[root@5426297443a8 app]# git commit --allow-empty -m "fix: test12"
[dev 1721987] fix: test12
[root@5426297443a8 app]# git log -n 3
commit 17219872c6032dc44ef4ca6feeacc6e6bf46e39d
Author: Your Name <[email protected]>
Date:   Wed Oct 13 16:25:56 2021 +0300

    fix: test12

commit c8f19559ee2d7ab9b1a4dcdadf0cc55903ac9f8a
Author: Your Name <[email protected]>
Date:   Wed Oct 13 16:18:38 2021 +0300

    test11

commit f710c53feb892ca0881b41a04a18162c3c9a9460
Author: Your Name <[email protected]>
Date:   Wed Oct 13 16:10:00 2021 +0300

    fix: test10
[root@5426297443a8 app]# ./gradlew printversion

> Configure project :
'lombok.addLombokGeneratedAnnotation = true' is not configured for '/app/src/main/java' of the main source-set
'lombok.addLombokGeneratedAnnotation = true' is not configured for '/app/src/test/java' of the test source-set

> Task :printVersion
--------------------
Version: 0.0.11-SNAPSHOT+013.sha.1721987

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
[root@5426297443a8 app]# git commit --allow-empty -m "test13"
[dev e6a8f6d] test13
[root@5426297443a8 app]# ./gradlew printversion

> Configure project :
'lombok.addLombokGeneratedAnnotation = true' is not configured for '/app/src/main/java' of the main source-set
'lombok.addLombokGeneratedAnnotation = true' is not configured for '/app/src/test/java' of the test source-set

> Task :printVersion
--------------------
Version: 0.0.11+014.sha.e6a8f6d

BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed
[root@5426297443a8 app]# git log -n 3
commit e6a8f6dad9bb672d467ebfd3a13814c01a099c95
Author: Your Name <[email protected]>
Date:   Wed Oct 13 16:26:17 2021 +0300

    test13

commit 17219872c6032dc44ef4ca6feeacc6e6bf46e39d
Author: Your Name <[email protected]>
Date:   Wed Oct 13 16:25:56 2021 +0300

    fix: test12

commit c8f19559ee2d7ab9b1a4dcdadf0cc55903ac9f8a
Author: Your Name <[email protected]>
Date:   Wed Oct 13 16:18:38 2021 +0300

    test11
[root@5426297443a8 app]#

After second commit i expect 0.0.11-SNAPSHOT+014.sha.e6a8f6d

gradlew config:

semver {
    releaseTagNameFormat = "v%s"
    noDirtyCheck = true
    groupVersionIncrements = false
    noAutoBumb = true
}

not bumped version after squash merge

Hi, i have another question.
I made branch test-111, than i made some commits and run gradlew printVersion + gradle releaseVersion and set tag 0.3.1. Than i merged my branch in dev branch with squash. Now i made test-222 from dev, set 2 commits and when i run gradlew printVersion, it's print me 0.3.1-SNAPSHOT+022.sha.7bab51a. But i expect 0.3.2

10:38:17.974 [DEBUG] [org.eclipse.jgit.internal.storage.file.FileSnapshot] file=/app/.git/config, is unmodified
10:38:17.974 [INFO] [git.semver.plugin.scm.GitProvider] The Git repository is dirty
10:38:17.974 [DEBUG] [git.semver.plugin.scm.GitProvider] added: []
10:38:17.974 [DEBUG] [git.semver.plugin.scm.GitProvider] changed: []
10:38:17.974 [DEBUG] [git.semver.plugin.scm.GitProvider] removed: []
10:38:17.974 [DEBUG] [git.semver.plugin.scm.GitProvider] conflicting: []
10:38:17.975 [DEBUG] [git.semver.plugin.scm.GitProvider] missing: []
10:38:17.975 [DEBUG] [git.semver.plugin.scm.GitProvider] modified: [build.gradle]
10:38:17.976 [DEBUG] [git.semver.plugin.semver.SemVersion] Found version: 0.3.0+sha.de571da in: 'v0.3'
10:38:17.976 [DEBUG] [git.semver.plugin.semver.VersionFinder] Release version found: 0.3.0+sha.de571da
10:38:17.976 [DEBUG] [git.semver.plugin.semver.VersionFinder] Version after commit("Started using Semantic versioning for Gradle"), pre-release(null): 0.3.0+001.sha.3ae727e
..........
10:38:17.977 [DEBUG] [git.semver.plugin.semver.VersionFinder] Version after commit("fix: Update README.md"), pre-release(null): 0.3.0+022.sha.7bab51a
.........
10:38:18.435 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :printVersion
10:38:18.435 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Task :printVersion' started
10:38:18.435 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter] Putting task artifact state for task ':printVersion' into context took 0.0 secs.
10:38:18.435 [INFO] [org.gradle.internal.execution.steps.ResolveCachingStateStep] Caching disabled for task ':printVersion' because:
  Build cache is disabled
10:38:18.435 [DEBUG] [org.gradle.internal.execution.steps.SkipUpToDateStep] Determining if task ':printVersion' is up-to-date
10:38:18.436 [INFO] [org.gradle.internal.execution.steps.SkipUpToDateStep] Task ':printVersion' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
10:38:18.436 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':printVersion'.
10:38:18.436 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute doLast {} action for :printVersion' started
10:38:18.436 [QUIET] [system.out] --------------------
10:38:18.436 [QUIET] [system.out] Version: 0.3.1-SNAPSHOT+022.sha.7bab51a

git tag

[root@3dbb63da6029 app]# git tag -l -n9
v0.3            Merge remote-tracking branch 'origin/dev' into dev
v0.3.1          Release tag set by user

if i set new tag 0.3.2 by 'git tag v0.3.2', i see 0.3.3

root@3dbb63da6029 app]# git tag v0.3.2
[root@3dbb63da6029 app]# git tag
v0.3
v0.3.1
v0.3.2
[root@3dbb63da6029 app]# ./gradlew printVersion

> Configure project :
'lombok.addLombokGeneratedAnnotation = true' is not configured for '/app/src/main/java' of the main source-set

> Task :printVersion
--------------------
Version: 0.3.3-SNAPSHOT+sha.7bab51a

Finished: Tue Aug 10 11:35:52 MSK 2021

strange behavior printVersion

Hi, sorry for my english. In my Jenkins pipeline i use docker image jdk:8u201 for building my app by gradle. And when i run printVersion after releaseVersion, module show me some strange (if you see, that the SHA of commit is same a81ff1f and latest tag is v0.3). If I do the same thing locally, then everything is fine. Where i make mistake?


+ ./gradlew printVersion
Downloading ...
.....................................................................................................................................
Welcome to Gradle 5.6!

Here are the highlights of this release:
 - Incremental Groovy compilation
 - Groovy compile avoidance
 - Test fixtures for Java projects
 - Manage plugin versions via settings script

For more details see https://docs.gradle.org/5.6/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :
'lombok.addLombokGeneratedAnnotation = true' is not configured for '/app/src/main/java' of the main source-set

> Task :printVersion
--------------------
Version: 0.3.1-SNAPSHOT+021.sha.a81ff1f

Finished: Fri Aug 06 14:52:55 MSK 2021

BUILD SUCCESSFUL in 8s
1 actionable task: 1 executed
[Pipeline] sh
+ cd /app
+ ./gradlew releaseVersion --no-dirty --no-commit --message 'Release tag set by user'
> Configure project :
'lombok.addLombokGeneratedAnnotation = true' is not configured for '/app/src/main/java' of the main source-set

> Task :releaseVersion

Finished: Fri Aug 06 14:52:56 MSK 2021

BUILD SUCCESSFUL in 707ms
1 actionable task: 1 executed
[Pipeline] sh
+ cd /app
+ ./gradlew printVersion
> Configure project :
'lombok.addLombokGeneratedAnnotation = true' is not configured for '/app/src/main/java' of the main source-set

> Task :printVersion
--------------------
Version: 0.3.2-SNAPSHOT+sha.a81ff1f

Finished: Fri Aug 06 14:52:58 MSK 2021

BUILD SUCCESSFUL in 862ms
1 actionable task: 1 executed

Can't get commit hash in version string

I'm using version 0.12.2 of the plugin.

When I print semver.semVersion.toString() in my build.gradle.kts file, the result doesn't include the commit hash, even though ./gradlew printSemVersion does.

When I try to call semver.semVersion.toInfoVersionString, my IDE thinks that the toInfoVersionString method doesn't exist.

These are the settings I've applied:

semver {
    releaseTagNameFormat = "v%s"
    createReleaseCommit = false
}

Any help would be appreciated. Thanks for the great work on the plugin!

"feat:" does not increase MINOR

Hi,

First, great plugin. It is serving exactly what I am looking for.

I do have a question though. When I have in my commit comment the text feat: either at the start or anywhere else in the comment, the MINOR is not increased by 1, instead these commits and subsequently pushes only increase the PATCH number.

I have set in my build.gradle file the configuration as follows:

semver {
    defaultPreRelease = "SNAPSHOT"
    releasePattern = "\\Arelease(?:\\(\\w+\\))?:"
    majorPattern = "\\A\\w+(?:\\(\\w+\\))?!:|^BREAKING[ -]CHANGE:"
    minorPattern = "\\Afeat(?:\\(\\w+\\))?:"
    patchPattern = "\\Afix(?:\\(\\w+\\))?:"
    releaseCommitTextFormat = "release: v%s\n\n%s"
    releaseTagNameFormat = "%s"
}

version = semver.version

The README.MD file is not really clear on how the sequence of MINOR and PATCH can be updated or are updated beyond '1'. Could you 'improve' the table (https://github.com/jmongard/Git.SemVersioning.Gradle#example-of-how-version-is-calculated) showing what happens when you do what with increase to for example 0.2.1 and 0.2.2 and 1.0.0?

Thanks again for this great plugin.

Problem with version 0.4.2

Hi, i'm a little confused, but the plugin stopped working for some reason. The settings did not change, the environment did not change either, since the assembly takes place in a container.

My settings in build.gradle:

semver {
    releaseTagNameFormat = "v%s"
    noDirtyCheck = true
    groupVersionIncrements = true
    noAutoBumb = true
}

The version that is being generated now:

[root@88e629868eb7 app]# ./gradlew printVersion

> Task :printVersion
--------------------
Version: 0.13.24-SNAPSHOT+020.sha.ae5d1cf

If we look at graph of commits, we see that patch version don't bump after "fix" commit. But after version 0.13.23 and 1 "fix" commit we see 0.13.24:
Screenshot 2022-04-26 at 16 36 35 2

printChangelog doesn't print out emojis on terminal

We're currently using the printChangelog task to generate a Github release changelog.

We're using Jenkins to capture the stdout of the sh command and forwarding it to another step that creates the github release.

For whatever reason the emojis don't render when outputted to the shell, so they end up as "?" that get captured by the pipeline and forwarded to the github release step.

Then the changelog notes will have stuff like "Build ? & CI ??".

We've overridden the semver changelog to eliminate the emojis in the header strings. We figure that we'd need to do this for every project that we have and it could get tedious.

Is it possible to add a changelog template that strips away the emojis?

buildSrc conventions style example

Hi

Great plugin and really simple to configure up.

I have a question or query as I'm struggling to get the versioning quite right in a multi-module project that is configured using Gradle 6's convention style plugins in the buildSrc directory. Do you have an example working with this?

I effectively have the following structure in buildSrc;

  • project-conventions.gradle
  • library-conventions.gradle

I apply the semantic versioning plugin in project-conventions.gradle and apply that to the root build.gradle

plugins {
    id 'com.github.jmongard.git-semver-plugin'
}

semver {
    //Example of each property with their respective default value
    defaultPreRelease = "SNAPSHOT"
    releasePattern = "\\Arelease(?:\\(\\w+\\))?:"
    majorPattern = "\\A\\w+(?:\\(\\w+\\))?!:|^BREAKING[ -]CHANGE:"
    minorPattern = "\\ANew Feature(?:\\(\\w+\\))?:"
    patchPattern = "\\AFix(?:\\(\\w+\\))?:"
    releaseCommitTextFormat = "Applying this commit will tag the release: %s\n\n%s"
    releaseTagNameFormat = "v%s"
    groupVersionIncrements = true
}

version semver.version

Each submodule has library-conventions.gradle applied. project-conventions.gradle also applies library-conventions.gradle

I was hoping that submodules would pick up on that version property but they don't seem to be.

Happy to provide an example repository if that's helpful?

Many thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.