From 20c61a4d6bbba9b65721ead93336b4e99ab7b53e Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Wed, 17 Jul 2024 17:06:09 +0800 Subject: [PATCH] optimize build configs --- .github/workflows/publish-release.yml | 107 +++++++----------- .github/workflows/publish-snapshot.yml | 51 +++++++-- buildSrc/src/main/kotlin/P.kt | 11 +- .../simbot-telegram-maven-publish.gradle.kts | 88 -------------- ...ram-multiplatform-maven-publish.gradle.kts | 86 ++++++-------- .../simbot-telegram-nexus-publish.gradle.kts | 18 ++- gradle/libs.versions.toml | 6 +- 7 files changed, 140 insertions(+), 227 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/simbot-telegram-maven-publish.gradle.kts diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index af8af57..31d966a 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -5,6 +5,9 @@ on: - v** env: + JAVA_VERSION: 21 + JAVA_DISTRIBUTION: zulu + GRADLE_VERSION: 8.5 IS_CI: true GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} @@ -14,49 +17,63 @@ env: SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} GRADLE_OPTS: "-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8" - + SIMBOT_IS_SNAPSHOT: false + SIMBOT_RELEASES_ONLY: true jobs: - run-test-and-publish: - name: Run test and publish + run-test: + name: Run all tests strategy: matrix: os: [ macos-latest, ubuntu-latest, windows-latest ] runs-on: ${{ matrix.os }} steps: # 检出仓库代码 - - name: Check Out Repo - uses: actions/checkout@v4 - + - uses: actions/checkout@v4 # setup Java - name: Setup Java uses: actions/setup-java@v4 with: - distribution: 'zulu' - java-version: 21 + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} cache: 'gradle' - # setup Gradle - - name: Gradle Run Test + # https://github.com/gradle/actions/blob/main/docs/setup-gradle.md + - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 with: - gradle-version: 8.5 - arguments: assemble test -Porg.gradle.daemon=false + gradle-version: ${{ env.GRADLE_VERSION }} + + - name: Run all tests + run: gradle assemble allTests --stacktrace --warning-mode all + + publish-release: + name: Publish release + needs: run-test + runs-on: macos-latest + steps: + # 检出仓库代码 + - uses: actions/checkout@v4 + # setup Java + - uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + cache: 'gradle' # setup Gradle - - name: Publish Release + - name: Publish releases uses: gradle/actions/setup-gradle@v3 with: - gradle-version: 8.5 + gradle-version: ${{ env.GRADLE_VERSION }} arguments: | - publishToSonatype - closeAndReleaseStagingRepositories + publishToSonatype + closeAndReleaseStagingRepositories --info - --warning-mode all - -x test - --build-cache + --warning-mode all + -x test + --build-cache -Porg.gradle.jvmargs="-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8" - env: SIMBOT_IS_SNAPSHOT: false SIMBOT_RELEASES_ONLY: true @@ -64,7 +81,7 @@ jobs: create-release: name: Create release runs-on: ubuntu-latest - needs: run-test-and-publish + needs: publish-release permissions: contents: write steps: @@ -82,49 +99,10 @@ jobs: generate_release_notes: true prerelease: ${{ contains(github.ref_name, 'preview') || contains(github.ref_name, 'alpha') }} - # || contains(github.ref_name, 'beta') - - publish-snapshot: - name: Publish snapshot - strategy: - matrix: - os: [ macos-latest, windows-latest, ubuntu-latest ] - runs-on: ${{ matrix.os }} - needs: run-test-and-publish - steps: - # 检出仓库代码 - - name: Check out repo - uses: actions/checkout@v4 - - # setup Java - - name: Setup java - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: 21 - - # setup Gradle - - name: Gradle publish snapshot - uses: gradle/actions/setup-gradle@v3 - with: - gradle-version: 8.5 - arguments: | - publishToSonatype - closeAndReleaseStagingRepositories - --info - --warning-mode all - -x test - --build-cache - -Porg.gradle.jvmargs="-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8" - -Porg.gradle.daemon=false - env: - SIMBOT_IS_SNAPSHOT: true - SIMBOT_SNAPSHOT_ONLY: true - deploy-doc: name: Deploy-doc runs-on: ubuntu-latest - needs: run-test-and-publish + needs: publish-release steps: # 检出仓库代码 - name: Check out repo @@ -136,14 +114,15 @@ jobs: - name: Setup java uses: actions/setup-java@v4 with: - distribution: 'zulu' - java-version: 21 + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + cache: 'gradle' # setup Gradle - name: Gradle generate documentation uses: gradle/actions/setup-gradle@v3 with: - gradle-version: 8.5 + gradle-version: ${{ env.GRADLE_VERSION }} arguments: | dokkaHtmlMultiModule --info diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index e708f2f..97a4879 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -21,6 +21,9 @@ on: workflow_dispatch: env: + JAVA_VERSION: 21 + JAVA_DISTRIBUTION: zulu + GRADLE_VERSION: 8.5 IS_CI: true GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} @@ -35,12 +38,36 @@ env: jobs: - publish-snapshot: - name: Publish snapshot + run-test: + name: Run all tests strategy: matrix: - os: [ macos-latest, windows-latest, ubuntu-latest ] + os: [ macos-latest, ubuntu-latest, windows-latest ] runs-on: ${{ matrix.os }} + steps: + # 检出仓库代码 + - uses: actions/checkout@v4 + # setup Java + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + cache: 'gradle' + # setup Gradle + # https://github.com/gradle/actions/blob/main/docs/setup-gradle.md + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: ${{ env.GRADLE_VERSION }} + + - name: Run all tests + run: gradle assemble allTests --stacktrace --warning-mode all + + publish-snapshot: + name: Publish snapshot + needs: run-test + runs-on: macos-latest steps: # 检出仓库代码 - name: Check out repo @@ -50,14 +77,17 @@ jobs: - name: Setup java uses: actions/setup-java@v4 with: - distribution: 'zulu' - java-version: 21 + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + cache: 'gradle' # setup Gradle - uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: ${{ env.GRADLE_VERSION }} - - name: Gradle test and publish snapshot - run: gradle allTests publishToSonatype closeAndReleaseStagingRepositories --info --warning-mode all "-Porg.gradle.daemon=false" "-Porg.gradle.jvmargs='-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8'" + - name: Publish snapshots + run: gradle publishToSonatype closeAndReleaseStagingRepositories --info --warning-mode all -x test "-Porg.gradle.jvmargs='-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8'" - name: Upload test reports uses: actions/upload-artifact@v4 @@ -82,11 +112,14 @@ jobs: - name: Setup java uses: actions/setup-java@v4 with: - distribution: 'zulu' - java-version: 21 + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VERSION }} + cache: 'gradle' # setup Gradle - uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: ${{ env.GRADLE_VERSION }} - run: gradle dokkaHtmlMultiModule "-Porg.gradle.jvmargs='-Xmx4g -Xms4g -XX:MaxMetaspaceSize=2g -Dfile.encoding=UTF-8'" "-Porg.gradle.daemon=false" "-DisSnapshot=false" --info --warning-mode all -x test --build-cache diff --git a/buildSrc/src/main/kotlin/P.kt b/buildSrc/src/main/kotlin/P.kt index 556fa98..0725174 100644 --- a/buildSrc/src/main/kotlin/P.kt +++ b/buildSrc/src/main/kotlin/P.kt @@ -16,10 +16,7 @@ */ import love.forte.gradle.common.core.project.ProjectDetail -import love.forte.gradle.common.core.project.Version -import love.forte.gradle.common.core.project.minus import love.forte.gradle.common.core.property.systemProp -import love.forte.gradle.common.core.project.version as v /** @@ -43,11 +40,11 @@ object P { override val description: String get() = DESCRIPTION override val homepage: String get() = HOMEPAGE + const val VERSION = "0.0.5" + const val NEXT_VERSION = "0.0.6" - private val baseVersion = v(0, 1, 0) - - val snapshotVersion = baseVersion - Version.SNAPSHOT - override val version = if (isSnapshot()) snapshotVersion else baseVersion + override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT" + override val version = if (isSnapshot()) snapshotVersion else VERSION override val developers: List = developers { developer { diff --git a/buildSrc/src/main/kotlin/simbot-telegram-maven-publish.gradle.kts b/buildSrc/src/main/kotlin/simbot-telegram-maven-publish.gradle.kts deleted file mode 100644 index b5fc9fd..0000000 --- a/buildSrc/src/main/kotlin/simbot-telegram-maven-publish.gradle.kts +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2022-2024. ForteScarlet. - * - * This file is part of simbot-component-telegram. - * - * simbot-component-telegram is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * simbot-component-telegram is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with simbot-component-telegram. - * If not, see . - */ - -import love.forte.gradle.common.core.Gpg -import love.forte.gradle.common.publication.configure.jvmConfigPublishing -import util.checkPublishConfigurable -import util.isCi -import util.isLinux - - -plugins { - id("signing") - id("maven-publish") -} - -val (isSnapshotOnly, isReleaseOnly, isPublishConfigurable) = checkPublishConfigurable() - - -logger.info("isSnapshotOnly: {}", isSnapshotOnly) -logger.info("isReleaseOnly: {}", isReleaseOnly) -logger.info("isPublishConfigurable: {}", isPublishConfigurable) - -if (!isCi || isLinux) { - checkPublishConfigurable { - jvmConfigPublishing { - project = P.ComponentTelegram - publicationName = "QQGuildDist" - isSnapshot = isSnapshot().also { - logger.info("jvmConfigPublishing.isSnapshot: {}", it) - } - - val jarSources by tasks.registering(Jar::class) { - archiveClassifier.set("sources") - from(sourceSets["main"].allSource) - } - - val jarJavadoc by tasks.registering(Jar::class) { - if (!(isSnapshot || isSnapshot())) { - dependsOn(tasks.dokkaHtml) - from(tasks.dokkaHtml.flatMap { it.outputDirectory }) - } - archiveClassifier.set("javadoc") - } - - artifact(jarSources) - artifact(jarJavadoc) - - releasesRepository = ReleaseRepository - snapshotRepository = SnapshotRepository - gpg = Gpg.ofSystemPropOrNull() - } - } - - show() -} - - -inline val Project.sourceSets: SourceSetContainer - get() = extensions.getByName("sourceSets") as SourceSetContainer - -internal val TaskContainer.dokkaHtml: TaskProvider - get() = named("dokkaHtml") - -fun Project.show() { - //// show project info - logger.info("========================================================") - logger.info("== project.group: $group") - logger.info("== project.name: $name") - logger.info("== project.version: $version") - logger.info("== project.description: $description") - logger.info("========================================================") -} - - diff --git a/buildSrc/src/main/kotlin/simbot-telegram-multiplatform-maven-publish.gradle.kts b/buildSrc/src/main/kotlin/simbot-telegram-multiplatform-maven-publish.gradle.kts index 4d618c0..f94d820 100644 --- a/buildSrc/src/main/kotlin/simbot-telegram-multiplatform-maven-publish.gradle.kts +++ b/buildSrc/src/main/kotlin/simbot-telegram-multiplatform-maven-publish.gradle.kts @@ -18,7 +18,9 @@ import love.forte.gradle.common.core.Gpg import love.forte.gradle.common.core.project.setup import love.forte.gradle.common.core.property.systemProp -import love.forte.gradle.common.publication.configure.multiplatformConfigPublishing +import love.forte.gradle.common.publication.configure.configPublishMaven +import love.forte.gradle.common.publication.configure.publishingExtension +import love.forte.gradle.common.publication.configure.setupPom plugins { signing @@ -28,62 +30,44 @@ plugins { setup(P.ComponentTelegram) val p = project -multiplatformConfigPublishing { - project = P.ComponentTelegram - isSnapshot = project.version.toString().contains("SNAPSHOT", true) - releasesRepository = ReleaseRepository - snapshotRepository = SnapshotRepository - gpg = Gpg.ofSystemPropOrNull() - - // publishing { - // publications.withType { - // val dokkaJar = p.tasks.register("${name}DokkaJar", Jar::class) { - // group = JavaBasePlugin.DOCUMENTATION_GROUP - // description = "Assembles Kotlin docs with Dokka into a Javadoc jar" - // archiveClassifier.set("javadoc") - // from(tasks.named("dokkaHtml")) - // - // // Each archive name should be distinct, to avoid implicit dependency issues. - // // We use the same format as the sources Jar tasks. - // // https://youtrack.jetbrains.com/issue/KT-46466 - // archiveBaseName.set("${archiveBaseName.get()}-${name}") - // } - // artifact(dokkaJar) - // } - // } - - val jarJavadoc by tasks.registering(Jar::class) { - group = "documentation" - archiveClassifier.set("javadoc") - if (!(isSnapshot || isSnapshot() || isSimbotLocal())) { - dependsOn(tasks.dokkaHtml) - from(tasks.dokkaHtml.flatMap { it.outputDirectory }) - // from(tasks.findByName("dokkaHtml")) - } +val isSnapshot = isSnapshot() + +val jarJavadoc by tasks.registering(Jar::class) { + group = "documentation" + archiveClassifier.set("javadoc") + if (!(isSnapshot || isSnapshot() || isSimbotLocal())) { + dependsOn(tasks.dokkaHtml) + from(tasks.dokkaHtml.flatMap { it.outputDirectory }) + // from(tasks.findByName("dokkaHtml")) } +} +publishing { + repositories { + mavenLocal() + if (isSnapshot) { + configPublishMaven(SnapshotRepository) + } else { + configPublishMaven(ReleaseRepository) + } + } - // val dokkaJar = p.tasks.register("${publication.name}DokkaJar", Jar::class) { - // group = JavaBasePlugin.DOCUMENTATION_GROUP - // description = "Assembles Kotlin docs with Dokka into a Javadoc jar" - // archiveClassifier.set("javadoc") - // from(tasks.named("dokkaHtml")) - // - // // Each archive name should be distinct, to avoid implicit dependency issues. - // // We use the same format as the sources Jar tasks. - // // https://youtrack.jetbrains.com/issue/KT-46466 - // archiveBaseName.set("${archiveBaseName.get()}-${publication.name}") - // } - - artifact(jarJavadoc) + publications { + withType { + artifacts { + artifact(jarJavadoc) + } - if (isSimbotLocal()) { - logger.info("Is 'SIMBOT_LOCAL', mainHost set as null") - mainHost = null + setupPom(project.name, P.ComponentTelegram) + } } +} - publicationsFromMainHost += listOf("wasm", "wasm32", "wasm_js") - mainHostSupportedTargets += listOf("wasm", "wasm32", "wasm_js") +signing { + val gpg = Gpg.ofSystemPropOrNull() ?: return@signing + val (keyId, secretKey, password) = gpg + useInMemoryPgpKeys(keyId, secretKey, password) + sign(publishingExtension.publications) } // TODO see https://github.com/gradle-nexus/publish-plugin/issues/208#issuecomment-1465029831 diff --git a/buildSrc/src/main/kotlin/simbot-telegram-nexus-publish.gradle.kts b/buildSrc/src/main/kotlin/simbot-telegram-nexus-publish.gradle.kts index 16b8af4..a0bb3df 100644 --- a/buildSrc/src/main/kotlin/simbot-telegram-nexus-publish.gradle.kts +++ b/buildSrc/src/main/kotlin/simbot-telegram-nexus-publish.gradle.kts @@ -17,7 +17,7 @@ import love.forte.gradle.common.core.project.setup import love.forte.gradle.common.core.repository.Repositories -import love.forte.gradle.common.publication.configure.nexusPublishConfig +import java.time.Duration plugins { id("io.github.gradle-nexus.publish-plugin") @@ -31,10 +31,17 @@ if (userInfo == null) { logger.warn("sonatype.username or sonatype.password is null, cannot config nexus publishing.") } -nexusPublishConfig { - projectDetail = P.ComponentTelegram - useStaging = project.provider { !project.version.toString().endsWith("SNAPSHOT", ignoreCase = true) } - repositoriesConfig = { +nexusPublishing { + packageGroup.set(P.ComponentTelegram.group) + repositoryDescription.set(P.ComponentTelegram.description) + useStaging = project.provider { !isSnapshot() } + + transitionCheckOptions { + maxRetries = 1000 + delayBetween = Duration.ofSeconds(2) + } + + repositories { sonatype { snapshotRepositoryUrl.set(uri(Repositories.Snapshot.URL)) username.set(userInfo?.username) @@ -42,3 +49,4 @@ nexusPublishConfig { } } } + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1034013..d048046 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,14 +5,14 @@ kotlinx-serialization = "1.6.3" kotlinx-datetime = "0.6.0" dokka = "1.9.20" okio = "3.3.0" -ktor = "2.3.8" +ktor = "2.3.11" openjdk-jmh = "1.35" log4j = "2.20.0" reactor = "3.6.2" # simbot -simbot = "4.0.0" +simbot = "4.1.0" suspendTransform = "0.9.0" -gradleCommon = "0.4.0" +gradleCommon = "0.6.0" # ksp ksp = "2.0.0-1.0.22" # https://square.github.io/kotlinpoet/