Skip to content

Commit

Permalink
Changelog. Support passing a range (#5188)
Browse files Browse the repository at this point in the history
Needed for 1.7.2:
```
kotlin changelog.main.kts v1.7.1..release/1.7.2
```

Otherwise it compares with `1.8.0-alpha01`

---------

Co-authored-by: Ivan Matkov <[email protected]>
  • Loading branch information
igordmn and MatkovIvan authored Dec 17, 2024
1 parent a093ae6 commit 293bd1b
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions tools/changelog.main.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/**
* Script for creating a changelog. Call:
* ```
* kotlin changelog.main.kts release/1.6.0 1.6.0-rc02
* kotlin changelog.main.kts v1.7.0-dev555
* ```
* or:
* ```
* kotlin changelog.main.kts v1.7.0..v1.7.1-dev555
* ```
* where:
* release/1.6.0 - the commit of the version
* 1.6.0-rc02 - the name of the version
* v1.7.0-dev555 - the tag/branch of the version. The previous version will be read from CHANGELOG.md
* v1.7.0..1.7.1-dev555 - the range of tag/branches for the changelog
*
* It modifies CHANGELOG.md and adds new changes between the last version in CHANGELOG.md and the specified version.
*
Expand Down Expand Up @@ -74,18 +78,37 @@ val argsKeyToValue = args
.filter { it.contains("=") }
.associate { it.substringBefore("=") to it.substringAfter("=") }

val versionCommit = argsKeyless.getOrNull(0) ?: "HEAD"
val commitsArg = argsKeyless.getOrNull(0) ?: "HEAD"

var previousVersionCommitArg: String?
var versionCommitArg: String
if (commitsArg.contains("..")) {
previousVersionCommitArg = commitsArg.substringBefore("..")
versionCommitArg = commitsArg.substringAfter("..")
} else {
previousVersionCommitArg = null
versionCommitArg = commitsArg
}

val versionCommit = versionCommitArg

val token = argsKeyToValue["token"]

println("Note. The script supports optional arguments: kotlin changelog.main.kts [versionCommit] [versionName] [token=githubToken]")
println("Note. The script supports optional arguments: kotlin changelog.main.kts [previousVersionCommit..versionCommit] [token=githubToken]")
if (token == null) {
println("To increase the rate limit, specify token (https://github.com/settings/tokens)")
}
println()

val androidxLibToPreviousVersion = previousVersionCommitArg?.let(::androidxLibToVersion)
val androidxLibToVersion = androidxLibToVersion(versionCommit)
val androidxLibToRedirectingVersion = androidxLibToRedirectingVersion(versionCommit)

fun formatAndroidxLibPreviousVersion(libName: String) =
androidxLibToPreviousVersion?.get(libName) ?: "PLACEHOLDER".also {
println("Can't find $libName previous version. Using PLACEHOLDER")
}

fun formatAndroidxLibVersion(libName: String) =
androidxLibToVersion[libName] ?: "PLACEHOLDER".also {
println("Can't find $libName version. Using PLACEHOLDER")
Expand Down Expand Up @@ -120,12 +143,21 @@ val previousChangelog =
currentChangelog
}

val previousVersion = previousChangelog.substringAfter("# ").substringBefore(" (")
var previousVersionCommit: String
var previousVersion: String
if (previousVersionCommitArg != null) {
previousVersionCommit = previousVersionCommitArg!!
previousVersion = formatAndroidxLibPreviousVersion("COMPOSE")
} else {
val previousVersionInChangelog = previousChangelog.substringAfter("# ").substringBefore(" (")
previousVersionCommit = "v$previousVersionInChangelog"
previousVersion = previousVersionInChangelog
}

println()
println("Generating changelog between $previousVersion and $versionName")

val newChangelog = getChangelog("v$previousVersion", versionCommit, previousVersion)
val newChangelog = getChangelog(previousVersionCommit, versionCommit, previousVersion)

changelogFile.writeText(
newChangelog + previousChangelog
Expand Down Expand Up @@ -521,4 +553,4 @@ inline fun <T> fetchPagedUntilEmpty(fetch: (page: Int) -> List<T>): MutableList<
return all
}

//endregion
//endregion

0 comments on commit 293bd1b

Please sign in to comment.