Skip to content

Commit

Permalink
Prepare for release 0.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisCAD committed Aug 21, 2020
1 parent c0354bd commit c39409b
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 4 deletions.
114 changes: 114 additions & 0 deletions Apollo_releasing.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env kotlin

import java.io.File

/**
* A script to run locally in order to make a release.
*
* You need kotlin 1.3.70+ installed on your machine
*/

fun runCommand(vararg args: String): String {
val builder = ProcessBuilder(*args)
.redirectError(ProcessBuilder.Redirect.INHERIT)

val process = builder.start()
val ret = process.waitFor()

val output = process.inputStream.bufferedReader().readText()
if (ret != 0) {
throw java.lang.Exception("command ${args.joinToString(" ")} failed:\n$output")
}

return output
}

fun setCurrentVersion(version: String) {
val gradleProperties = File("gradle.properties")
var newContent = gradleProperties.readLines().map {
it.replace(Regex("VERSION_NAME=.*"), "VERSION_NAME=$version")
}.joinToString(separator = "\n", postfix = "\n")
gradleProperties.writeText(newContent)

val dependencies = File("gradle/dependencies.gradle")
// apollo : '1.2.2', // This should only be used by apollo-gradle-plugin-incubating:test to get the artifacts locally
newContent = dependencies.readLines().map {
it.replace(Regex("( *apollo *: *').*('.*)")) {
"${it.groupValues[1]}$version${it.groupValues[2]}"
}
}.joinToString(separator = "\n", postfix = "\n")
dependencies.writeText(newContent)
}

fun getCurrentVersion(): String {
val versionLines = File("gradle.properties").readLines().filter { it.startsWith("VERSION_NAME=") }

require(versionLines.size > 0) {
"cannot find the version in ./gradle.properties"
}

require(versionLines.size == 1) {
"multiple versions found in ./gradle.properties"
}

val regex = Regex("VERSION_NAME=(.*)-SNAPSHOT")
val matchResult = regex.matchEntire(versionLines.first())

require(matchResult != null) {
"'${versionLines.first()}' doesn't match VERSION_NAME=(.*)-SNAPSHOT"
}

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
}
}.joinToString(".")

fun getNextPatch(version: String) = getNext(version, 2)
fun getNextMinor(version: String) = getNext(version, 1)
fun getNextMajor(version: String) = getNext(version, 0)

if (runCommand("git", "status", "--porcelain").isNotEmpty()) {
println("Your git repo is not clean. Make sur to stash or commit your changes before making a release")
System.exit(1)
}

val version = getCurrentVersion()
val nextPatch = getNextPatch(version)
val nextMinor = getNextMinor(version)
val nextPatchAfterMinor = getNextPatch(nextMinor)
val nextMajor = getNextMajor(version)
val nextPatchAfterMajor = getNextPatch(nextMajor)

var tagVersion: String = ""

while (tagVersion.isEmpty()) {
println("Current version is '$version-SNAPSHOT'.")
println("1. patch: tag $version and bump to $nextPatch")
println("2. minor: tag $nextMinor and bump to $nextPatchAfterMinor")
println("3. major: tag $nextMajor and bump to $nextPatchAfterMajor")
println("What do you want to do [1/2/3]?")

val answer = readLine()!!.trim()
when (answer) {
"1" -> tagVersion = version
"2" -> tagVersion = nextMinor
"3" -> tagVersion = nextMajor
}
}

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")

println("Everything is done. Verify everything is ok and type `git push origin master` to trigger the new version.")
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Change log for refreshVersions

<!--## Version 0.9.5 (2020-08-??)-->
## [Unreleased]
## Version 0.9.5 (2020-08-21)

This is a **major release** that brings surface-level and internal changes, paving the way for the upcoming 1.0 release.

Expand Down
11 changes: 11 additions & 0 deletions TODO_libs_for_publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Priority

- Find a way to keep track of the previous dev versions without is being overwritten by non stable releases.
- Make a script for dev versions.

## Other
- Open files (with text editor command defaulting to `idea`)

- Get new version string based on last version(s) and channel(s)
- Update version in README (check side-effects are almost impossible)

2 changes: 1 addition & 1 deletion docs/Setting-up.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:sectanchors:
:gradle_version: 6.4.1
:last_version: 0.9.5
:last_dev_version: 0.9.5-dev-006
:last_dev_version: 0.9.5-dev-017
:buildSrc_doc: https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources
:included_builds_support: https://github.com/jmfayard/refreshVersions/issues/205

Expand Down
2 changes: 1 addition & 1 deletion plugins/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.5-SNAPSHOT
0.9.5
3 changes: 3 additions & 0 deletions sample-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ buildscript {

plugins {
kotlin("jvm")
id("org.gradle.hello-world")
//id("io.gitlab.arturbosch.detekt") apply false
}

group = "de.fayard"
Expand Down Expand Up @@ -47,6 +49,7 @@ dependencies {

api("org.apache.poi:poi:_")
api("org.apache.poi:poi-ooxml:_")
//detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:_")
}

tasks.register("run", JavaExec::class.java) {
Expand Down
2 changes: 2 additions & 0 deletions sample-kotlin/refreshVersions-extra-rules.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
org.apache.poi:poi(-*)
^^^^^^.^^^
io.gitlab.arturbosch.detekt:detekt(-*)
^^^^^^
11 changes: 11 additions & 0 deletions sample-kotlin/versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
## Generated by $ ./gradlew refreshVersions
## Please, don't put extra comments in that file yet, keeping them is not supported yet.

plugin.io.gitlab.arturbosch.detekt=version.detekt

plugin.org.gradle.hello-world=0.1
## # available=0.2

plugin.org.gradle.hello-world=version.org.gradle..gradle-hello-world-plugin

version.androidx.browser=1.0.0
## # available=1.2.0-alpha07
## # available=1.2.0-alpha08
Expand All @@ -22,6 +29,7 @@ version.androidx.cardview=1.0.0
version.androidx.core=1.3.1
## # available=1.4.0-alpha01
## # available=1.5.0-alpha01
## # available=1.5.0-alpha02

version.apache.poi=4.0.0
## # available=4.0.1
Expand All @@ -32,6 +40,8 @@ version.apache.poi=4.0.0
version.kotest=4.1.3
## # available=4.2.0.RC1
## # available=4.2.0.RC2
## # available=4.2.0.RC3
## # available=4.2.0

version.kotlin=1.3.72
## # available=1.4-M1
Expand All @@ -45,6 +55,7 @@ version.kotlinx.coroutines=1.3.8
## # available=1.3.8-1.4-rc-154
## # available=1.3.8-1.4.0-rc
## # available=1.3.8-1.4.0-rc-218
## # available=1.3.9-native-mt
## # available=1.3.9

version.org.gradle..gradle-hello-world-plugin=0.1
Expand Down

0 comments on commit c39409b

Please sign in to comment.