Skip to content

Commit

Permalink
release/v1.5.0 (#94)
Browse files Browse the repository at this point in the history
* tweak release.main.kts

- adjust default next version
- make buildGradleKts lazy
- use `exitProcess()`
- add `\n` suffix to `build.gradle.kts`
- use `./gradlew` instead of `gradlew`
- adjust release branch name
- forward IO for processes
- additional logging
- Gradle --no-daemon
- prompt for nextVersion
- set gh repo

* release 1.5.0
  • Loading branch information
aSemy authored Jun 14, 2023
1 parent b531e50 commit 156d9a4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "dev.adamko.dokkatoo"
version = "1.5.0-SNAPSHOT"
version = "1.5.0"


idea {
Expand Down
76 changes: 48 additions & 28 deletions devOps/release.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
import Release_main.SemVer.Companion.SemVer
import com.github.ajalt.clikt.core.CliktCommand
import java.io.File
import java.lang.ProcessBuilder.Redirect.INHERIT
import java.lang.ProcessBuilder.Redirect.PIPE
import kotlin.system.exitProcess
import me.alllex.parsus.parser.*
import me.alllex.parsus.token.literalToken
import me.alllex.parsus.token.regexToken

try {
Release.main(args)
exitProcess(0)
} catch (ex: Exception) {
println("${ex::class.simpleName}: ${ex.message}")
exitProcess(1)
}

/**
* Release a new version.
*
Expand All @@ -34,36 +43,44 @@ object Release : CliktCommand() {
check(startBranch == "main") {
"Must be on the main branch to make a release, but current branch is $startBranch"
}
gh.setRepo("adamko-dev/dokkatoo")
//endregion

echo("Current version is $currentVersion")
echo("git dir is ${git.rootDir}")

val versionToRelease = prompt(
val releaseVersion = prompt(
text = "version to release?",
default = currentVersion.incrementMinor(snapshot = false).toString(),
default = currentVersion.copy(snapshot = false).toString(),
requireConfirmation = true,
) {
SemVer.of(it)
} ?: error("invalid SemVer")

check(!versionToRelease.snapshot) {
"versionToRelease must not be a snapshot version, but was $versionToRelease"
check(!releaseVersion.snapshot) {
"versionToRelease must not be a snapshot version, but was $releaseVersion"
}

val nextVersion = versionToRelease.incrementMinor(snapshot = true)
val nextVersion = prompt(
text = "post-release version?",
default = releaseVersion.incrementMinor(snapshot = true).toString(),
requireConfirmation = true,
) {
SemVer.of(it)
} ?: error("invalid SemVer")

echo("Current version is $currentVersion")
confirm("Release $versionToRelease and bump to $nextVersion?", abort = true)
confirm("Release $releaseVersion and bump to $nextVersion?", abort = true)

updateAndRelease(versionToRelease)
updateAndRelease(releaseVersion)

// Tag the release
git.checkout(startBranch)
git.pull(startBranch)
require(currentVersion == versionToRelease) {
"incorrect version after update. Expected $versionToRelease but got $currentVersion"
require(currentVersion == releaseVersion) {
"incorrect version after update. Expected $releaseVersion but got $currentVersion"
}
val tagName = "v$versionToRelease"
val tagName = "v$releaseVersion"
git.tag(tagName)
confirm("Push tag $tagName?", abort = true)
git.push(tagName)
Expand All @@ -76,23 +93,28 @@ object Release : CliktCommand() {
git.checkout(startBranch)
git.pull(startBranch)

echo("Released version $versionToRelease")
echo("Released version $releaseVersion")
}

private fun updateAndRelease(version: SemVer) {
// checkout a release branch
val releaseBranch = "release-$version"
val releaseBranch = "release/v$version"
echo("checkout out new branch...")
git.checkout(releaseBranch)

// update the version & run tests
currentVersion = version
echo("running Gradle check...")
gradle.check()

// commit and push
echo("committing...")
git.commit("release $version")
echo("pushing...")
git.push(releaseBranch)

// create a new PR
echo("creating PR...")
gh.createPr(releaseBranch)

confirm("Merge the PR for branch $releaseBranch?", abort = true)
Expand Down Expand Up @@ -120,11 +142,14 @@ object Release : CliktCommand() {

/** GitHub commands */
private val gh = object {
fun setRepo(repo: String): String =
runCommand("gh repo set-default $repo")

fun prState(branchName: String): String =
runCommand("gh pr view $branchName --json state --jq .state")

fun createPr(branch: String): String =
runCommand("gh pr create --base $branch --fill")
runCommand("gh pr create --head $branch --fill")

fun autoMergePr(branch: String): String =
runCommand("gh pr merge $branch --squash --auto --delete-branch")
Expand All @@ -135,19 +160,17 @@ object Release : CliktCommand() {

/** GitHub commands */
private val gradle = object {
fun check(): String = runCommand("gradlew check")
fun check(): String = runCommand("./gradlew check --no-daemon")
}

// private val currentDir: String get() = System.getProperty("user.dir")

private val buildGradleKts: File
get() {
val rootDir = git.rootDir
echo("rootDir: $rootDir")
return File("$rootDir/build.gradle.kts").apply {
require(exists()) { "could not find build.gradle.kts in ${git.rootDir}" }
}
private val buildGradleKts: File by lazy {
val rootDir = git.rootDir
File("$rootDir/build.gradle.kts").apply {
require(exists()) { "could not find build.gradle.kts in $rootDir" }
}
}

private fun runCommand(
cmd: String,
Expand All @@ -156,7 +179,8 @@ object Release : CliktCommand() {
val args = parseSpaceSeparatedArgs(cmd)

val process = ProcessBuilder(*args.toTypedArray()).apply {
redirectError(INHERIT)
redirectOutput(PIPE)
redirectError(PIPE)
if (dir != null) directory(dir)
}.start()

Expand Down Expand Up @@ -185,7 +209,7 @@ object Release : CliktCommand() {
}
set(value) {
val updatedFile = buildGradleKts.useLines { lines ->
lines.joinToString("\n") { line ->
lines.joinToString(separator = "\n", postfix = "\n") { line ->
if (line.startsWith("version = ")) {
"version = \"${value}\""
} else {
Expand Down Expand Up @@ -237,10 +261,6 @@ object Release : CliktCommand() {
}
}


Release.main(args)


private data class SemVer(
val major: Int,
val minor: Int,
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-format-example/dokkatoo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm") version "1.8.22"
id("dev.adamko.dokkatoo") version "1.5.0-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.5.0"
}

dokkatoo {
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-example/dokkatoo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm") version "1.8.22"
id("dev.adamko.dokkatoo") version "1.5.0-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.5.0"
}

dokkatoo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ plugins {

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22")
implementation("dev.adamko.dokkatoo:dokkatoo-plugin:1.5.0-SNAPSHOT")
implementation("dev.adamko.dokkatoo:dokkatoo-plugin:1.5.0")
}
2 changes: 1 addition & 1 deletion examples/multiplatform-example/dokkatoo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("multiplatform") version "1.8.22"
id("dev.adamko.dokkatoo") version "1.5.0-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.5.0"
}

group = "org.dokka.example"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("com.android.library") version "4.2.2"
kotlin("android") version "1.8.22"
id("dev.adamko.dokkatoo") version "1.5.0-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.5.0"
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dev.adamko.dokkatoo.dokka.plugins.DokkaHtmlPluginParameters

plugins {
kotlin("jvm") version "1.8.22"
id("dev.adamko.dokkatoo") version "1.5.0-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.5.0"
}

version = "1.8.20-SNAPSHOT"
Expand Down

0 comments on commit 156d9a4

Please sign in to comment.