From c3ed2682b759dd0df9f7718a048f7cc443308576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Wed, 12 Apr 2023 04:38:09 +0200 Subject: [PATCH] Write GitHub Actions workflow files in Kotlin instead of Yaml --- .github/workflows/branches-and-prs.main.kts | 153 +++++++++++ .github/workflows/branches-and-prs.yaml | 94 +++++++ .github/workflows/branches-and-prs.yml | 68 ----- .github/workflows/codeql-analysis.main.kts | 147 ++++++++++ .github/workflows/codeql-analysis.yaml | 59 ++++ .github/workflows/codeql-analysis.yml | 63 ----- .../gradle-wrapper-validation.main.kts | 51 ++++ .../workflows/gradle-wrapper-validation.yaml | 34 +++ .../workflows/gradle-wrapper-validation.yml | 10 - .github/workflows/release.main.kts | 255 ++++++++++++++++++ .github/workflows/release.yaml | 167 ++++++++++++ .github/workflows/release.yml | 118 -------- build.gradle | 45 +++- 13 files changed, 1004 insertions(+), 260 deletions(-) create mode 100755 .github/workflows/branches-and-prs.main.kts create mode 100644 .github/workflows/branches-and-prs.yaml delete mode 100644 .github/workflows/branches-and-prs.yml create mode 100755 .github/workflows/codeql-analysis.main.kts create mode 100644 .github/workflows/codeql-analysis.yaml delete mode 100644 .github/workflows/codeql-analysis.yml create mode 100755 .github/workflows/gradle-wrapper-validation.main.kts create mode 100644 .github/workflows/gradle-wrapper-validation.yaml delete mode 100644 .github/workflows/gradle-wrapper-validation.yml create mode 100755 .github/workflows/release.main.kts create mode 100644 .github/workflows/release.yaml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/branches-and-prs.main.kts b/.github/workflows/branches-and-prs.main.kts new file mode 100755 index 0000000000..3eefb5e1f1 --- /dev/null +++ b/.github/workflows/branches-and-prs.main.kts @@ -0,0 +1,153 @@ +#!/usr/bin/env kotlin + +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:DependsOn("io.github.typesafegithub:github-workflows-kt:0.40.1") + +import io.github.typesafegithub.workflows.actions.actions.CheckoutV3 +import io.github.typesafegithub.workflows.actions.codecov.CodecovActionV3 +import io.github.typesafegithub.workflows.actions.gradle.GradleBuildActionV2 +import io.github.typesafegithub.workflows.domain.Concurrency +import io.github.typesafegithub.workflows.domain.RunnerType +import io.github.typesafegithub.workflows.domain.actions.CustomAction +import io.github.typesafegithub.workflows.domain.triggers.PullRequest +import io.github.typesafegithub.workflows.domain.triggers.Push +import io.github.typesafegithub.workflows.dsl.expressions.Contexts +import io.github.typesafegithub.workflows.dsl.expressions.expr +import io.github.typesafegithub.workflows.dsl.workflow +import io.github.typesafegithub.workflows.yaml.writeToFile + +workflow( + name = "Verify Branches and PRs", + on = listOf( + Push( + branchesIgnore = listOf( + "master", + "gh-pages" + ) + ), + PullRequest( + branches = listOf("*") + ) + ), + sourceFile = __FILE__.toPath(), + //# https://stackoverflow.com/a/72408109/16358266 + concurrency = Concurrency( + group = "${expr { github.workflow }}-${expr("${Contexts.github.eventPullRequest.pull_request.number} || ${Contexts.github.ref}")}", + cancelInProgress = true + ) +) { + job( + id = "build-and-verify", + name = "Build and Verify", + runsOn = RunnerType.Custom(expr("matrix.os")), + _customArguments = mapOf( + "strategy" to mapOf( + "fail-fast" to false, + "matrix" to mapOf( + "os" to listOf("ubuntu-latest"), + "variant" to listOf("2.5", "3.0", "4.0"), + "java" to listOf("8", "11", "17"), + "exclude" to listOf( + mapOf( + "os" to "ubuntu-latest", + "variant" to "2.5", + "java" to "17" + ) + ), + "include" to listOf( + mapOf( + "os" to "windows-latest", + "variant" to "2.5", + "java" to "8" + ), + mapOf( + "os" to "windows-latest", + "variant" to "3.0", + "java" to "8" + ), + mapOf( + "os" to "windows-latest", + "variant" to "4.0", + "java" to "8" + ), + mapOf( + "os" to "macos-latest", + "variant" to "2.5", + "java" to "8" + ), + mapOf( + "os" to "macos-latest", + "variant" to "3.0", + "java" to "8" + ), + mapOf( + "os" to "macos-latest", + "variant" to "4.0", + "java" to "8" + ) + ) + ) + ) + ) + ) { + uses( + name = "Checkout Repository", + action = CheckoutV3( + // Codecov needs fetch-depth > 1 + fetchDepth = CheckoutV3.FetchDepth.Value(2) + ) + ) + uses( + name = "Set up JDKs", + action = CustomAction( + actionOwner = ".github", + actionName = "actions/setup-build-env", + actionVersion = "v0", + inputs = mapOf( + "additional-java-version" to expr("matrix.java") + ) + ), + _customArguments = mapOf( + "uses" to "./.github/actions/setup-build-env" + ) + ) + val SPOCK_BUILD_CACHE_USERNAME by Contexts.secrets + val SPOCK_BUILD_CACHE_PASSWORD by Contexts.secrets + val GRADLE_ENTERPRISE_ACCESS_KEY by Contexts.secrets + uses( + name = "Build Spock", + action = GradleBuildActionV2( + arguments = """--no-parallel --stacktrace ghActionsBuild "-Dvariant=${expr("matrix.variant")}" "-DjavaVersion=${ + expr( + "matrix.java" + ) + }"""" + ), + // secrets are not injected for pull requests + env = linkedMapOf( + "ORG_GRADLE_PROJECT_spockBuildCacheUsername" to expr(SPOCK_BUILD_CACHE_USERNAME), + "ORG_GRADLE_PROJECT_spockBuildCachePassword" to expr(SPOCK_BUILD_CACHE_PASSWORD), + "GRADLE_ENTERPRISE_ACCESS_KEY" to expr(GRADLE_ENTERPRISE_ACCESS_KEY) + ) + ) + uses( + name = "Upload to Codecov.io", + action = CodecovActionV3() + ) + } +}.writeToFile() diff --git a/.github/workflows/branches-and-prs.yaml b/.github/workflows/branches-and-prs.yaml new file mode 100644 index 0000000000..7f30275c80 --- /dev/null +++ b/.github/workflows/branches-and-prs.yaml @@ -0,0 +1,94 @@ +# This file was generated using Kotlin DSL (.github/workflows/branches-and-prs.main.kts). +# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. +# Generated with https://github.com/typesafegithub/github-workflows-kt + +name: Verify Branches and PRs +on: + push: + branches-ignore: + - master + - gh-pages + pull_request: + branches: + - '*' +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +jobs: + check_yaml_consistency: + name: Check YAML consistency + runs-on: ubuntu-latest + steps: + - id: step-0 + name: Check out + uses: actions/checkout@v3 + - id: step-1 + name: Execute script + run: rm '.github/workflows/branches-and-prs.yaml' && '.github/workflows/branches-and-prs.main.kts' + - id: step-2 + name: Consistency check + run: git diff --exit-code '.github/workflows/branches-and-prs.yaml' + build-and-verify: + name: Build and Verify + runs-on: ${{ matrix.os }} + needs: + - check_yaml_consistency + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + variant: + - 2.5 + - 3.0 + - 4.0 + java: + - 8 + - 11 + - 17 + exclude: + - os: ubuntu-latest + variant: 2.5 + java: 17 + include: + - os: windows-latest + variant: 2.5 + java: 8 + - os: windows-latest + variant: 3.0 + java: 8 + - os: windows-latest + variant: 4.0 + java: 8 + - os: macos-latest + variant: 2.5 + java: 8 + - os: macos-latest + variant: 3.0 + java: 8 + - os: macos-latest + variant: 4.0 + java: 8 + steps: + - id: step-0 + name: Checkout Repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + - id: step-1 + name: Set up JDKs + uses: ./.github/actions/setup-build-env + with: + additional-java-version: ${{ matrix.java }} + - id: step-2 + name: Build Spock + uses: gradle/gradle-build-action@v2 + with: + arguments: --no-parallel --stacktrace ghActionsBuild "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}" + env: + ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }} + ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }} + GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + - id: step-3 + name: Upload to Codecov.io + uses: codecov/codecov-action@v3 diff --git a/.github/workflows/branches-and-prs.yml b/.github/workflows/branches-and-prs.yml deleted file mode 100644 index ea4c97ef3e..0000000000 --- a/.github/workflows/branches-and-prs.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: 'Verify Branches and PRs' - -on: - push: - branches-ignore: - - master - - gh-pages - pull_request: - branches: - - '*' - -# https://stackoverflow.com/a/72408109/16358266 -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - build-and-verify: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: ['ubuntu-latest'] - variant: ['2.5', '3.0', '4.0'] - java: ['8', '11', '17'] - exclude: - - os: 'ubuntu-latest' - variant: '2.5' - java: '17' - include: - - os: 'windows-latest' - variant: '2.5' - java: '8' - - os: 'windows-latest' - variant: '3.0' - java: '8' - - os: 'windows-latest' - variant: '4.0' - java: '8' - - os: 'macos-latest' - variant: '2.5' - java: '8' - - os: 'macos-latest' - variant: '3.0' - java: '8' - - os: 'macos-latest' - variant: '4.0' - java: '8' - steps: - - uses: actions/checkout@v3 - with: - # Codecov needs fetch-depth > 1 - fetch-depth: 2 - - name: 'Set up JDKs' - uses: ./.github/actions/setup-build-env - with: - additional-java-version: ${{ matrix.java }} - - name: 'Build Spock' - # secrets are not injected for pull requests - env: - ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }} - ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }} - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - uses: gradle/gradle-build-action@v2 - with: - arguments: --no-parallel --stacktrace ghActionsBuild "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}" - - name: 'Upload to Codecov.io' - uses: codecov/codecov-action@v3 diff --git a/.github/workflows/codeql-analysis.main.kts b/.github/workflows/codeql-analysis.main.kts new file mode 100755 index 0000000000..0a0e81e6bf --- /dev/null +++ b/.github/workflows/codeql-analysis.main.kts @@ -0,0 +1,147 @@ +#!/usr/bin/env kotlin + +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:DependsOn("io.github.typesafegithub:github-workflows-kt:0.40.1") + +import io.github.typesafegithub.workflows.actions.actions.CheckoutV3 +import io.github.typesafegithub.workflows.actions.gradle.GradleBuildActionV2 +import io.github.typesafegithub.workflows.domain.Concurrency +import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest +import io.github.typesafegithub.workflows.domain.actions.CustomAction +import io.github.typesafegithub.workflows.domain.triggers.Cron +import io.github.typesafegithub.workflows.domain.triggers.PullRequest +import io.github.typesafegithub.workflows.domain.triggers.Push +import io.github.typesafegithub.workflows.domain.triggers.Schedule +import io.github.typesafegithub.workflows.dsl.expressions.Contexts.github +import io.github.typesafegithub.workflows.dsl.expressions.expr +import io.github.typesafegithub.workflows.dsl.workflow +import io.github.typesafegithub.workflows.yaml.writeToFile + +workflow( + name = "Code scanning - action", + on = listOf( + Push( + branches = listOf("!dependabot/**") + ), + PullRequest(), + Schedule( + listOf( + Cron( + minute = "0", + hour = "15", + dayWeek = "TUE" + ) + ) + ) + ), + sourceFile = __FILE__.toPath(), + //# https://stackoverflow.com/a/72408109/16358266 + concurrency = Concurrency( + group = "${expr { github.workflow }}-${expr("${github.eventPullRequest.pull_request.number} || ${github.ref}")}", + cancelInProgress = true + ) +) { + job( + id = "codeql-build", + name = "CodeQL-Build", + // CodeQL runs on UbuntuLatest, WindowsLatest, and MacOSLatest + runsOn = UbuntuLatest, + _customArguments = mapOf( + "strategy" to mapOf( + "fail-fast" to false, + "matrix" to mapOf( + "variant" to listOf("2.5", "3.0", "4.0") + ) + ) + ) + ) { + uses( + name = "Checkout Repository", + action = CheckoutV3() + ) + // Manually added: Install and setup JDK + uses( + name = "Set up JDKs", + action = CustomAction( + actionOwner = ".github", + actionName = "actions/setup-build-env", + actionVersion = "v0", + inputs = emptyMap() + ), + _customArguments = mapOf( + "uses" to "./.github/actions/setup-build-env" + ) + ) + // Initializes the CodeQL tools for scanning + uses( + name = "Initialize CodeQL", + action = CustomAction( + actionOwner = "github", + actionName = "codeql-action/init", + actionVersion = "v2", + inputs = emptyMap() + // Override language selection by uncommenting this and choosing your languages + //inputs = mapOf("languages" to "go, javascript, csharp, python, cpp, java") + ) + ) + // Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + // If this step fails, then you should remove it and run the build manually (see below). + //uses( + // name = "Autobuild", + // action = CustomAction( + // actionOwner = "github", + // actionName = "codeql-action/autobuild", + // actionVersion = "v1", + // inputs = emptyMap() + // ) + //) + // + // ℹī¸ Command-line programs to run using the OS shell. + // 📚 https://git.io/JvXDl + // + // ✏ī¸ If the Autobuild fails above, remove it and uncomment the following + // three lines and modify them (or add more) to build your code if your + // project uses a compiled language + // + //run( + // command = """ + // make bootstrap + // make release + // """.trimIndent() + //) + + // Manually added: build + // we have to disable build cache for now as it seems to be necessary for the compiler to run during the build + // https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-the-codeql-workflow#no-code-found-during-the-build + uses( + name = "Build Spock Classes", + action = GradleBuildActionV2( + arguments = """--stacktrace --no-build-cache testClasses "-Dvariant=${expr("matrix.variant")}"""" + ) + ) + uses( + name = "Perform CodeQL Analysis", + action = CustomAction( + actionOwner = "github", + actionName = "codeql-action/analyze", + actionVersion = "v2", + inputs = emptyMap() + ) + ) + } +}.writeToFile() diff --git a/.github/workflows/codeql-analysis.yaml b/.github/workflows/codeql-analysis.yaml new file mode 100644 index 0000000000..fb0248fc62 --- /dev/null +++ b/.github/workflows/codeql-analysis.yaml @@ -0,0 +1,59 @@ +# This file was generated using Kotlin DSL (.github/workflows/codeql-analysis.main.kts). +# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. +# Generated with https://github.com/typesafegithub/github-workflows-kt + +name: Code scanning - action +on: + push: + branches: + - '!dependabot/**' + pull_request: {} + schedule: + - cron: 0 15 * * TUE +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +jobs: + check_yaml_consistency: + name: Check YAML consistency + runs-on: ubuntu-latest + steps: + - id: step-0 + name: Check out + uses: actions/checkout@v3 + - id: step-1 + name: Execute script + run: rm '.github/workflows/codeql-analysis.yaml' && '.github/workflows/codeql-analysis.main.kts' + - id: step-2 + name: Consistency check + run: git diff --exit-code '.github/workflows/codeql-analysis.yaml' + codeql-build: + name: CodeQL-Build + runs-on: ubuntu-latest + needs: + - check_yaml_consistency + strategy: + fail-fast: false + matrix: + variant: + - 2.5 + - 3.0 + - 4.0 + steps: + - id: step-0 + name: Checkout Repository + uses: actions/checkout@v3 + - id: step-1 + name: Set up JDKs + uses: ./.github/actions/setup-build-env + - id: step-2 + name: Initialize CodeQL + uses: github/codeql-action/init@v2 + - id: step-3 + name: Build Spock Classes + uses: gradle/gradle-build-action@v2 + with: + arguments: --stacktrace --no-build-cache testClasses "-Dvariant=${{ matrix.variant }}" + - id: step-4 + name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index a3b180141e..0000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: "Code scanning - action" - -on: - push: - branches: - - '!dependabot/**' - pull_request: - schedule: - - cron: '0 15 * * 2' - -# https://stackoverflow.com/a/72408109/16358266 -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - CodeQL-Build: - # CodeQL runs on ubuntu-latest, windows-latest, and macos-latest - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - variant: [ '2.5', '3.0', '4.0' ] - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Manually added: Install and setup JDK - - name: 'Set up JDKs' - uses: ./.github/actions/setup-build-env - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - # Override language selection by uncommenting this and choosing your languages - # with: - # languages: go, javascript, csharp, python, cpp, java - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below). - #- name: Autobuild - # uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following - # three lines and modify them (or add more) to build your code if your - # project uses a compiled language - - #- run: | - # make bootstrap - # make release - - # Manually added: build - # we have to disable build cache for now as it seems to be necessary for the compiler to run during the build - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-the-codeql-workflow#no-code-found-during-the-build - - name: 'Build Spock Classes' - uses: gradle/gradle-build-action@v2 - with: - arguments: --stacktrace --no-build-cache testClasses "-Dvariant=${{ matrix.variant }}" - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/gradle-wrapper-validation.main.kts b/.github/workflows/gradle-wrapper-validation.main.kts new file mode 100755 index 0000000000..6e0e014e68 --- /dev/null +++ b/.github/workflows/gradle-wrapper-validation.main.kts @@ -0,0 +1,51 @@ +#!/usr/bin/env kotlin + +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:DependsOn("io.github.typesafegithub:github-workflows-kt:0.40.1") + +import io.github.typesafegithub.workflows.actions.actions.CheckoutV3 +import io.github.typesafegithub.workflows.actions.gradle.WrapperValidationActionV1 +import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest +import io.github.typesafegithub.workflows.domain.triggers.PullRequest +import io.github.typesafegithub.workflows.domain.triggers.Push +import io.github.typesafegithub.workflows.dsl.workflow +import io.github.typesafegithub.workflows.yaml.writeToFile + +workflow( + name = "Validate Gradle Wrapper", + on = listOf( + Push(), + PullRequest() + ), + sourceFile = __FILE__.toPath() +) { + job( + id = "validation", + name = "Validation", + runsOn = UbuntuLatest + ) { + uses( + name = "Checkout Repository", + action = CheckoutV3() + ) + uses( + name = "Validate Wrapper", + action = WrapperValidationActionV1() + ) + } +}.writeToFile() diff --git a/.github/workflows/gradle-wrapper-validation.yaml b/.github/workflows/gradle-wrapper-validation.yaml new file mode 100644 index 0000000000..19bda3bd90 --- /dev/null +++ b/.github/workflows/gradle-wrapper-validation.yaml @@ -0,0 +1,34 @@ +# This file was generated using Kotlin DSL (.github/workflows/gradle-wrapper-validation.main.kts). +# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. +# Generated with https://github.com/typesafegithub/github-workflows-kt + +name: Validate Gradle Wrapper +on: + push: {} + pull_request: {} +jobs: + check_yaml_consistency: + name: Check YAML consistency + runs-on: ubuntu-latest + steps: + - id: step-0 + name: Check out + uses: actions/checkout@v3 + - id: step-1 + name: Execute script + run: rm '.github/workflows/gradle-wrapper-validation.yaml' && '.github/workflows/gradle-wrapper-validation.main.kts' + - id: step-2 + name: Consistency check + run: git diff --exit-code '.github/workflows/gradle-wrapper-validation.yaml' + validation: + name: Validation + runs-on: ubuntu-latest + needs: + - check_yaml_consistency + steps: + - id: step-0 + name: Checkout Repository + uses: actions/checkout@v3 + - id: step-1 + name: Validate Wrapper + uses: gradle/wrapper-validation-action@v1 diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml deleted file mode 100644 index 8bfd0dcf51..0000000000 --- a/.github/workflows/gradle-wrapper-validation.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: "Validate Gradle Wrapper" -on: [push, pull_request] - -jobs: - validation: - name: "Validation" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: gradle/wrapper-validation-action@v1 diff --git a/.github/workflows/release.main.kts b/.github/workflows/release.main.kts new file mode 100755 index 0000000000..d69863b5b7 --- /dev/null +++ b/.github/workflows/release.main.kts @@ -0,0 +1,255 @@ +#!/usr/bin/env kotlin + +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:DependsOn("io.github.typesafegithub:github-workflows-kt:0.40.1") + +import io.github.typesafegithub.workflows.actions.actions.CheckoutV3 +import io.github.typesafegithub.workflows.actions.actions.CheckoutV3.FetchDepth +import io.github.typesafegithub.workflows.actions.codecov.CodecovActionV3 +import io.github.typesafegithub.workflows.actions.gradle.GradleBuildActionV2 +import io.github.typesafegithub.workflows.domain.RunnerType +import io.github.typesafegithub.workflows.domain.actions.CustomAction +import io.github.typesafegithub.workflows.domain.triggers.Push +import io.github.typesafegithub.workflows.dsl.expressions.Contexts +import io.github.typesafegithub.workflows.dsl.expressions.Contexts.github +import io.github.typesafegithub.workflows.dsl.expressions.expr +import io.github.typesafegithub.workflows.dsl.workflow +import io.github.typesafegithub.workflows.yaml.writeToFile + +workflow( + name = "Build and Release Spock", + on = listOf( + Push( + branches = listOf("master"), + tags = listOf("spock-*") + ) + ), + sourceFile = __FILE__.toPath() +) { + val GITHUB_TOKEN by Contexts.secrets + val SONATYPE_OSS_USER by Contexts.secrets + val SONATYPE_OSS_PASSWORD by Contexts.secrets + val SIGNING_GPG_PASSWORD by Contexts.secrets + val SPOCK_BUILD_CACHE_USERNAME by Contexts.secrets + val SPOCK_BUILD_CACHE_PASSWORD by Contexts.secrets + val GRADLE_ENTERPRISE_ACCESS_KEY by Contexts.secrets + + val buildAndVerify = job( + id = "build-and-verify", + name = "Build and Verify", + runsOn = RunnerType.Custom(expr("matrix.os")), + condition = "${github.repository} == 'spockframework/spock'", + _customArguments = mapOf( + "strategy" to mapOf( + "fail-fast" to false, + "matrix" to mapOf( + "os" to listOf("ubuntu-latest"), + "variant" to listOf("2.5", "3.0", "4.0"), + "java" to listOf("8", "11", "17"), + "exclude" to listOf( + mapOf( + "os" to "ubuntu-latest", + "variant" to "2.5", + "java" to "17" + ) + ), + "include" to listOf( + mapOf( + "os" to "windows-latest", + "variant" to "2.5", + "java" to "8" + ), + mapOf( + "os" to "windows-latest", + "variant" to "3.0", + "java" to "8" + ), + mapOf( + "os" to "windows-latest", + "variant" to "4.0", + "java" to "8" + ), + mapOf( + "os" to "macos-latest", + "variant" to "2.5", + "java" to "8" + ), + mapOf( + "os" to "macos-latest", + "variant" to "3.0", + "java" to "8" + ), + mapOf( + "os" to "macos-latest", + "variant" to "4.0", + "java" to "8" + ) + ) + ) + ) + ) + ) { + uses( + name = "Checkout Repository", + action = CheckoutV3( + // Codecov needs fetch-depth > 1 + fetchDepth = FetchDepth.Value(2) + ) + ) + uses( + name = "Set up JDKs", + action = CustomAction( + actionOwner = ".github", + actionName = "actions/setup-build-env", + actionVersion = "v0", + inputs = mapOf( + "additional-java-version" to expr("matrix.java") + ) + ), + _customArguments = mapOf( + "uses" to "./.github/actions/setup-build-env" + ) + ) + uses( + name = "Build Spock", + action = GradleBuildActionV2( + arguments = """--no-parallel --stacktrace ghActionsBuild "-Dvariant=${expr("matrix.variant")}" "-DjavaVersion=${ + expr( + "matrix.java" + ) + }" "-Dscan.tag.main-build"""" + ), + env = linkedMapOf( + "ORG_GRADLE_PROJECT_spockBuildCacheUsername" to expr(SPOCK_BUILD_CACHE_USERNAME), + "ORG_GRADLE_PROJECT_spockBuildCachePassword" to expr(SPOCK_BUILD_CACHE_PASSWORD), + "GRADLE_ENTERPRISE_ACCESS_KEY" to expr(GRADLE_ENTERPRISE_ACCESS_KEY) + ) + ) + run( + name = "Stop Daemon", + command = "./gradlew --stop" + ) + uses( + name = "Upload to Codecov.io", + action = CodecovActionV3() + ) + } + val releaseSpock = job( + id = "release-spock", + name = "Release Spock", + runsOn = RunnerType.Custom(expr("matrix.os")), + needs = listOf(buildAndVerify), + strategyMatrix = mapOf( + "os" to listOf("ubuntu-latest"), + // publish needs to be done for all versions + "variant" to listOf("2.5", "3.0", "4.0"), + // publish needs the min supported java version + "java" to listOf("8") + ) + ) { + uses( + name = "Checkout Repository", + action = CheckoutV3() + ) + uses( + name = "Set up JDKs", + action = CustomAction( + actionOwner = ".github", + actionName = "actions/setup-build-env", + actionVersion = "v0", + inputs = mapOf( + "additional-java-version" to expr("matrix.java") + ) + ), + _customArguments = mapOf( + "uses" to "./.github/actions/setup-build-env" + ) + ) + uses( + name = "Publish Spock", + action = GradleBuildActionV2( + arguments = """--no-parallel --stacktrace ghActionsPublish "-Dvariant=${expr("matrix.variant")}" "-DjavaVersion=${ + expr( + "matrix.java" + ) + }" "-Dscan.tag.main-publish"""" + ), + env = linkedMapOf( + "GITHUB_TOKEN" to expr(GITHUB_TOKEN), + "SONATYPE_OSS_USER" to expr(SONATYPE_OSS_USER), + "SONATYPE_OSS_PASSWORD" to expr(SONATYPE_OSS_PASSWORD), + "SIGNING_PASSWORD" to expr(SIGNING_GPG_PASSWORD), + "ORG_GRADLE_PROJECT_spockBuildCacheUsername" to expr(SPOCK_BUILD_CACHE_USERNAME), + "ORG_GRADLE_PROJECT_spockBuildCachePassword" to expr(SPOCK_BUILD_CACHE_PASSWORD), + "GRADLE_ENTERPRISE_ACCESS_KEY" to expr(GRADLE_ENTERPRISE_ACCESS_KEY) + ) + ) + } + job( + id = "publish-release-docs", + name = "Publish Release Docs", + runsOn = RunnerType.Custom(expr("matrix.os")), + needs = listOf(releaseSpock), + strategyMatrix = mapOf( + "os" to listOf("ubuntu-latest"), + // docs need the highest variant + "variant" to listOf("4.0"), + // docs need the highest java version + "java" to listOf("17") + ) + ) { + uses( + name = "Checkout Repository", + action = CheckoutV3() + ) + uses( + name = "Set up JDKs", + action = CustomAction( + actionOwner = ".github", + actionName = "actions/setup-build-env", + actionVersion = "v0", + inputs = mapOf( + "additional-java-version" to expr("matrix.java") + ) + ), + _customArguments = mapOf( + "uses" to "./.github/actions/setup-build-env" + ) + ) + run( + name = "Create Temporary Branch", + command = "git checkout -b \"docs-\$GITHUB_SHA\"" + ) + uses( + name = "Publish Docs", + action = GradleBuildActionV2( + arguments = """--no-parallel --stacktrace ghActionsDocs "-Dvariant=${expr("matrix.variant")}" "-DjavaVersion=${ + expr( + "matrix.java" + ) + }" "-Dscan.tag.main-docs"""" + ), + env = linkedMapOf( + "GITHUB_TOKEN" to expr(GITHUB_TOKEN), + "ORG_GRADLE_PROJECT_spockBuildCacheUsername" to expr(SPOCK_BUILD_CACHE_USERNAME), + "ORG_GRADLE_PROJECT_spockBuildCachePassword" to expr(SPOCK_BUILD_CACHE_PASSWORD), + "GRADLE_ENTERPRISE_ACCESS_KEY" to expr(GRADLE_ENTERPRISE_ACCESS_KEY) + ) + ) + } +}.writeToFile() diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..8edf539c9f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,167 @@ +# This file was generated using Kotlin DSL (.github/workflows/release.main.kts). +# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. +# Generated with https://github.com/typesafegithub/github-workflows-kt + +name: Build and Release Spock +on: + push: + branches: + - master + tags: + - spock-* +jobs: + check_yaml_consistency: + name: Check YAML consistency + runs-on: ubuntu-latest + steps: + - id: step-0 + name: Check out + uses: actions/checkout@v3 + - id: step-1 + name: Execute script + run: rm '.github/workflows/release.yaml' && '.github/workflows/release.main.kts' + - id: step-2 + name: Consistency check + run: git diff --exit-code '.github/workflows/release.yaml' + build-and-verify: + name: Build and Verify + runs-on: ${{ matrix.os }} + needs: + - check_yaml_consistency + if: github.repository == 'spockframework/spock' + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + variant: + - 2.5 + - 3.0 + - 4.0 + java: + - 8 + - 11 + - 17 + exclude: + - os: ubuntu-latest + variant: 2.5 + java: 17 + include: + - os: windows-latest + variant: 2.5 + java: 8 + - os: windows-latest + variant: 3.0 + java: 8 + - os: windows-latest + variant: 4.0 + java: 8 + - os: macos-latest + variant: 2.5 + java: 8 + - os: macos-latest + variant: 3.0 + java: 8 + - os: macos-latest + variant: 4.0 + java: 8 + steps: + - id: step-0 + name: Checkout Repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + - id: step-1 + name: Set up JDKs + uses: ./.github/actions/setup-build-env + with: + additional-java-version: ${{ matrix.java }} + - id: step-2 + name: Build Spock + uses: gradle/gradle-build-action@v2 + with: + arguments: --no-parallel --stacktrace ghActionsBuild "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}" "-Dscan.tag.main-build" + env: + ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }} + ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }} + GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + - id: step-3 + name: Stop Daemon + run: ./gradlew --stop + - id: step-4 + name: Upload to Codecov.io + uses: codecov/codecov-action@v3 + release-spock: + name: Release Spock + runs-on: ${{ matrix.os }} + needs: + - build-and-verify + - check_yaml_consistency + strategy: + matrix: + os: + - ubuntu-latest + variant: + - 2.5 + - 3.0 + - 4.0 + java: + - 8 + steps: + - id: step-0 + name: Checkout Repository + uses: actions/checkout@v3 + - id: step-1 + name: Set up JDKs + uses: ./.github/actions/setup-build-env + with: + additional-java-version: ${{ matrix.java }} + - id: step-2 + name: Publish Spock + uses: gradle/gradle-build-action@v2 + with: + arguments: --no-parallel --stacktrace ghActionsPublish "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}" "-Dscan.tag.main-publish" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONATYPE_OSS_USER: ${{ secrets.SONATYPE_OSS_USER }} + SONATYPE_OSS_PASSWORD: ${{ secrets.SONATYPE_OSS_PASSWORD }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_GPG_PASSWORD }} + ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }} + ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }} + GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + publish-release-docs: + name: Publish Release Docs + runs-on: ${{ matrix.os }} + needs: + - release-spock + - check_yaml_consistency + strategy: + matrix: + os: + - ubuntu-latest + variant: + - 4.0 + java: + - 17 + steps: + - id: step-0 + name: Checkout Repository + uses: actions/checkout@v3 + - id: step-1 + name: Set up JDKs + uses: ./.github/actions/setup-build-env + with: + additional-java-version: ${{ matrix.java }} + - id: step-2 + name: Create Temporary Branch + run: git checkout -b "docs-$GITHUB_SHA" + - id: step-3 + name: Publish Docs + uses: gradle/gradle-build-action@v2 + with: + arguments: --no-parallel --stacktrace ghActionsDocs "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}" "-Dscan.tag.main-docs" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }} + ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }} + GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index d0323c2537..0000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,118 +0,0 @@ -name: 'Build and Release Spock' - -on: - push: - branches: - - master - tags: - - 'spock-*' - -jobs: - build-and-verify: - runs-on: ${{ matrix.os }} - if: github.repository == 'spockframework/spock' - strategy: - fail-fast: false - matrix: - os: [ 'ubuntu-latest' ] - variant: ['2.5', '3.0', '4.0'] - java: [ '8', '11', '17' ] - exclude: - - os: 'ubuntu-latest' - variant: '2.5' - java: '17' - include: - - os: 'windows-latest' - variant: '2.5' - java: '8' - - os: 'windows-latest' - variant: '3.0' - java: '8' - - os: 'windows-latest' - variant: '4.0' - java: '8' - - os: 'macos-latest' - variant: '2.5' - java: '8' - - os: 'macos-latest' - variant: '3.0' - java: '8' - - os: 'macos-latest' - variant: '4.0' - java: '8' - steps: - - uses: actions/checkout@v3 - with: - # Codecov needs fetch-depth > 1 - fetch-depth: 2 - - name: 'Set up JDKs' - uses: ./.github/actions/setup-build-env - with: - additional-java-version: ${{ matrix.java }} - - name: 'Build Spock' - env: - ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }} - ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }} - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - uses: gradle/gradle-build-action@v2 - with: - arguments: --no-parallel --stacktrace ghActionsBuild "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}" "-Dscan.tag.main-build" - - name: 'Stop Daemon' - run: | - ./gradlew --stop - - name: 'Upload to Codecov.io' - uses: codecov/codecov-action@v3 - - release-spock: - runs-on: ${{ matrix.os }} - needs: [ 'build-and-verify' ] - strategy: - matrix: - os: [ 'ubuntu-latest' ] - variant: [ '2.5', '3.0', '4.0' ] # publish needs to be done for all versions - java: [ '8' ] # publish needs the min supported java version - steps: - - uses: actions/checkout@v3 - - name: 'Set up JDKs' - uses: ./.github/actions/setup-build-env - with: - additional-java-version: ${{ matrix.java }} - - name: 'Publish Spock' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONATYPE_OSS_USER: ${{ secrets.SONATYPE_OSS_USER }} - SONATYPE_OSS_PASSWORD: ${{ secrets.SONATYPE_OSS_PASSWORD }} - SIGNING_PASSWORD: ${{ secrets.SIGNING_GPG_PASSWORD }} - ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }} - ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }} - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - uses: gradle/gradle-build-action@v2 - with: - arguments: --no-parallel --stacktrace ghActionsPublish "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}" "-Dscan.tag.main-publish" - - publish-release-docs: - runs-on: ${{ matrix.os }} - needs: ['release-spock'] - strategy: - matrix: - os: ['ubuntu-latest'] - variant: ['4.0'] # docs need the highest variant - java: ['17'] # docs need the highest java version - steps: - - uses: actions/checkout@v3 - - name: 'Set up JDKs' - uses: ./.github/actions/setup-build-env - with: - additional-java-version: ${{ matrix.java }} - - name: 'Create Temporary Branch' - run: | - git checkout -b "docs-$GITHUB_SHA" - - name: 'Publish Docs' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }} - ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }} - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - uses: gradle/gradle-build-action@v2 - with: - arguments: --no-parallel --stacktrace ghActionsDocs "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}" "-Dscan.tag.main-docs" diff --git a/build.gradle b/build.gradle index dbb2d1fdc5..bf65008acd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ import static groovy.io.FileType.FILES plugins { - id "base" + id "java-base" id "org.asciidoctor.jvm.convert" id "jacoco" id "net.nemerosa.versioning" @@ -463,3 +463,46 @@ def configureGroovydoc(TaskProvider groovydoc) { include "spock/**" } } + +configurations { + kotlinCompilerClasspath { + canBeConsumed = false + } + kotlinScriptClasspath { + canBeConsumed = false + } +} + +dependencies { + kotlinCompilerClasspath 'org.jetbrains.kotlin:kotlin-compiler:1.8.20' + kotlinCompilerClasspath 'org.jetbrains.kotlin:kotlin-scripting-compiler:1.8.20' + kotlinScriptClasspath('org.jetbrains.kotlin:kotlin-main-kts:1.8.20') { transitive = false } +} + +def preprocessWorkflows = tasks.register('preprocessWorkflows') +file('.github/workflows').eachFileMatch(~/.*\.main\.kts$/) { workflowScript -> + def workflowName = workflowScript.name - ~/\.main\.kts$/ + def pascalCasedWorkflowName = workflowName + .replaceAll(/-\w/) { it[1].toUpperCase() } + .replaceFirst(/^\w/) { it[0].toUpperCase() } + def preprocessWorkflow = tasks.register("preprocess${pascalCasedWorkflowName}Workflow", JavaExec) { + inputs + .file(workflowScript) + .withPropertyName('workflowScript') + outputs + .file(new File(workflowScript.parent, "${workflowName}.yaml")) + .withPropertyName('workflowFile') + + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(17) + } + classpath(configurations.kotlinCompilerClasspath) + mainClass = 'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler' + args('-no-stdlib', '-no-reflect') + args('-classpath', configurations.kotlinScriptClasspath.asPath) + args('-script', workflowScript.absolutePath) + } + preprocessWorkflows.configure { + dependsOn(preprocessWorkflow) + } +}