Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolves the accidental mangling of Helm subchart versions on release #285

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions buildSrc/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Utils {
@JvmStatic
fun updateHelmChartVersion(project: Project, chartName: String, newVersion: SemVer) {
val manifestFile = File(project.rootProject.projectDir, "charts/${chartName}/Chart.yaml")
updateStringInFile(manifestFile, "version:", "version: $newVersion")
updateStringInFile(manifestFile, "version:", "version: $newVersion", false)
}

@JvmStatic
Expand All @@ -39,31 +39,30 @@ class Utils {
updateStringInFile(manifestFile, "appVersion:", "appVersion: \"${newVersion}\"")
}

private fun updateStringInFile(file: File, startsWith: String, newString: String) {
private fun updateStringInFile(file: File, startsWith: String, newString: String, ignoreLeadingSpace: Boolean = true) {
var lines: List<String> = mutableListOf()

if (file.exists()) {
lines = file.readLines(Charsets.UTF_8)
}

val finalLines: List<String>

if (lines.isNotEmpty()) {
finalLines = lines.map {
if (it.trimStart().startsWith(startsWith)) {
val finalLines: List<String> = if (lines.isNotEmpty()) {
lines.map {
if (ignoreLeadingSpace && it.trimStart().startsWith(startsWith)) {
newString
} else if (it.startsWith(startsWith)) {
newString
} else {
it
}
}
} else {
finalLines = listOf(newString)
listOf(newString)
}

file.bufferedWriter(Charsets.UTF_8).use {
val writer = it
finalLines.forEach {
writer.write(it)
file.bufferedWriter(Charsets.UTF_8).use { writer ->
finalLines.forEach { lines ->
writer.write(lines)
writer.newLine()
}
writer.flush()
Expand Down