From 507b8d5e35d7a8894e7bedc1564d2698900deefd Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Mon, 22 Nov 2021 13:38:32 +0100 Subject: [PATCH] ci: Switch deployment to gh actions and use semver & java 17 --- .github/workflows/build.yml | 41 +++++++++++------ build.gradle.kts | 8 ++-- buildSrc/build.gradle.kts | 1 + buildSrc/src/main/kotlin/CommonConfig.kt | 2 +- buildSrc/src/main/kotlin/CommonJavaConfig.kt | 4 +- buildSrc/src/main/kotlin/LibsConfig.kt | 47 +++++++++----------- buildSrc/src/main/kotlin/PlatformConfig.kt | 43 +++++++++--------- 7 files changed, 77 insertions(+), 69 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30201b465..3137c908c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,18 +7,9 @@ jobs: runs-on: "ubuntu-latest" steps: - name: "Checkout Repository" - uses: "actions/checkout@v2.3.4" + uses: "actions/checkout@v2.4.0" - name : "Validate Gradle Wrapper" uses : "gradle/wrapper-validation-action@v1.0.4" - - name: "Grab SHA" - uses: "benjlevesque/short-sha@v1.2" - id: "short-sha" - with: - length: "7" - - name: "Echo SHA" - run: "echo $SHA" - env: - SHA: "${{ steps.short-sha.outputs.sha }}" - name: "Setup Java" uses: "actions/setup-java@v2.3.1" with: @@ -27,8 +18,30 @@ jobs: java-version: "17" - name: "Clean Build" run: "./gradlew clean build --no-daemon" - - name: Archive Artifacts - uses: actions/upload-artifact@v2 + - name: "Determine release status" + if: "${{ runner.os == 'Linux' }}" + run: | + if [ "$(./gradlew properties | awk '/^version:/ { print $2; }' | grep '\-SNAPSHOT')" ]; then + echo "STATUS=snapshot" >> $GITHUB_ENV + else + echo "STATUS=release" >> $GITHUB_ENV + fi + - name: "Publish Release" + if: "${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main'}}" + run: "./gradlew publishToSonatype closeSonatypeStagingRepository" + env: + ORG_GRADLE_PROJECT_sonatypeUsername: "${{ secrets.SONATYPE_USERNAME }}" + ORG_GRADLE_PROJECT_sonatypePassword: "${{ secrets.SONATYPE_PASSWORD }}" + ORG_GRADLE_PROJECT_signingKey: "${{ secrets.SIGNING_KEY }}" + ORG_GRADLE_PROJECT_signingPassword: "${{ secrets.SIGNING_PASSWORD }}" + - name: "Publish Snapshot" + if: "${{ runner.os == 'Linux' && env.STATUS != 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}" + run: "./gradlew publishToSonatype" + env: + ORG_GRADLE_PROJECT_sonatypeUsername: "${{ secrets.SONATYPE_USERNAME }}" + ORG_GRADLE_PROJECT_sonatypePassword: "${{ secrets.SONATYPE_PASSWORD }}" + - name: "Archive Artifacts" + uses: "actions/upload-artifact@v2.2.4" with: - name: FastAsyncWorldEdit-Bukkit-1.17-${{ env.SHA }} - path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-1.17-${{ env.SHA }}.jar + name: "FastAsyncWorldEdit-Bukkit-SNAPSHOT" + path: "worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar" diff --git a/build.gradle.kts b/build.gradle.kts index 018b45f39..05749e19e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,8 @@ logger.lifecycle(""" ******************************************* """) -var rootVersion by extra("1.17") +var rootVersion by extra("2.0.0") +var snapshot by extra("SNAPSHOT") var revision: String by extra("") var buildNumber by extra("") var date: String by extra("") @@ -27,15 +28,14 @@ ext { } date = git.head().dateTime.format(DateTimeFormatter.ofPattern("yy.MM.dd")) revision = "-${git.head().abbreviatedId}" - val commit: String? = git.head().abbreviatedId buildNumber = if (project.hasProperty("buildnumber")) { project.properties["buildnumber"] as String } else { - commit.toString() + null.toString() //1.18 TODO: drop classifier if not used, otherwise the version is 'null' } } -version = String.format("%s-%s", rootVersion, buildNumber) +version = String.format("%s-%s+%s", rootVersion, snapshot, buildNumber) if (!project.hasProperty("gitCommitHash")) { apply(plugin = "org.ajoberstar.grgit") diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 32d43750f..6a5085ec5 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -29,4 +29,5 @@ dependencies { implementation("org.ajoberstar.grgit:grgit-gradle:4.1.0") implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.0") implementation("io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.1.14") + implementation("io.github.gradle-nexus:publish-plugin:1.1.0") } diff --git a/buildSrc/src/main/kotlin/CommonConfig.kt b/buildSrc/src/main/kotlin/CommonConfig.kt index d746fcefa..c658cf173 100644 --- a/buildSrc/src/main/kotlin/CommonConfig.kt +++ b/buildSrc/src/main/kotlin/CommonConfig.kt @@ -42,7 +42,7 @@ fun Project.applyCommonConfiguration() { plugins.withId("java") { the().toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) + languageVersion.set(JavaLanguageVersion.of(17)) } } diff --git a/buildSrc/src/main/kotlin/CommonJavaConfig.kt b/buildSrc/src/main/kotlin/CommonJavaConfig.kt index b0029429c..21c059715 100644 --- a/buildSrc/src/main/kotlin/CommonJavaConfig.kt +++ b/buildSrc/src/main/kotlin/CommonJavaConfig.kt @@ -24,7 +24,7 @@ fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, banSlf4j: Boolean val disabledLint = listOf( "processing", "path", "fallthrough", "serial" ) - options.release.set(11) + options.release.set(17) options.compilerArgs.addAll(listOf("-Xlint:all") + disabledLint.map { "-Xlint:-$it" }) options.isDeprecation = true options.encoding = "UTF-8" @@ -32,7 +32,7 @@ fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, banSlf4j: Boolean } configurations.all { - attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16) + attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17) } tasks.withType().configureEach { diff --git a/buildSrc/src/main/kotlin/LibsConfig.kt b/buildSrc/src/main/kotlin/LibsConfig.kt index e0eeb117d..bdcadc009 100644 --- a/buildSrc/src/main/kotlin/LibsConfig.kt +++ b/buildSrc/src/main/kotlin/LibsConfig.kt @@ -1,4 +1,5 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import io.github.gradlenexus.publishplugin.NexusPublishExtension import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.ExternalModuleDependency @@ -21,6 +22,8 @@ import org.gradle.kotlin.dsl.invoke import org.gradle.kotlin.dsl.named import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.register +import org.gradle.plugins.signing.SigningExtension +import java.net.URI import javax.inject.Inject fun Project.applyLibrariesConfiguration() { @@ -28,6 +31,8 @@ fun Project.applyLibrariesConfiguration() { apply(plugin = "java-base") apply(plugin = "maven-publish") apply(plugin = "com.github.johnrengelman.shadow") + apply(plugin = "signing") + apply(plugin = "io.github.gradle-nexus.publish-plugin") configurations { create("shade") @@ -112,7 +117,7 @@ fun Project.applyLibrariesConfiguration() { attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11) + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17) } outgoing.artifact(tasks.named("jar")) } @@ -127,7 +132,7 @@ fun Project.applyLibrariesConfiguration() { attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11) + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17) } outgoing.artifact(tasks.named("jar")) } @@ -158,6 +163,16 @@ fun Project.applyLibrariesConfiguration() { mapToMavenScope("runtime") } + configure { + if (!version.toString().endsWith("-SNAPSHOT")) { + val signingKey: String? by project + val signingPassword: String? by project + useInMemoryPgpKeys(signingKey, signingPassword) + isRequired + sign(tasks["publications"]) + } + } + configure { publications { register("maven") { @@ -212,31 +227,13 @@ fun Project.applyLibrariesConfiguration() { } } } + } + configure { repositories { - mavenLocal() - val nexusUsername: String? by project - val nexusPassword: String? by project - if (nexusUsername != null && nexusPassword != null) { - maven { - val releasesRepositoryUrl = "https://mvn.intellectualsites.com/content/repositories/releases/" - val snapshotRepositoryUrl = "https://mvn.intellectualsites.com/content/repositories/snapshots/" - /* Commenting this out for now - Fawe currently does not user semver or any sort of versioning that - differentiates between snapshots and releases, API & (past) deployment wise, this will come with a next major release. - url = uri( - if (version.toString().endsWith("-SNAPSHOT")) snapshotRepositoryUrl - else releasesRepositoryUrl - ) - */ - url = uri(releasesRepositoryUrl) - - credentials { - username = nexusUsername - password = nexusPassword - } - } - } else { - logger.warn("No nexus repository is added; nexusUsername or nexusPassword is null.") + sonatype { + nexusUrl.set(URI.create("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/")) } } } diff --git a/buildSrc/src/main/kotlin/PlatformConfig.kt b/buildSrc/src/main/kotlin/PlatformConfig.kt index 6f805aece..0d0b09f75 100644 --- a/buildSrc/src/main/kotlin/PlatformConfig.kt +++ b/buildSrc/src/main/kotlin/PlatformConfig.kt @@ -12,6 +12,9 @@ import org.gradle.kotlin.dsl.named import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.the +import org.gradle.plugins.signing.SigningExtension +import io.github.gradlenexus.publishplugin.NexusPublishExtension +import java.net.URI fun Project.applyPlatformAndCoreConfiguration() { applyCommonConfiguration() @@ -20,6 +23,8 @@ fun Project.applyPlatformAndCoreConfiguration() { apply(plugin = "idea") apply(plugin = "maven-publish") apply(plugin = "com.github.johnrengelman.shadow") + apply(plugin = "signing") + apply(plugin = "io.github.gradle-nexus.publish-plugin") applyCommonJavaConfiguration( sourcesJar = name in setOf("worldedit-core", "worldedit-bukkit"), @@ -45,6 +50,16 @@ fun Project.applyPlatformAndCoreConfiguration() { skip() } + configure { + if (!version.toString().endsWith("-SNAPSHOT")) { + val signingKey: String? by project + val signingPassword: String? by project + useInMemoryPgpKeys(signingKey, signingPassword) + isRequired + sign(tasks["publications"]) + } + } + configure { publications { register("maven") { @@ -99,31 +114,13 @@ fun Project.applyPlatformAndCoreConfiguration() { } } } + } + configure { repositories { - mavenLocal() - val nexusUsername: String? by project - val nexusPassword: String? by project - if (nexusUsername != null && nexusPassword != null) { - maven { - val releasesRepositoryUrl = "https://mvn.intellectualsites.com/content/repositories/releases/" - val snapshotRepositoryUrl = "https://mvn.intellectualsites.com/content/repositories/snapshots/" - /* Commenting this out for now - Fawe currently does not user semver or any sort of versioning that - differentiates between snapshots and releases, API & (past) deployment wise, this will come with a next major release. - url = uri( - if (version.toString().endsWith("-SNAPSHOT")) snapshotRepositoryUrl - else releasesRepositoryUrl - ) - */ - url = uri(releasesRepositoryUrl) - - credentials { - username = nexusUsername - password = nexusPassword - } - } - } else { - logger.warn("No nexus repository is added; nexusUsername or nexusPassword is null.") + sonatype { + nexusUrl.set(URI.create("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/")) } } }