Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
wooga app versioning (#42)
Browse files Browse the repository at this point in the history
* Restructure custom wooga version strategies

To prepare for a new default setup I moved the version
strategies to `src/main/groovy/wooga/gradle/release/version/semver/VersionStrategies`
The old `src/main/groovy/wooga/gradle/release/utils/WoogaStrategies` stays in
the project and links its static definitions to `VersionStrategies`

* Add new second versioning scheme based on semver2.x

`src/main/groovy/wooga/gradle/release/version/semver2/VersionStrategies`
contains adjusted version strategies for semver2.x based version.
The project can switch to these strategies by setting the
`version.scheme` property to 'semver2'.

Add test specs for new scheme

* Add groovy doc strings for new VersionStrategy configs

* Fix snapshot strategy definition

* use common name instead of `ci`
* set `allowDirtyRepo` flag to true so strategy can be applied during development

* Add branch name exception for develop branch

To accommodate gitflow setups the `develop` branch shouldn't produce
versions with a `branch.` prefix.
  • Loading branch information
Larusso authored Aug 14, 2018
1 parent 682ea62 commit a11034e
Show file tree
Hide file tree
Showing 5 changed files with 763 additions and 99 deletions.
32 changes: 26 additions & 6 deletions src/main/groovy/wooga/gradle/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.language.base.plugins.LifecycleBasePlugin
import wooga.gradle.github.GithubPlugin
import wooga.gradle.github.publish.tasks.GithubPublish
import wooga.gradle.github.publish.GithubPublishPlugin
import wooga.gradle.github.publish.tasks.GithubPublish
import wooga.gradle.paket.PaketPlugin
import wooga.gradle.paket.base.PaketBasePlugin
import wooga.gradle.paket.base.PaketPluginExtension
Expand All @@ -48,6 +48,7 @@ import wooga.gradle.paket.unity.PaketUnityPlugin
import wooga.gradle.release.internal.DefaultAtlasReleasePluginExtension
import wooga.gradle.release.utils.ProjectStatusTaskSpec
import wooga.gradle.release.utils.WoogaStrategies
import wooga.gradle.release.version.semver.VersionStrategies
import wooga.gradle.releaseNotesGenerator.ReleaseNotesGeneratorPlugin
import wooga.gradle.releaseNotesGenerator.utils.ReleaseBodyStrategy

Expand Down Expand Up @@ -78,6 +79,10 @@ class ReleasePlugin implements Plugin<Project> {
static final String GROUP = "Wooga"
static final String EXTENSION_NAME = "atlasRelease"

static final String VERSION_SCHEME_DEFAULT = 'semver'
static final String VERSION_SCHEME_SEMVER_1 = 'semver'
static final String VERSION_SCHEME_SEMVER_2 = 'semver2'

@Override
void apply(Project project) {
def extension = project.extensions.create(EXTENSION_NAME, DefaultAtlasReleasePluginExtension)
Expand Down Expand Up @@ -412,12 +417,27 @@ class ReleasePlugin implements Plugin<Project> {
if (project == project.rootProject) {
ReleasePluginExtension releaseExtension = project.extensions.findByType(ReleasePluginExtension)

def versionScheme = project.properties.getOrDefault("version.scheme", VERSION_SCHEME_DEFAULT)


releaseExtension.with {
releaseExtension.versionStrategy(WoogaStrategies.SNAPSHOT)
releaseExtension.versionStrategy(WoogaStrategies.DEVELOPMENT)
releaseExtension.versionStrategy(WoogaStrategies.PRE_RELEASE)
releaseExtension.versionStrategy(WoogaStrategies.FINAL)
releaseExtension.defaultVersionStrategy = WoogaStrategies.DEVELOPMENT
switch(versionScheme) {
case VERSION_SCHEME_SEMVER_2:
releaseExtension.versionStrategy(wooga.gradle.release.version.semver2.VersionStrategies.SNAPSHOT)
releaseExtension.versionStrategy(wooga.gradle.release.version.semver2.VersionStrategies.DEVELOPMENT)
releaseExtension.versionStrategy(wooga.gradle.release.version.semver2.VersionStrategies.PRE_RELEASE)
releaseExtension.versionStrategy(wooga.gradle.release.version.semver2.VersionStrategies.FINAL)
releaseExtension.defaultVersionStrategy = wooga.gradle.release.version.semver2.VersionStrategies.DEVELOPMENT
break
case VERSION_SCHEME_SEMVER_1:
default:
releaseExtension.versionStrategy(VersionStrategies.SNAPSHOT)
releaseExtension.versionStrategy(VersionStrategies.DEVELOPMENT)
releaseExtension.versionStrategy(VersionStrategies.PRE_RELEASE)
releaseExtension.versionStrategy(VersionStrategies.FINAL)
releaseExtension.defaultVersionStrategy = VersionStrategies.DEVELOPMENT
break
}
}

replaceReleaseTask(project, releaseExtension)
Expand Down
93 changes: 6 additions & 87 deletions src/main/groovy/wooga/gradle/release/utils/WoogaStrategies.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@

package wooga.gradle.release.utils

import nebula.plugin.release.NetflixOssStrategies
import org.ajoberstar.gradle.git.release.opinion.Strategies
import org.ajoberstar.gradle.git.release.semver.ChangeScope
import org.ajoberstar.gradle.git.release.semver.PartialSemVerStrategy
import org.ajoberstar.gradle.git.release.semver.SemVerStrategy
import org.ajoberstar.gradle.git.release.semver.SemVerStrategyState
import org.ajoberstar.gradle.git.release.semver.StrategyUtil

import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.closure
import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.parseIntOrZero
import wooga.gradle.release.version.semver.VersionStrategies

/**
* Set of {@code SemVerStrategy} properties to determine current version.
Expand All @@ -36,33 +29,7 @@ import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.parseIntOrZe
*/
class WoogaStrategies {

private static final scopes = StrategyUtil.one(
Strategies.Normal.USE_SCOPE_PROP,
Strategies.Normal.ENFORCE_GITFLOW_BRANCH_MAJOR_X, Strategies.Normal.ENFORCE_BRANCH_MAJOR_X,
Strategies.Normal.ENFORCE_GITFLOW_BRANCH_MAJOR_MINOR_X, Strategies.Normal.ENFORCE_BRANCH_MAJOR_MINOR_X,
Strategies.Normal.USE_NEAREST_ANY, Strategies.Normal.useScope(ChangeScope.PATCH))

static final PartialSemVerStrategy COUNT_INCREMENTED = closure { SemVerStrategyState state ->
def nearest = state.nearestVersion
def currentPreIdents = state.inferredPreRelease ? state.inferredPreRelease.split('\\.') as List : []
if (nearest.any == nearest.normal || nearest.any.normalVersion != state.inferredNormal) {
currentPreIdents << '1'
} else {
def indexOfFirstDiget = nearest.any.preReleaseVersion.findIndexOf { it ==~ /\d/ }
def preReleaseversion = nearest.any.preReleaseVersion

def nearestPreIdents = [preReleaseversion.substring(0,indexOfFirstDiget),preReleaseversion.substring(indexOfFirstDiget)]
if (nearestPreIdents.size() <= currentPreIdents.size()) {
currentPreIdents << '1'
} else if (currentPreIdents == nearestPreIdents[0..(currentPreIdents.size() - 1)]) {
def count = parseIntOrZero(nearestPreIdents[currentPreIdents.size()])
currentPreIdents << Integer.toString(count + 1)
} else {
currentPreIdents << '1'
}
}
return state.copyWith(inferredPreRelease: currentPreIdents.join('.'))
}
static final PartialSemVerStrategy COUNT_INCREMENTED = VersionStrategies.COUNT_INCREMENTED

/**
* Returns a version strategy to be used for {@code pre-release}/{@code candidate} builds.
Expand Down Expand Up @@ -100,17 +67,7 @@ class WoogaStrategies {
* }
* </pre>
*/
static final SemVerStrategy PRE_RELEASE = Strategies.PRE_RELEASE.copyWith(
normalStrategy: scopes,
preReleaseStrategy: StrategyUtil.all(StrategyUtil.closure({ state ->
state = Strategies.PreRelease.STAGE_FIXED.infer(state)
def stage = state.inferredPreRelease
def count = WoogaStrategies.COUNT_INCREMENTED.infer(state).inferredPreRelease
count = count.split(/\./).last()
def integration = "$count".padLeft(5, '0')
state.copyWith(inferredPreRelease: "$stage$integration")
}))
)
static final SemVerStrategy PRE_RELEASE = VersionStrategies.PRE_RELEASE

/**
* Returns a version strategy to be used for {@code final} builds.
Expand All @@ -126,7 +83,7 @@ class WoogaStrategies {
* }
* </pre>
*/
static final SemVerStrategy FINAL = Strategies.FINAL.copyWith(normalStrategy: scopes)
static final SemVerStrategy FINAL = VersionStrategies.FINAL

/**
* Returns a version strategy to be used for {@code development} builds.
Expand All @@ -147,9 +104,7 @@ class WoogaStrategies {
* }
* </pre>
*/
static final SemVerStrategy DEVELOPMENT = Strategies.DEVELOPMENT.copyWith(
normalStrategy: scopes,
buildMetadataStrategy: NetflixOssStrategies.BuildMetadata.DEVELOPMENT_METADATA_STRATEGY)
static final SemVerStrategy DEVELOPMENT = VersionStrategies.DEVELOPMENT

/**
* Returns a version strategy to be used for {@code snapshot} builds.
Expand Down Expand Up @@ -183,41 +138,5 @@ class WoogaStrategies {
* }
* </pre>
*/
static final SemVerStrategy SNAPSHOT = Strategies.PRE_RELEASE.copyWith(
name: 'snapshot',
stages: ['snapshot','SNAPSHOT'] as SortedSet,
normalStrategy: scopes,
preReleaseStrategy: StrategyUtil.all(StrategyUtil.closure({state ->

String branchName = state.currentBranch.name
String prefix = "branch"

if( branchName == "HEAD" && System.getenv("BRANCH_NAME") ) {
branchName = System.getenv("BRANCH_NAME")
}

if( branchName != "master") {
branchName = "$prefix${branchName.capitalize()}"
}
branchName = branchName.replaceAll(/(\/|-|_)([\w])/) {all, delimiter, firstAfter -> "${firstAfter.capitalize()}" }
branchName = branchName.replaceAll(/\./, "Dot")
branchName = branchName.replaceAll(/0/, "Zero")
branchName = branchName.replaceAll(/1/, "One")
branchName = branchName.replaceAll(/2/, "Two")
branchName = branchName.replaceAll(/3/, "Three")
branchName = branchName.replaceAll(/4/, "Four")
branchName = branchName.replaceAll(/5/, "Five")
branchName = branchName.replaceAll(/6/, "Six")
branchName = branchName.replaceAll(/7/, "Seven")
branchName = branchName.replaceAll(/8/, "Eight")
branchName = branchName.replaceAll(/9/, "Nine")

def buildSinceAny = state.nearestVersion.distanceFromNormal
def integration = "$buildSinceAny".padLeft(5, '0')
state.copyWith(inferredPreRelease: "$branchName$integration")
})),
createTag: false,
allowDirtyRepo: true,
enforcePrecedence: false
)
static final SemVerStrategy SNAPSHOT = VersionStrategies.SNAPSHOT
}
Loading

0 comments on commit a11034e

Please sign in to comment.