gradle-semantic-release-plugin
gradle-semantic-release-plugin copied to clipboard
Help with Prerelease
Hi,
I've been stuck in this problem for a while and I hope somebody can help me here. My goal is to release new versions via semantic versioning on every Pull Request merge from our develop branch in our master. This works very well but additionally, I want to have prereleases generated on every push in our develop branch. The prereleases must have a version like vX.Y.Z-beta.1 or -rc.1 where the number after the dot is incremented automatically.
I've tried many things to achive this behaviour but ended every time in an SNAPSHOT Postfix. For example I had a Branch rc/1.0.0 and the inferred version was ...-rc-1-0-0-SNAPSHOT. I've tried to configure the plugin in our build.gradle with the versionStrategy and .copyWith() but got still no prerelease Version.
We are using the plugin in Version 1.3.1 together with grgit 2.2.0 listed in our dependencies.
Can anybody help me?
Please have a look at https://github.com/tschulte/gradle-semantic-release-test/blob/master/build.gradle.
release {
// add a second strategy to create release candidates from 'rc/.*' branches
versionStrategy semanticRelease.releaseStrategy.copyWith(
// the type is important, without type you would again replace the default strategy
type: 'rc',
selector: { SemVerStrategyState state ->
!state.repoDirty && state.currentBranch.name ==~ /rc\/.*/ &&
semanticRelease.semanticStrategy.canRelease(state) && project.gradle.startParameter.taskNames.find { it == 'release' }
},
preReleaseStrategy: StrategyUtil.all({ it.copyWith(inferredPreRelease: 'rc') } as PartialSemVerStrategy, Strategies.PreRelease.COUNT_INCREMENTED)
)
}
Hi Tobias,
i've tried your suggested configuration in my current project and in a clean repo. And it doesn't generate the rc.X suffix.
On my clean master branch I get the following output when I run my printVersion Task:
10:51:19: Executing task 'printVersion'...
> Task :printVersion
Inferred version: 1.0.0-SNAPSHOT
1.0.0-SNAPSHOT
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
10:51:20: Task execution finished 'printVersion'.
on my branch rc/1.0.0 the output is
10:53:38: Executing task 'printVersion'...
> Task :printVersion
Inferred version: 1.0.0-rc-1-0-0-SNAPSHOT
1.0.0-rc-1-0-0-SNAPSHOT
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
10:53:38: Task execution finished 'printVersion'.
My printVersion Task just prints the value of project.version
My build.gradle looks like yours in your test project except that I'm using the Version 1.3.1 and removed the java tasks, as i don't have a Java project.
import org.ajoberstar.gradle.git.release.semver.*
import org.ajoberstar.gradle.git.release.opinion.Strategies
plugins {
id 'de.gliderpilot.semantic-release' version '1.4.0'
}
release {
// add a second strategy to create release candidates from 'rc/.*' branches
versionStrategy semanticRelease.releaseStrategy.copyWith(
// the type is important, without type you would again replace the default strategy
type: 'rc',
selector: { SemVerStrategyState state ->
!state.repoDirty && state.currentBranch.name ==~ /rc\/.*/ &&
semanticRelease.semanticStrategy.canRelease(state) && project.gradle.startParameter.taskNames.find { it == 'release' }
},
preReleaseStrategy: StrategyUtil.all({ it.copyWith(inferredPreRelease: 'rc') } as PartialSemVerStrategy, Strategies.PreRelease.COUNT_INCREMENTED)
)
}
semanticRelease {
repo {
ghToken = project.ext.githubToken
useGhEnterprise project.ext.githubUrl
}
}
task printVersion {
doLast { // add a task action
println project.version
}
}
In the selector, it explicitly says
&& project.gradle.startParameter.taskNames.find { it == 'release' }
to only set the version, when doing a release. Unless you do a release, -SNAPSHOT IMHO is the right version. But feel free to remove that part.
Hi Tobias,
yep you are right. That was my mistake, sry. I've tried the above solution with the gradle Task release which should be the right one.
When I execute the task on my master branch a new Version 1.0.0 has been released in my repo. Executing the task on my rc/1.0.0 branch gives me the following output
> Task :release
Task ':release' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Initial State: org.ajoberstar.gradle.git.release.semver.SemVerStrategyState(scopeFromProp:null, stageFromProp:null, currentHead:org.ajoberstar.grgit.Commit(cc11bf2788e48ba301988fa984a7dbe2c6a313ea, [920a987e83c347c6cbeaa03021ec4f5ff45330e3, 04751564abccab81a1bd0dcee1ccf473604ec35a], org.ajoberstar.grgit.Person(XXXXX, [email protected]), org.ajoberstar.grgit.Person(GitHub Enterprise, [email protected]), 1550480213, Merge pull request #1 from pattern-library/rc/1.0.0
fix(build): check repo status, Merge pull request #1 from pattern-library/rc/1.0.0), currentBranch:org.ajoberstar.grgit.Branch(refs/heads/rc/1.0.0, org.ajoberstar.grgit.Branch(refs/remotes/origin/rc/1.0.0)), repoDirty:false, nearestVersion:org.ajoberstar.gradle.git.release.semver.NearestVersion(1.0.0, 1.0.0, 0, 0), inferredNormal:null, inferredPreRelease:null, inferredBuildMetadata:null)
Falling back to default strategy: semantic-release-SNAPSHOT
Beginning version inference using semantic-release-SNAPSHOT strategy
Inferred version: 1.0.1-rc-1-0-0-SNAPSHOT
Pushing changes in [refs/heads/rc/1.0.0] to origin
The following authentication options are allowed (though they may not be available): [HARDCODED, INTERACTIVE, PAGEANT, SSHAGENT]
using hardcoded credentials from system properties
:release (Thread[Task worker for ':',5,main]) completed. Took 0.175 secs.
:updateGithubRelease (Thread[Task worker for ':',5,main]) started.
> Task :updateGithubRelease SKIPPED
Skipping task ':updateGithubRelease' as task onlyIf is false.
:updateGithubRelease (Thread[Task worker for ':',5,main]) completed. Took 0.005 secs.
BUILD SUCCESSFUL in 0s
And it doesn't create a rc.X release.
I just checked using https://github.com/tschulte/gradle-semantic-release-test/.
[21:47][~/projects/gradle-semantic-release-test (master u=)]$ git checkout -b rc/doesntmatter
Switched to a new branch 'rc/doesntmatter'
[21:47][~/projects/gradle-semantic-release-test (rc/doesntmatter)]$ git commit -m 'feat: cool new feature' --allow-empty
[rc/doesntmatter f839490] feat: cool new feature
[21:47][~/projects/gradle-semantic-release-test (rc/doesntmatter)]$ gw release --dry-run
Inferred version: 2.2.0-rc.1
[...]
BUILD SUCCESSFUL
Total time: 1.018 secs
[21:48][~/projects/gradle-semantic-release-test (rc/doesntmatter)]$
Only when there is no feature or fix commit since the last tag, a SNAPSHOT will be built:
[21:48][~/projects/gradle-semantic-release-test (rc/doesntmatter)]$ git reset --hard HEAD~
HEAD is now at b7f24d6 feat: test new gh-token
[21:49][~/projects/gradle-semantic-release-test (rc/doesntmatter)]$ gw release --dry-run
Inferred version: 2.1.1-rc-doesntmatter-SNAPSHOT
[...]
BUILD SUCCESSFUL
Total time: 1.018 secs
[21:49][~/projects/gradle-semantic-release-test (rc/doesntmatter)]$