Browse Source

Changelog. Support passing a range (#5188)

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 <ivan.matkov@jetbrains.com>
pull/5174/merge
Igor Demin 2 days ago committed by GitHub
parent
commit
293bd1b2b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 46
      tools/changelog.main.kts

46
tools/changelog.main.kts

@ -1,11 +1,15 @@
/** /**
* Script for creating a changelog. Call: * 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: * where:
* release/1.6.0 - the commit of the version * v1.7.0-dev555 - the tag/branch of the version. The previous version will be read from CHANGELOG.md
* 1.6.0-rc02 - the name of the version * 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. * It modifies CHANGELOG.md and adds new changes between the last version in CHANGELOG.md and the specified version.
* *
@ -74,18 +78,37 @@ val argsKeyToValue = args
.filter { it.contains("=") } .filter { it.contains("=") }
.associate { it.substringBefore("=") to it.substringAfter("=") } .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"] 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) { if (token == null) {
println("To increase the rate limit, specify token (https://github.com/settings/tokens)") println("To increase the rate limit, specify token (https://github.com/settings/tokens)")
} }
println() println()
val androidxLibToPreviousVersion = previousVersionCommitArg?.let(::androidxLibToVersion)
val androidxLibToVersion = androidxLibToVersion(versionCommit) val androidxLibToVersion = androidxLibToVersion(versionCommit)
val androidxLibToRedirectingVersion = androidxLibToRedirectingVersion(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) = fun formatAndroidxLibVersion(libName: String) =
androidxLibToVersion[libName] ?: "PLACEHOLDER".also { androidxLibToVersion[libName] ?: "PLACEHOLDER".also {
println("Can't find $libName version. Using PLACEHOLDER") println("Can't find $libName version. Using PLACEHOLDER")
@ -120,12 +143,21 @@ val previousChangelog =
currentChangelog 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()
println("Generating changelog between $previousVersion and $versionName") println("Generating changelog between $previousVersion and $versionName")
val newChangelog = getChangelog("v$previousVersion", versionCommit, previousVersion) val newChangelog = getChangelog(previousVersionCommit, versionCommit, previousVersion)
changelogFile.writeText( changelogFile.writeText(
newChangelog + previousChangelog newChangelog + previousChangelog

Loading…
Cancel
Save