From da97a0f073cab5b0409ea12f2a1195a998fa7896 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sun, 12 Feb 2023 11:35:32 +0100 Subject: [PATCH] Add branch name when not master, simplify publish, use GitHub Actions And updated Gradle --- .github/workflows/build.yml | 30 +++++++++++++++++ build-logic/build.gradle.kts | 4 +-- build-logic/src/main/kotlin/extensions.kt | 20 ++++++------ .../floodgate.base-conventions.gradle.kts | 27 +++++++++------- .../floodgate.publish-conventions.gradle.kts | 32 ++++--------------- .../floodgate/util/ReflectionUtils.java | 4 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 10 +++--- settings.gradle.kts | 5 +++ 9 files changed, 79 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..6fb75dec --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,30 @@ +name: Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: actions/setup-java@v3 + with: + java-version: 8 + distribution: temurin + + - name: Build + uses: gradle/gradle-build-action@v2 + with: + arguments: build + + - name: Publish + uses: gradle/gradle-build-action@v2 + env: + ORG_GRADLE_PROJECT_geysermcUsername: "${{ secrets.DEPLOY_USER }}" + ORG_GRADLE_PROJECT_geysermcPassword: "${{ secrets.DEPLOY_PASS }}" + with: + arguments: publish \ No newline at end of file diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 75f6eda2..6200d2c9 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -9,8 +9,8 @@ repositories { } dependencies { - implementation("net.kyori", "indra-common", "2.0.6") - implementation("org.jfrog.buildinfo", "build-info-extractor-gradle", "4.26.1") + implementation("net.kyori", "indra-common", "3.0.1") + implementation("net.kyori", "indra-git", "3.0.1") implementation("gradle.plugin.com.github.johnrengelman", "shadow", "7.1.1") implementation("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext", "gradle-idea-ext", "1.1.7") } diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index 54158d84..cbb5e8a8 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -28,9 +28,6 @@ import org.gradle.api.Project import org.gradle.api.artifacts.ProjectDependency import org.gradle.kotlin.dsl.the -fun Project.isSnapshot(): Boolean = - version.toString().endsWith("-SNAPSHOT") - fun Project.fullVersion(): String { var version = version.toString() if (version.endsWith("-SNAPSHOT")) { @@ -42,14 +39,19 @@ fun Project.fullVersion(): String { fun Project.lastCommitHash(): String? = the().commit()?.name?.substring(0, 7) -// retrieved from https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project -// some properties might be specific to Jenkins fun Project.branchName(): String = - System.getenv("GIT_BRANCH") ?: "local/dev" -fun Project.buildNumber(): Int = - Integer.parseInt(System.getenv("BUILD_NUMBER") ?: "-1") + the().branchName() ?: System.getenv("BRANCH_NAME") ?: "local/dev" -fun Project.buildNumberAsString(): String = +fun Project.shouldAddBranchName(): Boolean = + System.getenv("IGNORE_BRANCH")?.toBoolean() ?: (branchName() !in arrayOf("master", "local/dev")) + +fun Project.versionWithBranchName(): String = + branchName().replace(Regex("[^0-9A-Za-z-_]"), "-") + '-' + version + +fun buildNumber(): Int = + System.getenv("BUILD_NUMBER")?.let { Integer.parseInt(it) } ?: -1 + +fun buildNumberAsString(): String = buildNumber().takeIf { it != -1 }?.toString() ?: "??" val providedDependencies = mutableMapOf>>() diff --git a/build-logic/src/main/kotlin/floodgate.base-conventions.gradle.kts b/build-logic/src/main/kotlin/floodgate.base-conventions.gradle.kts index 0dba1832..f1d9ab8f 100644 --- a/build-logic/src/main/kotlin/floodgate.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/floodgate.base-conventions.gradle.kts @@ -1,7 +1,7 @@ plugins { `java-library` - `maven-publish` // id("net.ltgt.errorprone") + id("net.kyori.indra") id("net.kyori.indra.git") } @@ -9,6 +9,21 @@ dependencies { compileOnly("org.checkerframework", "checker-qual", Versions.checkerQual) } +indra { + github("GeyserMC", "Floodgate") { + ci(true) + issues(true) + scm(true) + } + mitLicense() + + javaVersions { + // without toolchain & strictVersion sun.misc.Unsafe won't be found + minimumToolchain(8) + strictVersions(true) + } +} + tasks { processResources { filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json")) { @@ -22,14 +37,4 @@ tasks { ) } } - compileJava { - options.encoding = Charsets.UTF_8.name() - } -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - - withSourcesJar() } \ No newline at end of file diff --git a/build-logic/src/main/kotlin/floodgate.publish-conventions.gradle.kts b/build-logic/src/main/kotlin/floodgate.publish-conventions.gradle.kts index ad119489..39e180ae 100644 --- a/build-logic/src/main/kotlin/floodgate.publish-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/floodgate.publish-conventions.gradle.kts @@ -1,33 +1,15 @@ plugins { id("floodgate.shadow-conventions") - id("com.jfrog.artifactory") - id("maven-publish") + id("net.kyori.indra.publishing") } -publishing { - publications { - create("mavenJava") { - groupId = project.group as String - artifactId = project.name - version = project.version as String - - from(components["java"]) +indra { + configurePublications { + if (shouldAddBranchName()) { + version = versionWithBranchName() } } -} -artifactory { - setContextUrl("https://repo.opencollab.dev/artifactory") - publish { - repository { - setRepoKey(if (isSnapshot()) "maven-snapshots" else "maven-releases") - setMavenCompatible(true) - } - defaults { - publications("mavenJava") - setPublishArtifacts(true) - setPublishPom(true) - setPublishIvy(false) - } - } + publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/artifactory/maven-snapshots") + publishReleasesTo("geysermc", "https://repo.opencollab.dev/artifactory/maven-releases") } \ No newline at end of file diff --git a/core/src/main/java/org/geysermc/floodgate/util/ReflectionUtils.java b/core/src/main/java/org/geysermc/floodgate/util/ReflectionUtils.java index dfbc9d6a..709dfd43 100644 --- a/core/src/main/java/org/geysermc/floodgate/util/ReflectionUtils.java +++ b/core/src/main/java/org/geysermc/floodgate/util/ReflectionUtils.java @@ -287,7 +287,7 @@ public final class ReflectionUtils { } /** - * Get the value of a field and cast it to . + * Get the value of a field and cast it to T. * * @param instance the instance to get the value from * @param field the field to get the value from @@ -301,7 +301,7 @@ public final class ReflectionUtils { } /** - * Get the value of a field and cast it to . + * Get the value of a field and cast it to T. * * @param instance the instance to get the value from * @param fieldName the field to get the value from diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e5897..070cb702 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-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c7873..c53aefaa 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # diff --git a/settings.gradle.kts b/settings.gradle.kts index dadaef35..30992cbc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,4 @@ +@file:Suppress("UnstableApiUsage") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") dependencyResolutionManagement { @@ -54,6 +55,10 @@ pluginManagement { repositories { gradlePluginPortal() } + plugins { + id("net.kyori.indra") + id("net.kyori.indra.git") + } includeBuild("build-logic") }