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

Jenkinsfile Recipes? #12

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {

testImplementation("org.openrewrite:rewrite-test")
testImplementation("org.openrewrite:rewrite-java-tck")
testImplementation("org.openrewrite:rewrite-groovy")
testImplementation("org.assertj:assertj-core:latest.release")

testRuntimeOnly("com.github.spotbugs:spotbugs-annotations:4.7.0")
Expand Down
135 changes: 135 additions & 0 deletions src/test/java/org/openrewrite/jenkins/ModernizeJenkinsfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/
package org.openrewrite.jenkins;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.Recipe;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.groovy.Assertions.groovy;
import static org.openrewrite.maven.Assertions.pomXml;
import static org.openrewrite.test.SourceSpecs.text;

Expand Down Expand Up @@ -100,4 +103,136 @@ void shouldUpdateJenkinsfile() {
""".stripIndent(),
spec -> spec.path("Jenkinsfile")));
}

@Test
@Disabled
void shouldAddJdk21IfAbsent() {
rewriteRun(spec -> spec.recipe(new AddBuildPluginConfiguration("linux", "21")),
groovy("""
buildPlugin()
""".stripIndent(), """
buildPlugin(configurations:[
[ platform: 'linux', jdk: '21' ]
])
""".stripIndent(),
spec -> spec.path("Jenkinsfile")
));
}

@Test
@Disabled
void shouldRemoveJdk8IfPresent() {
rewriteRun(spec -> spec.recipe(new RemoveBuildPluginConfiguration("linux", "8")),
groovy("""
buildPlugin(useContainerAgent: true, configurations: [
[ platform: 'linux', jdk: '8' ],
[ platform: 'windows', jdk: '8' ],
[ platform: 'windows', jdk: '11' ],
[ platform: 'linux', jdk: '17' ],
])
""".stripIndent(), """
buildPlugin(useContainerAgent: true, configurations: [
[ platform: 'windows', jdk: '8' ],
[ platform: 'windows', jdk: '11' ],
[ platform: 'linux', jdk: '17' ],
])
""".stripIndent(),
spec -> spec.path("Jenkinsfile")
));
}

@Test
@Disabled
void shouldRemoveJdk8FromAllPlatformsIfPresent() {
rewriteRun(spec -> spec.recipe(new RemoveBuildPluginConfiguration("8")),
groovy("""
buildPlugin(useContainerAgent: true, failFast: false, configurations: [
[ platform: 'linux', jdk: '8' ],
[ platform: 'windows', jdk: '8' ],
[ platform: 'windows', jdk: '11' ],
[ platform: 'linux', jdk: '17' ],
])
""".stripIndent(), """
buildPlugin(useContainerAgent: true, failFast: false, configurations: [
[ platform: 'windows', jdk: '11' ],
[ platform: 'linux', jdk: '17' ],
])
""".stripIndent(),
spec -> spec.path("Jenkinsfile")
));
}

@Test
@Disabled
void shouldRemoveJenkinsVersionsLessThan() {
rewriteRun(spec -> spec.recipe(new RemoveJenkinsVersionsLessThan("2.346.3")),
groovy("""
buildPlugin(jenkinsVersions: [null, '2.60.1', '2.387.3'])
""".stripIndent(), """
buildPlugin(jenkinsVersions: [null, '2.387.3'])
""".stripIndent(),
spec -> spec.path("Jenkinsfile")
));
}

@Test
@Disabled
void shouldRemoveKeyIfRemoveJenkinsVersionsLessThanLeavesOnlyNull() {
rewriteRun(spec -> spec.recipe(new RemoveJenkinsVersionsLessThan("2.346.3")),
groovy("""
buildPlugin(jenkinsVersions: [null, '2.60.1'])
""".stripIndent(), """
buildPlugin()
""".stripIndent(),
spec -> spec.path("Jenkinsfile")
));
}

private static class AddBuildPluginConfiguration extends Recipe {
public AddBuildPluginConfiguration(String platform, String jdk) {
}

@Override
public String getDisplayName() {
return null;
}

@Override
public String getDescription() {
return null;
}
}

private static class RemoveBuildPluginConfiguration extends Recipe {
public RemoveBuildPluginConfiguration(String jdk) {
}

public RemoveBuildPluginConfiguration(String platform, String jdk) {
}

@Override
public String getDisplayName() {
return null;
}

@Override
public String getDescription() {
return null;
}
}

private class RemoveJenkinsVersionsLessThan extends Recipe {
public RemoveJenkinsVersionsLessThan(String version) {
}

@Override
public String getDisplayName() {
return null;
}

@Override
public String getDescription() {
return null;
}
}
}