Skip to content

Commit

Permalink
#3 Change default git tag pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Zhdanov committed Dec 24, 2024
1 parent 5af112e commit ee956d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Example:
```
* the plugin commits the changes in *build.gradle.kts* and *RELEASE_NOTES.md* into git
* the plugin creates git tag `release-3.6.0` from the current sources
* the plugin creates git tag `v3.6.0` from the current sources
## Table of Contents
Expand Down Expand Up @@ -196,7 +196,7 @@ Which will create a tag with this format:
```v1.0.0```
Do remember that the character `%s` must be provided as the place for the version. If `tagPattern` does not defined, default pattern
will be `release-%s` which will create a tag with this format:
will be `v%s` which will create a tag with this format:
```release-1.0.0```
```v1.0.0```
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class GradleReleasePaperworkPlugin : Plugin<Project> {
val SEMVER_WITH_PRE_RELEASE_BUILD_REGEX = """(\d+)\.(\d+)\.(\d+)-(.+)""".toRegex()
val SEMVER_WITHOUT_BUILD_REGEX = """(\d+)\.(\d+)\.(\d+)""".toRegex()
const val DEFAULT_RELEASE_NOTES_FILE = "RELEASE_NOTES.md"
const val DEFAULT_RELEASE_COMMIT_MESSAGE_PATTERN = "release-%s"
const val DEFAULT_RELEASE_COMMIT_MESSAGE_PATTERN = "v%s"
const val RELEASE_DESCRIPTION_FORMAT = "v<version> released on <date><additional-release-description>"
const val COMMIT_DESCRIPTION_FORMAT = " * <commit-hash> <commit-description>"
val COMMIT_DESCRIPTION_SUFFIX_REGEX = """\s+\*\s+""".toRegex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ internal class GradleReleasePaperworkPluginTest {
assertThat(paths).contains(expectedPath.toString())
}

private fun verifyTagExists(tagName: String) {
val availableTags = mutableListOf<String>()
val tag = git.tagList().call().find {
val actual = it.name.substring("refs/tags/".length)
availableTags += actual
actual == tagName
}
assertThat(tag)
.describedAs("tag '$tagName' does not exist, available tags: ${availableTags.joinToString()}")
.isNotNull
}

@Test
fun `when no version is defined in gradle file then the build fails`() {
verifyFailure("can't extract project version")
Expand Down Expand Up @@ -162,6 +174,7 @@ internal class GradleReleasePaperworkPluginTest {
* ${getCommitDescriptionInNotes(commit1message)}
""".trimIndent())
verifyTagExists("v$version")
}

@Test
Expand Down Expand Up @@ -480,16 +493,11 @@ internal class GradleReleasePaperworkPluginTest {

private fun prepareAndRunTagPatternTest(
gradleFileContent: String,
expectedResult: String,
expectedTagName: String,
) {
gradleFile.appendText(gradleFileContent)
runBuild()

val tag = git.tagList().call().find {
val actual = it.name.substring("refs/tags/".length)
actual == expectedResult
}
assertThat(tag).isNotNull
verifyTagExists(expectedTagName)
}

@Test
Expand All @@ -508,7 +516,7 @@ internal class GradleReleasePaperworkPluginTest {
@Test
fun `when release is made and tagPattern is defined then tag is created and named using tagPattern`() {
val version = "1.0.0"
val pattern = "v%s"
val pattern = "release-%s"
val content = """
version = "$version"
Expand Down

0 comments on commit ee956d1

Please sign in to comment.