generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: minor version strategy rules #132
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d0c98f8
feat: minor version strategy rules
0marperez 3e95dad
move slf4j to libs
0marperez 4c92f2b
feedback
0marperez 7e97ee6
feedback
0marperez ee25d9b
self review
0marperez 079ebb1
self review
0marperez 3f388e2
feedback
0marperez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name: Minor version bump | ||
| description: Verifies branch is ready to merge before minor version bump | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Configure Gradle | ||
| uses: awslabs/aws-kotlin-repo-tools/.github/actions/configure-gradle@main | ||
|
|
||
| - name: Verify minor version bump | ||
| shell: bash | ||
| run: ./gradlew verifyMinorVersionBump |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...d-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/MinorVersionStrategy.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.gradle.dsl | ||
|
|
||
| import aws.sdk.kotlin.gradle.util.verifyRootProject | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.artifacts.VersionCatalogsExtension | ||
| import org.gradle.api.attributes.Bundling | ||
| import org.gradle.api.tasks.JavaExec | ||
| import org.gradle.kotlin.dsl.* | ||
| import org.gradle.kotlin.dsl.getByType | ||
| import org.gradle.language.base.plugins.LifecycleBasePlugin | ||
|
|
||
| /** | ||
| * Configures Gradle task for minor-version-bump-specific Ktlint rules. | ||
| */ | ||
| fun Project.configureMinorVersionStrategyRules(lintPaths: List<String>) { | ||
| verifyRootProject { "Task configuration is expected to be configured on the root project" } | ||
|
|
||
| val ktlintVersion = object {} // Can't use Project.javaClass because that's using the Gradle classloader | ||
| .javaClass | ||
| .getResource("ktlint-version.txt") | ||
| ?.readText() | ||
| ?: error("Missing ktlint-version.txt") | ||
|
|
||
| val repoToolsVersion = extensions | ||
| .getByType<VersionCatalogsExtension>() | ||
| .named("libs") | ||
| .findVersion("aws-kotlin-repo-tools-version") | ||
| .get() | ||
| .requiredVersion | ||
|
|
||
| val minorVersionBumpKtlint by configurations.creating | ||
|
|
||
| dependencies { | ||
| minorVersionBumpKtlint("com.pinterest.ktlint:ktlint-cli:$ktlintVersion") { | ||
| attributes { | ||
| attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.SHADOWED)) | ||
| } | ||
| } | ||
| minorVersionBumpKtlint("aws.sdk.kotlin.gradle:minor-version-rules:$repoToolsVersion") | ||
| } | ||
|
|
||
| tasks.register<JavaExec>("verifyMinorVersionBump") { | ||
| group = LifecycleBasePlugin.VERIFICATION_GROUP | ||
| description = "Check minor version bump rules" | ||
| classpath = minorVersionBumpKtlint | ||
| mainClass.set("com.pinterest.ktlint.Main") | ||
| args = lintPaths | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
|
||
| description = "Lint rules for minor version bumps" | ||
|
|
||
| plugins { | ||
| `maven-publish` | ||
| kotlin("jvm") | ||
| } | ||
|
|
||
| kotlin { | ||
| sourceSets { | ||
| main { | ||
| dependencies { | ||
| implementation(libs.ktlint.cli.ruleset.core) | ||
| } | ||
| } | ||
|
|
||
| test { | ||
| dependencies { | ||
| implementation(kotlin("test")) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.test { | ||
| testLogging { | ||
| events("passed", "skipped", "failed") | ||
| showStandardStreams = true | ||
| showStackTraces = true | ||
| showExceptions = true | ||
| exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile> { | ||
| compilerOptions { | ||
| jvmTarget.set(JvmTarget.JVM_1_8) | ||
| freeCompilerArgs.add("-Xjdk-release=1.8") | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<JavaCompile> { | ||
| sourceCompatibility = JavaVersion.VERSION_1_8.toString() | ||
| targetCompatibility = JavaVersion.VERSION_1_8.toString() | ||
| } | ||
|
|
||
| publishing { | ||
| publications { | ||
| create<MavenPublication>("ktlintRules") { | ||
| from(components["kotlin"]) | ||
| } | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
ktlint/minor-version-rules/src/main/kotlin/software/aws/ktlint/rules/DeprecatedApiRule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.aws.ktlint.rules | ||
|
|
||
| import com.pinterest.ktlint.rule.engine.core.api.ElementType | ||
| import com.pinterest.ktlint.rule.engine.core.api.Rule | ||
| import com.pinterest.ktlint.rule.engine.core.api.RuleId | ||
| import org.jetbrains.kotlin.com.intellij.lang.ASTNode | ||
|
|
||
| /** | ||
| * Matches @DeprecatedUntilVersion with either named args (major=x, minor=y) or positional args (x, y) | ||
| */ | ||
| internal fun deprecatedUntilVersionRegex(major: Int, minor: Int): Regex = | ||
| Regex( | ||
| """@DeprecatedUntilVersion\s*\(\s*(?:major\s*=\s*$major\s*,\s*minor\s*=\s*$minor\s*|\s*$major\s*,\s*$minor\s*)\s*\)""", | ||
| ) | ||
|
|
||
| /** | ||
| * Creates a ktlint rule that detects APIs annotated with @DeprecatedUntilVersion for the upcoming minor version. | ||
| */ | ||
| class DeprecatedApiRule : Rule(RuleId("minor-version-strategy-rules:deprecated-apis"), About()) { | ||
| override fun beforeVisitChildNodes( | ||
| node: ASTNode, | ||
| autoCorrect: Boolean, | ||
| emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, | ||
| ) { | ||
| if (node.elementType == ElementType.ANNOTATION_ENTRY) { | ||
| val sdkVersion = System.getProperty("sdkVersion").split(".") | ||
| val majorVersion = sdkVersion[0].toInt() | ||
| val minorVersion = sdkVersion[1].toInt() | ||
|
|
||
| val regex = deprecatedUntilVersionRegex(majorVersion, minorVersion + 1) | ||
| if (regex.containsMatchIn(node.text)) { | ||
| emit( | ||
| node.startOffset, | ||
| "The deprecated API is scheduled for removal, please remove it before releasing the next minor version.", | ||
| true, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
...or-version-rules/src/main/kotlin/software/aws/ktlint/rules/MinorVersionRuleSetProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.aws.ktlint.rules | ||
|
|
||
| import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3 | ||
| import com.pinterest.ktlint.rule.engine.core.api.RuleProvider | ||
| import com.pinterest.ktlint.rule.engine.core.api.RuleSetId | ||
|
|
||
| class MinorVersionRuleSetProvider : RuleSetProviderV3(RuleSetId("minor-version-strategy-rules")) { | ||
| override fun getRuleProviders() = setOf( | ||
| RuleProvider { DeprecatedApiRule() }, | ||
| ) | ||
| } |
4 changes: 4 additions & 0 deletions
4
...n/resources/META-INF/services/com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| software.aws.ktlint.rules.MinorVersionRuleSetProvider |
38 changes: 38 additions & 0 deletions
38
...nt/minor-version-rules/src/test/kotlin/software/aws/ktlint/rules/DeprecatedApiRuleTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.aws.ktlint.rules | ||
|
|
||
| import kotlin.test.Test | ||
| import kotlin.test.assertFalse | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class DeprecatedApiRuleTest { | ||
| fun runRegexTestCases(minor: Int, major: Int) { | ||
| val regex = deprecatedUntilVersionRegex(major, minor) | ||
|
|
||
| assertTrue(regex.containsMatchIn("@DeprecatedUntilVersion($major,$minor)")) | ||
| assertTrue(regex.containsMatchIn("@DeprecatedUntilVersion($major,$minor )")) | ||
| assertTrue(regex.containsMatchIn("@DeprecatedUntilVersion($major, $minor)")) | ||
| assertTrue(regex.containsMatchIn("@DeprecatedUntilVersion($major ,$minor)")) | ||
| assertTrue(regex.containsMatchIn("@DeprecatedUntilVersion( $major,$minor)")) | ||
| assertTrue(regex.containsMatchIn("@DeprecatedUntilVersion( $major , $minor )")) | ||
| assertTrue(regex.containsMatchIn("@DeprecatedUntilVersion(major=$major,minor=$minor)")) | ||
| assertTrue(regex.containsMatchIn("@DeprecatedUntilVersion( major= $major , minor= $minor )")) | ||
|
|
||
| assertFalse(regex.containsMatchIn("@DeprecatedUntilVersion")) | ||
| assertFalse(regex.containsMatchIn("@DeprecatedUntilVersion()")) | ||
| assertFalse(regex.containsMatchIn("@DeprecatedUntilVersion($minor,$minor)")) | ||
| assertFalse(regex.containsMatchIn("@DeprecatedUntilVersion($major,$major)")) | ||
| assertFalse(regex.containsMatchIn("@DeprecatedUntilVersion($minor,$major)")) | ||
| } | ||
|
|
||
| @Test | ||
| fun testRegex() { | ||
| runRegexTestCases(0, 1) | ||
| runRegexTestCases(1, 70) | ||
| runRegexTestCases(100, 1_000_000) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nt.cli.ruleset.core.api.RuleSetProviderV3 → ...nt.cli.ruleset.core.api.RuleSetProviderV3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| software.aws.ktlint.rules.CustomRuleSetProvider | ||
| software.aws.ktlint.rules.StyleRuleSetProvider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diving deeper, do we have to use a system property here? There's no way to inspect the gradle.properties and pull out the
sdkVersionfrom there?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code worked: