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

Commit

Permalink
added upm strategies and newsemver tests (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquimmnetto authored Dec 5, 2022
1 parent cc8c341 commit 1e12cef
Show file tree
Hide file tree
Showing 8 changed files with 971 additions and 11 deletions.
19 changes: 14 additions & 5 deletions src/main/groovy/wooga/gradle/version/VersionScheme.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ package wooga.gradle.version
import wooga.gradle.version.internal.release.base.VersionStrategy
import wooga.gradle.version.internal.release.semver.SemVerStrategy
import wooga.gradle.version.strategies.StaticMarkerStrategies
import wooga.gradle.version.strategies.WdkStrategies
import wooga.gradle.version.strategies.opinion.LegacyNuGetStrategies
import wooga.gradle.version.strategies.opinion.SemverV2WithDefaultStrategies
import wooga.gradle.version.strategies.opinion.UpmStrategies
import wooga.gradle.version.strategies.opinion.WdkNuGetStrategies

//TODO: Rename to VersionSchemes when breaking change
/**
Expand All @@ -50,10 +51,18 @@ enum VersionScheme implements IVersionScheme {
/**
* Schema for Paket/Nuget WDK projects. See WdkNuGetStrategies for more details.
*/
wdk(WdkStrategies.DEVELOPMENT,
WdkStrategies.SNAPSHOT,
WdkStrategies.PRE_RELEASE,
WdkStrategies.FINAL, WdkStrategies.PREFLIGHT)
wdk(WdkNuGetStrategies.DEVELOPMENT,
WdkNuGetStrategies.SNAPSHOT,
WdkNuGetStrategies.PRE_RELEASE,
WdkNuGetStrategies.FINAL, WdkNuGetStrategies.PREFLIGHT),
/**
* Schema for UPM-based unity3d projects. See UpmStrategies for more details.
* IMPORTANT: please note that the pre-release strategy for this schema does not enforces order between versions.
*/
upm(UpmStrategies.DEVELOPMENT,
UpmStrategies.SNAPSHOT,
UpmStrategies.PRE_RELEASE.copyWith(enforcePrecedence: false), //this is supposed to be temporary
UpmStrategies.FINAL, UpmStrategies.PREFLIGHT)

final VersionStrategy development
final VersionStrategy snapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package wooga.gradle.version.strategies

import wooga.gradle.version.IVersionScheme
import wooga.gradle.version.ReleaseStage
import wooga.gradle.version.internal.release.opinion.Strategies
import wooga.gradle.version.internal.release.semver.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package wooga.gradle.version.strategies

import wooga.gradle.version.IVersionScheme
import wooga.gradle.version.ReleaseStage
import wooga.gradle.version.internal.release.opinion.Strategies
import wooga.gradle.version.internal.release.semver.SemVerStrategy
Expand Down Expand Up @@ -158,4 +159,13 @@ final class NewSemverV2Strategies {
preReleaseStrategy: all(Strategies.PreRelease.WITH_BRANCH_NAME,
Strategies.PreRelease.COUNT_COMMITS_SINCE_ANY),
)

static final IVersionScheme scheme = new IVersionScheme() {
final SemVerStrategy development = DEVELOPMENT
final SemVerStrategy snapshot = SNAPSHOT
final SemVerStrategy preRelease = PRE_RELEASE
final SemVerStrategy finalStrategy = FINAL
final SemVerStrategy defaultStrategy = DEVELOPMENT
final List<SemVerStrategy> strategies = [development, snapshot, preRelease, finalStrategy]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package wooga.gradle.version.strategies.opinion


import wooga.gradle.version.ReleaseStage
import wooga.gradle.version.internal.release.opinion.Strategies
import wooga.gradle.version.internal.release.semver.*
import wooga.gradle.version.strategies.NewSemverV2Strategies

import static wooga.gradle.version.internal.release.semver.StrategyUtil.*

/**
* UPM-Specific strategies aimed at WDKs. Based on NewSemverV2Strategies,
* plus the same default stage as the older LegacyNuGetStrategies.
*/
class UpmStrategies {

/**
* Same as NewSemverV2Strategies.DEVELOPMENT plus LegacyNuGetStrategies.DEFAULT_SCOPE as a default in case no change scope is provided.
*/
static final SemVerStrategy DEVELOPMENT = NewSemverV2Strategies.DEVELOPMENT.copyWith(
normalStrategy: chainDefaultScope(NewSemverV2Strategies.DEVELOPMENT)
)
/**
* Same as NewSemverV2Strategies.SNAPSHOT plus LegacyNuGetStrategies.DEFAULT_SCOPE as a default in case no change scope is provided.
*/
static final SemVerStrategy SNAPSHOT = NewSemverV2Strategies.SNAPSHOT.copyWith(
normalStrategy: chainDefaultScope(NewSemverV2Strategies.SNAPSHOT)
)
/**
* Returns a version strategy to be used for {@code preflight} builds.
* <p>
* This strategy creates a wdk-specific preflight version based on Semver 2.0.
* The pre-release part of the version consists of the stage name(pre or preflight) and a timestamp (yyyyMMddHHmm), separated by dot(.).
* There are no metadata part in the generated versions.
* <p>
* Example:
<pre>
{@code
stage = "pre"
releaseScope = "minor"
nearestVersion = "1.3.0"
current date = 01/01/2022 10:10:30
inferred = "1.4.0-pre.202201011010"
}
*/
static final SemVerStrategy PREFLIGHT = NewSemverV2Strategies.SNAPSHOT.copyWith(
releaseStage: ReleaseStage.Preflight,
stages: ['pre', 'preflight'] as SortedSet,
normalStrategy: chainDefaultScope(NewSemverV2Strategies.SNAPSHOT),
preReleaseStrategy: all(
Strategies.PreRelease.STAGE_FIXED,
Strategies.PreRelease.withTimestamp(".")
),
)
/**
* Same as NewSemverV2Strategies.PRE_RELEASE plus LegacyNuGetStrategies.DEFAULT_SCOPE as a default in case no change scope is provided.
*/
static final SemVerStrategy PRE_RELEASE = NewSemverV2Strategies.PRE_RELEASE.copyWith(
normalStrategy: chainDefaultScope(NewSemverV2Strategies.PRE_RELEASE)
)
/**
* Same as NewSemverV2Strategies.FINAL plus LegacyNuGetStrategies.DEFAULT_SCOPE as a default in case no change scope is provided.
*/
static final SemVerStrategy FINAL = NewSemverV2Strategies.FINAL.copyWith(
normalStrategy: chainDefaultScope(NewSemverV2Strategies.FINAL)
)

private static PartialSemVerStrategy chainDefaultScope(SemVerStrategy base,
ChangeScope scope = LegacyNuGetStrategies.DEFAULT_SCOPE) {
return one(base.normalStrategy, Strategies.Normal.useScope(scope))
}
}
173 changes: 173 additions & 0 deletions src/test/groovy/wooga/gradle/version/NewSemverV1StrategySpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package wooga.gradle.version

import nebula.test.ProjectSpec
import org.ajoberstar.grgit.Grgit
import spock.lang.Unroll
import wooga.gradle.version.internal.release.semver.SemVerStrategy
import wooga.gradle.version.strategies.NewSemverV1Strategies

class NewSemverV1StrategySpec extends ProjectSpec {

public static final String PLUGIN_NAME = 'net.wooga.version'
static final IVersionScheme semverV1Scheme = new IVersionScheme() {
final SemVerStrategy development = NewSemverV1Strategies.DEVELOPMENT
final SemVerStrategy snapshot = NewSemverV1Strategies.SNAPSHOT
final SemVerStrategy preRelease = NewSemverV1Strategies.PRE_RELEASE
final SemVerStrategy finalStrategy = NewSemverV1Strategies.FINAL
final SemVerStrategy defaultStrategy = development
final List<SemVerStrategy> strategies = [development, snapshot, preRelease, finalStrategy]
}

Grgit git

def setup() {
new File(projectDir, '.gitignore') << """
userHome/
""".stripIndent()

git = Grgit.init(dir: projectDir)
git.add(patterns: ['.gitignore'])
git.commit(message: 'initial commit')
}

@Unroll('verify inferred new semver v1 version from nearestNormal: #nearestNormal, nearestAny: #nearestAnyTitle, scope: #scopeTitle, stage: #stage and branch: #branchName to be #expectedVersion')
def "uses custom wooga application strategies for new semver v1"() {
given: "a project with specified release stage and scope"

project.ext.set('release.stage', stage)
if (scope != _) {
project.ext.set('release.scope', scope)
}

and: "a history"

if (branchName != "master") {
git.checkout(branch: "$branchName", startPoint: 'master', createBranch: true)
}
if (nearestNormal != _) {
1.times {
git.commit(message: 'feature commit')
}
git.tag.add(name: "v$nearestNormal")
}

distance.times {
git.commit(message: 'fix commit')
}

if (nearestAny != _) {
git.tag.add(name: "v$nearestAny")
distance.times {
git.commit(message: 'fix commit')
}
}

if (expectedVersion?.contains("#COMMITHASH")) {
expectedVersion = expectedVersion.replace("#COMMITHASH", git.head().abbreviatedId)
}

when:
project.plugins.apply(PLUGIN_NAME)
and:
def versionExt = project.extensions.findByType(VersionPluginExtension)
def version = versionExt.inferVersion(semverV1Scheme)

then:
version.map { it.version.toString() }.orNull == expectedVersion

where:
nearestNormal | nearestAny | distance | stage | scope | branchName | expectedVersion
_ | _ | 2 | "snapshot" | "major" | "master" | "1.0.0-master00003"
_ | _ | 3 | "snapshot" | "minor" | "master" | "0.1.0-master00004"
_ | _ | 4 | "snapshot" | "patch" | "master" | "0.0.1-master00005"

'1.0.0' | _ | 2 | "snapshot" | "major" | "master" | "2.0.0-master00002"
'1.0.0' | _ | 3 | "snapshot" | "minor" | "master" | "1.1.0-master00003"
'1.0.0' | _ | 4 | "snapshot" | "patch" | "master" | "1.0.1-master00004"

'1.0.0' | _ | 2 | "snapshot" | "major" | "develop" | "2.0.0-branchDevelop00002"
'1.0.0' | _ | 3 | "snapshot" | "minor" | "develop" | "1.1.0-branchDevelop00003"
'1.0.0' | _ | 4 | "snapshot" | "patch" | "develop" | "1.0.1-branchDevelop00004"

'1.0.0' | _ | 7 | "snapshot" | "patch" | "PR-22" | "1.0.1-branchPRTwoTwo00007"

'0.0.1' | _ | 1 | "snapshot" | _ | "release/1.x" | "1.0.0-branchReleaseOneDotx00001"
'1.0.0' | _ | 1 | "snapshot" | "patch" | "release/1.x" | "1.0.1-branchReleaseOneDotx00001"
'1.0.0' | _ | 2 | "snapshot" | "patch" | "release-1.x" | "1.0.1-branchReleaseOneDotx00002"
'1.0.0' | _ | 3 | "snapshot" | _ | "release/1.1.x" | "1.1.0-branchReleaseOneDotOneDotx00003"
'1.0.0' | _ | 3 | "snapshot" | "patch" | "release/1.0.x" | "1.0.1-branchReleaseOneDotZeroDotx00003"
'1.0.0' | _ | 4 | "snapshot" | _ | "release-1.1.x" | "1.1.0-branchReleaseOneDotOneDotx00004"
'1.0.0' | _ | 4 | "snapshot" | "patch" | "release-1.0.x" | "1.0.1-branchReleaseOneDotZeroDotx00004"
'1.0.0' | '2.0.0-rc.2' | 0 | "snapshot" | _ | "release/2.x" | "2.0.0-branchReleaseTwoDotx00000"

'0.0.1' | _ | 1 | "snapshot" | _ | "1.x" | "1.0.0-branchOneDotx00001"
'1.0.0' | _ | 2 | "snapshot" | "patch" | "1.x" | "1.0.1-branchOneDotx00002"
'1.0.0' | _ | 3 | "snapshot" | _ | "1.1.x" | "1.1.0-branchOneDotOneDotx00003"
'1.0.0' | _ | 3 | "snapshot" | "patch" | "1.0.x" | "1.0.1-branchOneDotZeroDotx00003"

'1.0.0' | _ | 2 | "dev" | "major" | "master" | "2.0.0-dev.2+#COMMITHASH"
'1.0.0' | _ | 3 | "dev" | "minor" | "master" | "1.1.0-dev.3+#COMMITHASH"
'1.0.0' | _ | 4 | "dev" | "patch" | "master" | "1.0.1-dev.4+#COMMITHASH"

'0.0.1' | _ | 1 | "dev" | _ | "release/1.x" | "1.0.0-dev.1+#COMMITHASH"
'1.0.0' | _ | 1 | "dev" | "patch" | "release/1.x" | "1.0.1-dev.1+#COMMITHASH"
'1.0.0' | _ | 2 | "dev" | "patch" | "release-1.x" | "1.0.1-dev.2+#COMMITHASH"
'1.0.0' | _ | 3 | "dev" | _ | "release/1.1.x" | "1.1.0-dev.3+#COMMITHASH"
'1.0.0' | _ | 3 | "dev" | "patch" | "release/1.0.x" | "1.0.1-dev.3+#COMMITHASH"
'1.0.0' | _ | 4 | "dev" | _ | "release-1.1.x" | "1.1.0-dev.4+#COMMITHASH"
'1.0.0' | _ | 4 | "dev" | "patch" | "release-1.0.x" | "1.0.1-dev.4+#COMMITHASH"

'0.0.1' | _ | 1 | "dev" | _ | "1.x" | "1.0.0-dev.1+#COMMITHASH"
'1.0.0' | _ | 2 | "dev" | "patch" | "1.x" | "1.0.1-dev.2+#COMMITHASH"
'1.0.0' | _ | 3 | "dev" | _ | "1.1.x" | "1.1.0-dev.3+#COMMITHASH"
'1.0.0' | _ | 3 | "dev" | "patch" | "1.0.x" | "1.0.1-dev.3+#COMMITHASH"

'1.0.0' | _ | 2 | "rc" | "major" | "master" | "2.0.0-rc00001"
'1.0.0' | _ | 3 | "rc" | "minor" | "master" | "1.1.0-rc00001"
'1.0.0' | _ | 4 | "rc" | "patch" | "master" | "1.0.1-rc00001"

'1.0.0' | '1.1.0-rc00001' | 1 | "rc" | _ | "master" | "1.1.0-rc00002"
'1.0.0' | '1.1.0-rc00002' | 1 | "rc" | _ | "master" | "1.1.0-rc00003"

'0.0.1' | _ | 1 | "rc" | _ | "release/1.x" | "1.0.0-rc00001"
'1.0.0' | _ | 3 | "rc" | _ | "release/1.1.x" | "1.1.0-rc00001"
'1.0.0' | _ | 4 | "rc" | _ | "release-1.1.x" | "1.1.0-rc00001"
'1.0.0' | _ | 1 | "rc" | "patch" | "release/1.x" | "1.0.1-rc00001"
'1.0.0' | _ | 2 | "rc" | "patch" | "release-1.x" | "1.0.1-rc00001"
'1.0.0' | _ | 3 | "rc" | "patch" | "release/1.0.x" | "1.0.1-rc00001"
'1.0.0' | _ | 4 | "rc" | "patch" | "release-1.0.x" | "1.0.1-rc00001"

'0.0.1' | "1.0.0-rc00001" | 1 | "rc" | _ | "release/1.x" | "1.0.0-rc00002"
'1.0.0' | "1.1.0-rc00001" | 3 | "rc" | _ | "release/1.1.x" | "1.1.0-rc00002"
'1.0.0' | '2.0.0-master00002' | 0 | "rc" | _ | "release/2.x" | "2.0.0-rc00001"

'0.0.1' | _ | 1 | "rc" | _ | "1.x" | "1.0.0-rc00001"
'1.0.0' | _ | 3 | "rc" | _ | "1.1.x" | "1.1.0-rc00001"
'1.0.0' | _ | 2 | "rc" | "patch" | "1.x" | "1.0.1-rc00001"
'1.0.0' | _ | 3 | "rc" | "patch" | "1.0.x" | "1.0.1-rc00001"

'0.0.1' | "1.0.0-rc00001" | 0 | "rc" | _ | "1.x" | "1.0.0-rc00002"
'1.0.0' | "1.1.0-rc00001" | 3 | "rc" | _ | "1.1.x" | "1.1.0-rc00002"

'1.0.0' | _ | 2 | "final" | "major" | "master" | "2.0.0"
'1.0.0' | _ | 3 | "final" | "minor" | "master" | "1.1.0"
'1.0.0' | _ | 4 | "final" | "patch" | "master" | "1.0.1"

'0.0.1' | _ | 1 | "final" | _ | "release/1.x" | "1.0.0"
'1.0.0' | _ | 1 | "final" | "patch" | "release/1.x" | "1.0.1"
'1.0.0' | _ | 2 | "final" | "patch" | "release-1.x" | "1.0.1"
'1.0.0' | _ | 3 | "final" | _ | "release/1.1.x" | "1.1.0"
'1.0.0' | _ | 3 | "final" | "patch" | "release/1.0.x" | "1.0.1"
'1.0.0' | _ | 4 | "final" | _ | "release-1.1.x" | "1.1.0"
'1.0.0' | _ | 4 | "final" | "patch" | "release-1.0.x" | "1.0.1"

'0.0.1' | _ | 1 | "final" | _ | "1.x" | "1.0.0"
'1.0.0' | _ | 2 | "final" | "patch" | "1.x" | "1.0.1"
'1.0.0' | _ | 3 | "final" | _ | "1.1.x" | "1.1.0"
'1.0.0' | _ | 3 | "final" | "patch" | "1.0.x" | "1.0.1"


nearestAnyTitle = (nearestAny == _) ? "unset" : nearestAny
scopeTitle = (scope == _) ? "unset" : scope
}
}
Loading

0 comments on commit 1e12cef

Please sign in to comment.