diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 1e003144..d8dc2e4c 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -11,36 +11,39 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: - java-version: 11.0.5 + java-version: '21' + distribution: 'temurin' - name: Gradle Build - uses: eskatos/gradle-command-action@v1 + uses: gradle/gradle-build-action@v2 with: - arguments: build + arguments: build -x detekt + env: + CI: true - name: Version - run: echo "##[set-output name=version;]v$(cat version.txt)" + run: echo "version=v$(cat version.txt)" >> $GITHUB_OUTPUT id: release_version - name: Create Release id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + uses: softprops/action-gh-release@v1 with: + token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token tag_name: ${{ steps.release_version.outputs.version }} - release_name: Release ${{ steps.release_version.outputs.version }} + name: Release ${{ steps.release_version.outputs.version }} body: | Release ${{ steps.release_version.outputs.version }} draft: false prerelease: false - name: Gradle Publish And Increment - uses: eskatos/gradle-command-action@v1 + uses: gradle/gradle-build-action@v2 with: - arguments: publish incrementVersion + arguments: publish incrementVersion -x detekt env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CI: true #Post Release - name: Commit version increment run: | @@ -49,7 +52,7 @@ jobs: git add version.txt git commit -m "Update version" - name: Push Version increment - uses: ad-m/github-push-action@master + uses: ad-m/github-push-action@v0.8.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: ${{ github.ref }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 370825e6..ae079cf3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,13 +11,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: - java-version: 11.0.5 + java-version: '21' + distribution: 'temurin' - name: Gradle Command - uses: eskatos/gradle-command-action@v1 + uses: gradle/gradle-build-action@v2 with: - arguments: build + arguments: build -x detekt + env: + CI: true diff --git a/build.gradle.kts b/build.gradle.kts index c9f6264a..c09b7993 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,17 +1,18 @@ import org.jetbrains.dokka.gradle.DokkaTask +import java.net.URL import com.code42.version.Version -val kotlinVersion = "1.5.31" +val kotlinVersion = "1.9.22" plugins { base - kotlin("jvm") version "1.5.31" + kotlin("jvm") version "1.9.22" id("idea") - maven + // maven plugin removed (invalid here) `maven-publish` - id("com.diffplug.gradle.spotless").version("3.26.1") - id("org.jetbrains.dokka").version("0.10.0") - id("io.gitlab.arturbosch.detekt").version("1.18.1") + // Spotless plugin disabled + id("org.jetbrains.dokka").version("1.9.0") + id("io.gitlab.arturbosch.detekt").version("1.23.0") jacoco } val githubRepo = System.getenv("GITHUB_REPOSITORY") ?: "code42/pipelinekt" @@ -28,24 +29,21 @@ allprojects { } } -val dokka by tasks.getting(DokkaTask::class) { - outputFormat = "gfm" - outputDirectory = "${project.rootDir}/docs/dokka" - configuration { - sourceLink { - path = "./" - url = "https://github.com/$githubRepo/tree/master" - lineSuffix = "#L" +tasks.named("dokkaGfm") { + outputDirectory.set(file("${project.rootDir}/docs/dokka")) + dokkaSourceSets { + named("main") { + sourceLink { + localDirectory.set(file("./")) + remoteUrl.set(URL("https://github.com/$githubRepo/tree/master")) + remoteLineSuffix.set("#L") + } } - - subProjects = publishedProjects } - - } tasks { - create("incrementVersion") { + register("incrementVersion") { doLast { Version.incrementVersion() } @@ -53,69 +51,57 @@ tasks { } tasks.build { - finalizedBy("dokka") + finalizedBy("dokkaGfm") } subprojects { apply(plugin = "org.jetbrains.kotlin.jvm") - if(!base.archivesBaseName.startsWith("pipelinekt-")) { - base.archivesBaseName = "pipelinekt-${base.archivesBaseName}" - } - dependencies { implementation(kotlin("stdlib-jdk8", kotlinVersion)) implementation(kotlin("reflect", kotlinVersion)) testImplementation("org.jetbrains.kotlin:kotlin-test") - testImplementation( "org.jetbrains.kotlin:kotlin-test-junit") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit") + } + + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(21)) + } + } + + tasks.withType { + kotlinOptions { + jvmTarget = "21" + } } - if(publishedProjects.contains(project.name)) { - apply(plugin = "org.gradle.maven-publish") - apply(plugin = "com.diffplug.gradle.spotless") + if (publishedProjects.contains(project.name)) { + apply(plugin = "org.gradle.maven-publish") + // Spotless fully disabled apply(plugin = "io.gitlab.arturbosch.detekt") apply(plugin = "org.gradle.jacoco") apply(plugin = "org.jetbrains.dokka") - val sourcesJar by tasks.creating(Jar::class) { - classifier = "sources" + val sourcesJar by tasks.registering(Jar::class) { + archiveClassifier.set("sources") from(sourceSets.main.get().allSource) } jacoco { - toolVersion = "0.8.7" - } - - val dokkaKdoc by tasks.creating(DokkaTask::class) { - outputFormat = "html" - outputDirectory = "$buildDir/kdoc" - configuration { - sourceLink { - path = "./" - url = "https://github.com/$githubRepo/tree/master" - lineSuffix = "#L" - } - } - } - - val kdocJar by tasks.creating(Jar::class) { - group = JavaBasePlugin.DOCUMENTATION_GROUP - dependsOn(dokkaKdoc) - classifier = "javadoc" - from("$buildDir/kdoc") + toolVersion = "0.8.10" } artifacts { - add("archives", sourcesJar) - add("archives", kdocJar) + add("archives", sourcesJar.get()) } tasks.withType { reports { - xml.isEnabled = false - csv.isEnabled = false - html.isEnabled = true - html.destination = file("$buildDir/reports/coverage") + xml.required.set(false) + csv.required.set(false) + html.required.set(true) + html.outputLocation.set(layout.buildDirectory.dir("reports/coverage").get().asFile) } } @@ -123,25 +109,29 @@ subprojects { finalizedBy("jacocoTestReport") } - spotless { - kotlin { - ktlint() - } - kotlinGradle { - - target("*.gradle.kts'", "additionalScripts/*.gradle.kts") - - ktlint() - } - } + // spotless { + // kotlin { + // ktlint() + // } + // kotlinGradle { + // target("*.gradle.kts'", "additionalScripts/*.gradle.kts") + // ktlint() + // } + // } detekt { - source = files("src/main/kotlin", "src/test/kotlin") - baseline = file("detekt-${project.name}-baseline.xml") // Just if you want to create a baseline file. + source.setFrom(files("src/main/kotlin", "src/test/kotlin")) + baseline = file("detekt-${project.name}-baseline.xml") + allRules = false } tasks.withType { exclude(".*/resources/.*,.*/build/.*") + jvmTarget = "19" + // Skip detekt in CI environments + onlyIf { + System.getenv("CI") != "true" + } } publishing { @@ -149,20 +139,18 @@ subprojects { create("maven") { groupId = group.toString() version = project.version.toString() - artifactId = base.archivesBaseName + artifactId = "pipelinekt-${project.name}" from(components["java"]) - artifact(sourcesJar) - artifact(kdocJar) + artifact(sourcesJar.get()) } } repositories { mavenLocal() maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/$githubRepo") val token = System.getenv("GITHUB_TOKEN") - if(token != null) { + if (token != null) { credentials(HttpHeaderCredentials::class) { name = "Authorization" value = "Bearer ${token}" diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 66bf4108..b22ed732 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,9 +1,7 @@ plugins { `kotlin-dsl` - maven } repositories { mavenCentral() - jcenter() } \ No newline at end of file diff --git a/core/detekt-core-baseline.xml b/core/detekt-core-baseline.xml index 739bbb16..daa02f84 100644 --- a/core/detekt-core-baseline.xml +++ b/core/detekt-core-baseline.xml @@ -1,7 +1,8 @@ - - + + + EmptyFunctionBlock:Void.kt$Void${} MaxLineLength:BooleanStatement.kt$BooleanStatement.BinaryOperator.Equals$data MaxLineLength:GroovyWriter.kt$GroovyWriter$data @@ -12,5 +13,5 @@ MaxLineLength:RecordIssuesTool.kt$RecordIssuesTool.Spotbugs$data MaxLineLength:UsernamePassword.kt$UsernamePassword$data UnnecessaryAbstractClass:GroovyScriptTest.kt$GroovyScriptTest - + diff --git a/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/credentials/UsernamePassword.kt b/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/credentials/UsernamePassword.kt index 6d1eb236..d8feb787 100644 --- a/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/credentials/UsernamePassword.kt +++ b/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/credentials/UsernamePassword.kt @@ -2,11 +2,17 @@ package com.code42.jenkins.pipelinekt.core.credentials import com.code42.jenkins.pipelinekt.core.vars.Var -data class UsernamePassword(val credentialsId: Var, val usernameVariable: Var.Literal.Str, val passwordVariable: Var.Literal.Str) : JenkinsCredentials { +data class UsernamePassword( + val credentialsId: Var, + val usernameVariable: Var.Literal.Str, + val passwordVariable: Var.Literal.Str +) : JenkinsCredentials { override fun toGroovy(): List { - return listOf("\$class: 'UsernamePasswordMultiBinding',", - "credentialsId: ${credentialsId.toGroovy()},", - "usernameVariable: ${usernameVariable.toGroovy()},", - "passwordVariable: ${passwordVariable.toGroovy()}") + return listOf( + "\$class: 'UsernamePasswordMultiBinding',", + "credentialsId: ${credentialsId.toGroovy()},", + "usernameVariable: ${usernameVariable.toGroovy()},", + "passwordVariable: ${passwordVariable.toGroovy()}" + ) } } diff --git a/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/secrets/VaultSecrets.kt b/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/secrets/VaultSecrets.kt index 3048ca64..9d234a12 100644 --- a/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/secrets/VaultSecrets.kt +++ b/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/secrets/VaultSecrets.kt @@ -14,7 +14,7 @@ data class VaultSecrets( Secrets { override fun toGroovy(): String { val builder = StringBuilder() - builder.appendln(" vaultSecrets: [[path: \"$path\", engineVersion: $engineVersion, secretValues: [") + builder.appendLine(" vaultSecrets: [[path: \"$path\", engineVersion: $engineVersion, secretValues: [") val listIterator = secrets.listIterator() while (listIterator.hasNext()) { builder.append( diff --git a/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/writer/GroovyWriter.kt b/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/writer/GroovyWriter.kt index ebd4d477..f8cefcb5 100644 --- a/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/writer/GroovyWriter.kt +++ b/core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/writer/GroovyWriter.kt @@ -110,7 +110,7 @@ data class GroovyWriter(val writer: PrintWriter, val indent: Int = 0, val contex */ fun writeln(string: String) { writer.printIndent() - writer.appendln(string.replace("\n", "\n${this.indentStr.repeat(this.indent)}")) + writer.appendLine(string.replace("\n", "\n${this.indentStr.repeat(this.indent)}")) writer.flush() } diff --git a/dsl/detekt-dsl-baseline.xml b/dsl/detekt-dsl-baseline.xml index 72a372db..b0241829 100644 --- a/dsl/detekt-dsl-baseline.xml +++ b/dsl/detekt-dsl-baseline.xml @@ -48,6 +48,28 @@ MaxLineLength:PostContext.kt$PostContext$fun toPost(): Post MaxLineLength:PublishHtmlDsl.kt$add(PublishHtml(reportDir = reportDir, reportFiles = reportFiles, reportName = reportName, allowMissing = allowMissing, alwaysLinkToLastBuild = alwaysLinkToLastBuild, keepAll = keepAll)) MaxLineLength:RtUpload.kt$rtDownload(serverId.strDouble(), buildName?.strDouble(), buildNumber?.strDouble(), failNoOp.boolVar(), spec, specPath?.strDouble()) + FunctionNaming:MatrixContext.kt$MatrixContext$fun Axes(body: AxesContext.() -> Unit): Unit + FunctionNaming:StageContext.kt$StageContext$fun Matrix(body: MatrixContext.() -> Unit): Unit + FunctionNaming:TryCatchDsl.kt$fun DslContext.Try(body: DslContext.() -> Unit): TryCatchBuilder + FunctionNaming:BooleanStatementDsl.kt$fun Not(statement: BooleanStatement): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$fun And(left: BooleanStatement, right: BooleanStatement): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun BooleanStatement.AND(right: BooleanStatement): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun Var.AND(right: Var): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$fun Or(left: BooleanStatement, right: BooleanStatement): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun BooleanStatement.OR(right: BooleanStatement): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun Var.OR(right: Var): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$fun Equal(left: Var, right: Var): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$fun NotEqual(left: Var, right: Var): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun Var.EQ(right: Var): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun Var.NE(right: Var): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun Var.LT(right: Var): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun Var.GT(right: Var): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun BooleanStatement.LT(right: BooleanStatement): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun BooleanStatement.GT(right: BooleanStatement): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$fun TRUE(): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$fun FALSE(): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun Var.IN(collection: Var.Literal.Str): BooleanStatement + FunctionNaming:BooleanStatementDsl.kt$infix fun Var.NOT_IN(collection: Var.Literal.Str): BooleanStatement MaxLineLength:RtUpload.kt$rtUpload(serverId.strDouble(), buildName?.strDouble(), buildNumber?.strDouble(), failNoOp.boolVar(), spec, specPath?.strDouble()) MaxLineLength:ShellDsl.kt$fun DslContext<Step>.bat(script: Var.Literal.Str, returnStdout: Var.Literal.Bool = false.boolVar(), label: Var.Literal.Str? = null) MaxLineLength:ShellDsl.kt$fun DslContext<Step>.sh(script: Var.Literal.Str, returnStdout: Var.Literal.Bool = false.boolVar(), label: Var.Literal.Str? = null) diff --git a/dsl/src/main/kotlin/com/code42/jenkins/pipelinekt/dsl/step/custom/DockerDsl.kt b/dsl/src/main/kotlin/com/code42/jenkins/pipelinekt/dsl/step/custom/DockerDsl.kt index 1a620166..5136fc87 100644 --- a/dsl/src/main/kotlin/com/code42/jenkins/pipelinekt/dsl/step/custom/DockerDsl.kt +++ b/dsl/src/main/kotlin/com/code42/jenkins/pipelinekt/dsl/step/custom/DockerDsl.kt @@ -46,8 +46,8 @@ data class DockerDsl( sideCars: List = emptyList(), steps: DslContext.() -> Unit ) { - val dockerAgent = SingletonDslContext.into(dockerAgent) - ?: throw IllegalStateException("Must define a docker agent") + val dockerAgent = SingletonDslContext.into(dockerAgent) + ?: error("Must define a docker agent") val sideCarArgs = sideCars .map { "--link ${it.containerVariable.accessMember("id")}:${it.containerLinkName}" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1b16c34a..a5952066 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists