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(deps): update dependency org.jlleitschuh.gradle.ktlint:org.jlleitschuh.gradle.ktlint.gradle.plugin from 11.5.1 to v12 #134

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
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: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 140
tab_width = 4

[*.md]
max_line_length = 80

[{*.yaml,*.yml}]
indent_size = 2

[*.{kt,kts}]
ktlint_standard_filename = disabled
ktlint_standard_annotation = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_string-template-indent = disabled
14 changes: 6 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ dependencies {
// Leak semver library users of this plugin so that they can implement their own versionModifier strategy
// TODO: For v2, remove need for semver jar for consumers. They shouldn't need to know about this detail
listOf(
libs.swiftzer.semver
libs.swiftzer.semver,
).forEach {
api(it)
}

listOf(
gradleTestKit(),
libs.bundles.kotest
libs.bundles.kotest,
).forEach {
testImplementation(it)
}
Expand All @@ -83,7 +83,7 @@ tasks.withType<KotlinCompile>().configureEach {
freeCompilerArgs.addAll(
"-version",
"-Xjsr305=strict",
"-opt-in=kotlin.RequiresOptIn"
"-opt-in=kotlin.RequiresOptIn",
)
verbose.set(true)
}
Expand Down Expand Up @@ -127,13 +127,11 @@ githubRelease {
token(githubTokenValue)
}

ktlint {
disabledRules.set(setOf("trailing-comma-on-declaration-site", "trailing-comma-on-call-site"))
}

tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}

logger.lifecycle("JDK toolchain version: ${java.toolchain.languageVersion.get()}")
logger.lifecycle("Kotlin version: ${extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension>()?.coreLibrariesVersion}")
logger.lifecycle(
"Kotlin version: ${extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension>()?.coreLibrariesVersion}",
)
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ detekt = "1.23.6"
gradle-plugin-publish = "1.2.1"
jgit = "6.5.0.202303070854-r"
kotest = "5.8.1"
ktlint-gradle = "11.5.1"
ktlint-gradle = "12.1.0"
swiftzer-semver = "1.3.0"

