From ec338bee6a1da4f3f24e599e5007f1af292cca26 Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 17 Jul 2024 15:01:00 +0200 Subject: [PATCH 1/4] version is now 1.0.0-alpha.4-SNAPSHOT --- librarian.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/librarian.properties b/librarian.properties index ae079c1..482c14a 100644 --- a/librarian.properties +++ b/librarian.properties @@ -7,7 +7,7 @@ kdoc.artifactId=kdoc sonatype.backend=S01 pom.groupId=io.openfeedback -pom.version=1.0.0-alpha.3 +pom.version=1.0.0-alpha.4-SNAPSHOT pom.description=openfeedback-sdk-kotlin pom.vcsUrl=https://github.com/paug/openfeedback-sdk-kotlin pom.developer=openfeedback-sdk-kotlin authors From ce258d7b74d122001a3131ecda1804ad3e52ee66 Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 17 Jul 2024 14:56:26 +0200 Subject: [PATCH 2/4] chore: update version file in release script. --- scripts/release.main.kts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/release.main.kts b/scripts/release.main.kts index 589b6de..e741112 100755 --- a/scripts/release.main.kts +++ b/scripts/release.main.kts @@ -23,15 +23,15 @@ fun runCommand(vararg args: String): String { } fun setCurrentVersion(version: String) { - val gradleProperties = File("build.gradle.kts") + val gradleProperties = File("librarian.properties") val newContent = gradleProperties.readLines().map { - it.replace(Regex("version = .*"), "version = \"$version\"") + it.replace(Regex("pom.version=.*"), "pom.version=\"$version\"") }.joinToString(separator = "\n", postfix = "\n") gradleProperties.writeText(newContent) } fun getCurrentVersion(): String { - val versionLines = File("build.gradle.kts").readLines().filter { it.startsWith("version =") } + val versionLines = File("librarian.properties").readLines().filter { it.startsWith("pom.version=") } require(versionLines.isNotEmpty()) { "cannot find the version in ./gradle.properties" @@ -41,7 +41,7 @@ fun getCurrentVersion(): String { "multiple versions found in ./gradle.properties" } - val regex = Regex("version = \"(.*)-SNAPSHOT\"") + val regex = Regex("pom.version=(.*)-SNAPSHOT") val matchResult = regex.matchEntire(versionLines.first()) require(matchResult != null) { From 962d85a75c33e2c057aaf382be94eddd2f033ba7 Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 17 Jul 2024 15:45:41 +0200 Subject: [PATCH 3/4] chore: support prerelease format in release script. --- scripts/release.main.kts | 73 ++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/scripts/release.main.kts b/scripts/release.main.kts index e741112..c8c1d16 100755 --- a/scripts/release.main.kts +++ b/scripts/release.main.kts @@ -51,14 +51,31 @@ fun getCurrentVersion(): String { return matchResult.groupValues[1] } -fun getNext(version: String, position: Int) = version.split(".").mapIndexed { index, s -> - when { - index == position -> (s.toInt() + 1).toString() - index > position -> "0" - else -> s +val versionRegex = Regex("(?[0-9]+)\\.(?[0-9]+)\\.(?[0-9]+)(-(?alpha|beta)\\.(?[0-9]+))?(-SNAPSHOT)?") +fun getNext(version: String, position: Int): String { + val groupName = when (position) { + 0 -> "major" + 1 -> "minor" + 2 -> "patch" + 3 -> "prerelease" + else -> throw IllegalArgumentException("position must be 0, 1, 2 or 3") } -}.joinToString(".") + return version.replace(versionRegex) { + when (groupName) { + "major" -> "${it.groups["major"]!!.value.toInt() + 1}.0.0" + "minor" -> "${it.groups["major"]!!.value}.${it.groups["minor"]!!.value.toInt() + 1}.0" + "patch" -> "${it.groups["major"]!!.value}.${it.groups["minor"]!!.value}.${it.groups["patch"]!!.value.toInt() + 1}" + "prerelease" -> { + val prereleaseName = it.groups["prereleaseName"]?.value ?: "alpha" + val newPrerelease = (it.groups["prerelease"]?.value?.toInt() ?: 0) + 1 + "${it.groups["major"]!!.value}.${it.groups["minor"]!!.value}.${it.groups["patch"]!!.value}-$prereleaseName.$newPrerelease" + } + else -> throw IllegalArgumentException("unknown group $groupName") + } + } +} +fun getNextPreRelease(version: String) = getNext(version, 3) fun getNextPatch(version: String) = getNext(version, 2) fun getNextMinor(version: String) = getNext(version, 1) fun getNextMajor(version: String) = getNext(version, 0) @@ -69,26 +86,47 @@ if (runCommand("git", "status", "--porcelain").isNotEmpty()) { } val version = getCurrentVersion() +val nextPreRelease = getNextPreRelease(version) val nextPatch = getNextPatch(version) val nextMinor = getNextMinor(version) -val nextPatchAfterMinor = getNextPatch(nextMinor) +val nextMinorAfterMinor = getNextMinor(nextMinor) val nextMajor = getNextMajor(version) -val nextPatchAfterMajor = getNextPatch(nextMajor) +val nextMinorAfterMajor = getNextMinor(nextMajor) var tagVersion: String = "" +var nextSnapshot: String = "" while (tagVersion.isEmpty()) { println("Current version is '$version-SNAPSHOT'.") - println("1. patch: tag $version and bump to $nextPatch-SNAPSHOT") - println("2. minor: tag $nextMinor and bump to $nextPatchAfterMinor-SNAPSHOT") - println("3. major: tag $nextMajor and bump to $nextPatchAfterMajor-SNAPSHOT") - println("What do you want to do [1/2/3]?") + println("1. current: tag $version and bump to $nextMinor-SNAPSHOT") + println("2. prerelease: tag $version and bump to $nextPreRelease-SNAPSHOT") + println("3. patch: tag $nextPatch and bump to $nextMinor-SNAPSHOT") + println("4. minor: tag $nextMinor and bump to $nextMinorAfterMinor-SNAPSHOT") + println("5. major: tag $nextMajor and bump to $nextMinorAfterMajor-SNAPSHOT") + println("What do you want to do [1/2/3/4/5]?") val answer = readLine()!!.trim() when (answer) { - "1" -> tagVersion = version - "2" -> tagVersion = nextMinor - "3" -> tagVersion = nextMajor + "1" -> { + tagVersion = version + nextSnapshot = "$nextMinor-SNAPSHOT" + } + "2" -> { + tagVersion = version + nextSnapshot = "$nextPreRelease-SNAPSHOT" + } + "3" -> { + tagVersion = nextPatch + nextSnapshot = "$nextMinor-SNAPSHOT" + } + "4" -> { + tagVersion = nextMinor + nextSnapshot = "$nextMinorAfterMinor-SNAPSHOT" + } + "5" -> { + tagVersion = nextMajor + nextSnapshot = "$nextMinorAfterMajor-SNAPSHOT" + } } } @@ -97,8 +135,7 @@ setCurrentVersion(tagVersion) runCommand("git", "commit", "-a", "-m", "release $tagVersion") runCommand("git", "tag", "v$tagVersion") -val snapshot = "${getNextPatch(tagVersion)}-SNAPSHOT" -setCurrentVersion(snapshot) -runCommand("git", "commit", "-a", "-m", "version is now $snapshot") +setCurrentVersion(nextSnapshot) +runCommand("git", "commit", "-a", "-m", "version is now $nextSnapshot") println("Everything is done. Verify everything is ok and type `git push origin master` to trigger the new version.") From 62dfd1031a4f223aa1391b697cdbf79e108a832f Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 17 Jul 2024 16:06:11 +0200 Subject: [PATCH 4/4] docs: migrate releasing instructions to RELEASING.md file. --- CONTRIBUTING.md | 6 ------ RELEASING.md | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 RELEASING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 758c5a7..578556b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,3 @@ Thanks for contributing to openfeedback-android-sdk - -## Releases - -Releases are made automatically from CI every time a tag is pushed. - -Run `./scripts/release.main.kts` to start a new release \ No newline at end of file diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..3571c1f --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,5 @@ +## Releases + +Releases are made automatically from CI every time a tag is pushed. + +Run `./scripts/release.main.kts` to start a new release