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

Commit

Permalink
Fix Snapshot branchname strategy (#50)
Browse files Browse the repository at this point in the history
Description
===========

The `PartialSemVerStrategy` `STAGE_BRANCH_NAME` tries to generate a
unique semver 2.0 prerelease pattern. The provided tests where mostly
written in an optimistic fashion. This patch fixes the strategy when
branch names are in use which contain unusual characters or character
combinations.

As an example:

The branchName `feature/button_01` would yield a prerelease part of:
`branch.feature.button.01` which is not semver 2 compatible. Numerical
parts are not allowed to be `0` padded. The strategy also kept hanging
characters like `-`,`+`,`_`.

This patch tries to fix this cases.

_excerpt from the tests in `ReleasePluginSpec`

```
_  | 10   | "ci"  | _  | "test/build01-"            | "1.1.0-branch.test.build.1.10"
_  | 22   | "ci"  | _  | "test/build01+"            | "1.1.0-branch.test.build.1.22"
_  | 45   | "ci"  | _  | "test/build01_"            | "1.1.0-branch.test.build.1.45"
_  | 204  | "ci"  | _  | "test/build01"             | "1.1.0-branch.test.build.1.204"
_  | 100  | "ci"  | _  | "test/build.01"            | "1.1.0-branch.test.build.1.100"
_  | 55   | "ci"  | _  | "test/build002"            | "1.1.0-branch.test.build.2.55"
_  | 66   | "ci"  | _  | "test/build.002"           | "1.1.0-branch.test.build.2.66"
_  | 789  | "ci"  | _  | "test/build000000000003"   | "1.1.0-branch.test.build.3.789"
_  | 777  | "ci"  | _  | "test/build.000000000003"  | "1.1.0-branch.test.build.3.777"
_  | 789  | "ci"  | _  | "test/build000000.000003"  | "1.1.0-branch.test.build.0.3.789"
_  | 3    | "ci"  | _  | "test/build.000000.000003" | "1.1.0-branch.test.build.0.3.3"
_  | 3    | "ci"  | _  | "release/1.00.x"           | "1.0.1-branch.release.1.0.x.3"
```

Changes
=======

![FIX] Snapshot branchname strategy
  • Loading branch information
Larusso authored Jun 3, 2020
1 parent f1ecf75 commit 775a39b
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,19 @@ final class VersionStrategies {
if (branchName != "master" && branchName != "develop") {
branchName = "$prefix.${branchName.toLowerCase()}"
}

//Split at branch delimiter /-_+ and replace with .
branchName = branchName.replaceAll(/((\/|-|_|\.)+)([\w])/) { all, delimiterAll, delimiter , firstAfter -> ".${firstAfter}" }
//Remove all hanging /-_+
branchName = branchName.replaceAll(/[-\/_\+]+$/) { "" }
//parse all digits and replace with unpadded value e.g. 001 -> 1
branchName = branchName.replaceAll(/([\w\.])([0-9]+)/) { all, s, delimiter ->
if(s == ".") {
s = ""
}

"${s}.${Integer.parseInt(delimiter).toString()}"
}

state.copyWith(inferredPreRelease: branchName)
}
Expand Down
Loading

0 comments on commit 775a39b

Please sign in to comment.