# Plugin versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ abstract class SemverExtension @Inject constructor(
"""
|Cannot set semver tagPrefix after override version has been set.
| The override version depends on the tagPrefix. Set the tagPrefix first.
""".trimMargin().replace("\n", "")
""".trimMargin().replace("\n", ""),
)
}
this.tagPrefix.set(prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data class BranchMatchingConfiguration(
val regex: Regex,
val targetBranch: GitRef.Branch,
val versionQualifier: VersionQualifier,
val versionModifier: VersionModifier = { nextPatch() }
val versionModifier: VersionModifier = { nextPatch() },
)

fun mainBasedFlowVersionCalculatorStrategy(versionModifier: VersionModifier): VersionCalculatorStrategy =
Expand All @@ -33,56 +33,55 @@ fun masterBasedFlowVersionCalculatorStrategy(versionModifier: VersionModifier):

private fun buildFlowVersionCalculatorStrategy(
targetBranch: GitRef.Branch,
versionModifier: VersionModifier
): VersionCalculatorStrategy = listOf(
BranchMatchingConfiguration(
regex = """^${targetBranch.name}$""".toRegex(),
targetBranch = targetBranch,
versionQualifier = {
PreReleaseLabel.EMPTY to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier
),
BranchMatchingConfiguration(
regex = """^develop$""".toRegex(),
targetBranch = targetBranch,
versionQualifier = { currentBranch ->
preReleaseWithCommitCount(
currentBranch = currentBranch,
targetBranch = targetBranch,
label = "beta"
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier
),
BranchMatchingConfiguration(
regex = """^rc/.*""".toRegex(),
targetBranch = targetBranch,
versionQualifier = { currentBranch ->
preReleaseWithCommitCount(
currentBranch = currentBranch,
targetBranch = targetBranch,
label = "rc"
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier
),
/**
* This one must be last so the other configurations get matched first
*/
BranchMatchingConfiguration(
regex = """.*""".toRegex(),
targetBranch = GitRef.Branch.DEVELOP,
versionQualifier = { currentBranch ->
preReleaseWithCommitCount(
currentBranch = currentBranch,
targetBranch = targetBranch,
label = currentBranch.sanitizedNameWithoutPrefix()
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier
),
)
versionModifier: VersionModifier,
): VersionCalculatorStrategy =
listOf(
BranchMatchingConfiguration(
regex = """^${targetBranch.name}$""".toRegex(),
targetBranch = targetBranch,
versionQualifier = {
PreReleaseLabel.EMPTY to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier,
),
BranchMatchingConfiguration(
regex = """^develop$""".toRegex(),
targetBranch = targetBranch,
versionQualifier = { currentBranch ->
preReleaseWithCommitCount(
currentBranch = currentBranch,
targetBranch = targetBranch,
label = "beta",
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier,
),
BranchMatchingConfiguration(
regex = """^rc/.*""".toRegex(),
targetBranch = targetBranch,
versionQualifier = { currentBranch ->
preReleaseWithCommitCount(
currentBranch = currentBranch,
targetBranch = targetBranch,
label = "rc",
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier,
),
// This one must be last so the other configurations get matched first
BranchMatchingConfiguration(
regex = """.*""".toRegex(),
targetBranch = GitRef.Branch.DEVELOP,
versionQualifier = { currentBranch ->
preReleaseWithCommitCount(
currentBranch = currentBranch,
targetBranch = targetBranch,
label = currentBranch.sanitizedNameWithoutPrefix(),
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier,
),
)

fun mainBasedFlatVersionCalculatorStrategy(versionModifier: VersionModifier): VersionCalculatorStrategy =
buildFlatVersionCalculatorStrategy(GitRef.Branch.MAIN, versionModifier)
Expand All @@ -93,35 +92,36 @@ fun masterBasedFlatVersionCalculatorStrategy(versionModifier: VersionModifier):
private fun buildFlatVersionCalculatorStrategy(
targetBranch: GitRef.Branch,
versionModifier: VersionModifier,
): VersionCalculatorStrategy = listOf(
BranchMatchingConfiguration(
regex = """^${targetBranch.name}$""".toRegex(),
targetBranch = targetBranch,
versionQualifier = { PreReleaseLabel.EMPTY to BuildMetadataLabel.EMPTY },
versionModifier = versionModifier
),
BranchMatchingConfiguration(
regex = """^rc/.*""".toRegex(),
targetBranch = targetBranch,
versionQualifier = { currentBranch ->
preReleaseWithCommitCount(
currentBranch = currentBranch,
targetBranch = targetBranch,
label = "rc"
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier
),
BranchMatchingConfiguration(
regex = """.*""".toRegex(),
targetBranch = targetBranch,
versionQualifier = {
preReleaseWithCommitCount(
currentBranch = it,
targetBranch = targetBranch,
label = it.sanitizedNameWithoutPrefix()
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier
),
)
): VersionCalculatorStrategy =
listOf(
BranchMatchingConfiguration(
regex = """^${targetBranch.name}$""".toRegex(),
targetBranch = targetBranch,
versionQualifier = { PreReleaseLabel.EMPTY to BuildMetadataLabel.EMPTY },
versionModifier = versionModifier,
),
BranchMatchingConfiguration(
regex = """^rc/.*""".toRegex(),
targetBranch = targetBranch,
versionQualifier = { currentBranch ->
preReleaseWithCommitCount(
currentBranch = currentBranch,
targetBranch = targetBranch,
label = "rc",
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier,
),
BranchMatchingConfiguration(
regex = """.*""".toRegex(),
targetBranch = targetBranch,
versionQualifier = {
preReleaseWithCommitCount(
currentBranch = it,
targetBranch = targetBranch,
label = it.sanitizedNameWithoutPrefix(),
) to BuildMetadataLabel.EMPTY
},
versionModifier = versionModifier,
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import net.swiftzer.semver.SemVer

interface ContextProviderOperations {
fun currentBranch(): GitRef.Branch?

fun branchVersion(currentBranch: GitRef.Branch, targetBranch: GitRef.Branch): Result<SemVer?>

fun commitsSinceBranchPoint(currentBranch: GitRef.Branch, targetBranch: GitRef.Branch): Result<Int?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ interface SemverContext {
targetBranch: GitRef.Branch,
label: String,
) = PreReleaseLabel(
value = ops.commitsSinceBranchPoint(currentBranch, targetBranch).fold(
onSuccess = {
"$label.$it"
},
onFailure = {
log.semverWarn("Unable to calculate commits since branch point on current $currentBranch")
label
}
)
value =
ops.commitsSinceBranchPoint(currentBranch, targetBranch).fold(
onSuccess = {
"$label.$it"
},
onFailure = {
log.semverWarn("Unable to calculate commits since branch point on current $currentBranch")
label
},
),
)
}
12 changes: 11 additions & 1 deletion src/main/kotlin/com/figure/gradle/semver/internal/LogExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ private const val LOG_DEBUG_PREFIX = "[gradle-semver-plugin] DEBUG "
private fun String.colored(c: String) = "$c$this\u001B[0m"

internal fun String.darkgray() = this.colored("\u001B[30m")

internal fun String.red() = this.colored("\u001B[31m")

internal fun String.green() = this.colored("\u001B[32m")

internal fun String.yellow() = this.colored("\u001B[33m")

internal fun String.purple() = this.colored("\u001B[35m")

internal fun String.lightgray() = this.colored("\u001B[37m")

internal fun String.bold() = this.colored("\u001B[1m")

internal fun Logger.semverError(message: String) = this.error(LOG_ERROR_PREFIX.bold() + message.red())
internal fun Logger.semverError(message: String, e: Throwable) = this.error(LOG_ERROR_PREFIX.bold() + message.red(), e)

internal fun Logger.semverError(
message: String,
e: Throwable,
) = this.error(LOG_ERROR_PREFIX.bold() + message.red(), e)

internal fun Logger.semverQuiet(message: String) = this.quiet(LOG_QUIET_PREFIX.bold() + message.lightgray())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ internal class TagAlreadyExistsException(tag: String) :
"""
|Tag $tag already exists on remote! Either skip publishing the artifact on the next run or delete
| the existing tag before running again.
""".trimMargin().replace("\n", "")
""".trimMargin().replace("\n", ""),
)

internal class UnsupportedBranchingStrategy() :
Exception(
"Unsupported branching strategy. Supported branching strategies: main, master, main-develop, master-develop"
"Unsupported branching strategy. Supported branching strategies: main, master, main-develop, master-develop",
)
Loading
Loading