diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index ff4ce284f0..f8e7f1ce5b 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -14,18 +14,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout sources - uses: actions/checkout@v2 - - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: - java-version: 17 distribution: temurin - - name: Grant execute permission for gradlew - run: chmod +x gradlew + java-version: 21 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 - name: Build Artifacts - uses: gradle/gradle-build-action@v2.4.2 - with: - arguments: build + run: ./gradlew build - name: Upload Artifacts uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b12cfa7edd..ab1a9fc5dd 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -21,18 +21,17 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 17 - uses: actions/setup-java@v2 + - name: Checkout sources + uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: - java-version: 17 distribution: temurin - - name: Grant execute permission for gradlew - run: chmod +x gradlew + java-version: 21 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 - name: Generate documentation directory - uses: gradle/gradle-build-action@v2.4.2 - with: - arguments: javadoc + run: ./gradlew javadoc - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000000..4e87df317e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,37 @@ +name: Publish to Maven Central + +on: + workflow_dispatch: + +concurrency: + group: "publish" + +jobs: + publish: + environment: maven-release + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - name: Release to Maven Central + env: + ORG_GRADLE_PROJECT_ossrhUser: ${{ secrets.OSSRH_USER }} + ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }} + ORG_GRADLE_PROJECT_stagingProfile: ${{ secrets.STAGING_PROFILE_ID }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_KEY }} + ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.GPG_KEYID }} + run: ./gradlew rebuild release + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: Artifacts + path: | + build/libs/*.jar + build/libs/*.jar.asc diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 0f00e0e5af..f4c5e6b3a5 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -1,6 +1,3 @@ -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle - name: Pull Request Validation on: @@ -12,12 +9,15 @@ on: jobs: build: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v1 - with: - java-version: 11 - - uses: gradle/gradle-build-action@v2.4.2 - with: - arguments: build test + - name: Checkout sources + uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - name: Build and test + run: ./gradlew build test diff --git a/build.gradle.kts b/build.gradle.kts index 4e35143e0f..b7f9308843 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,12 +41,12 @@ plugins { val javaVersion = JavaVersion.current() val versionObj = Version(major = "5", minor = "1", revision = "1", classifier = null) +val isGithubAction = System.getProperty("GITHUB_ACTION") != null || System.getenv("GITHUB_ACTION") != null val isCI = System.getProperty("BUILD_NUMBER") != null // jenkins || System.getenv("BUILD_NUMBER") != null || System.getProperty("GIT_COMMIT") != null // jitpack || System.getenv("GIT_COMMIT") != null - || System.getProperty("GITHUB_ACTION") != null // Github Actions - || System.getenv("GITHUB_ACTION") != null + || isGithubAction // Github Actions // Check the commit hash and version information val commitHash: String by lazy { @@ -66,10 +66,23 @@ val previousVersion: Version by lazy { versionObj } -val isNewVersion = previousVersion != versionObj +val signingKey: String? by project +val signingKeyId: String? by project +val ossrhUser: String? by project +val ossrhPassword: String? by project +val stagingProfile: String? by project + +val ossrhConfigured = ossrhUser != null && ossrhPassword != null +val canSign = signingKey != null && signingKeyId != null +val shouldPublish = canSign && ossrhConfigured && isGithubAction // Use normal version string for new releases and commitHash for other builds -project.version = "$versionObj" + if (isNewVersion) "" else "_$commitHash" +if (shouldPublish) { + project.version = "$versionObj" +} else { + project.version = "${versionObj}_$commitHash" +} + project.group = "net.dv8tion" @@ -395,21 +408,17 @@ publishing { } } -val ossrhConfigured = getProjectProperty("ossrhUser") != null -val canSign = getProjectProperty("signing.keyId") != null -val shouldPublish = isNewVersion && canSign && ossrhConfigured - -if (canSign) { - signing { - sign(publishing.publications.getByName("Release")) - } +signing { + useInMemoryPgpKeys(signingKeyId, signingKey, "") + sign(publishing.publications.getByName("Release")) + isRequired = shouldPublish } nexusPublishing { repositories.sonatype { - username.set(getProjectProperty("ossrhUser")) - password.set(getProjectProperty("ossrhPassword")) - stagingProfileId.set(getProjectProperty("stagingProfileId")) + username.set(ossrhUser) + password.set(ossrhPassword) + stagingProfileId.set(stagingProfile) } connectTimeout.set(Duration.ofMinutes(1)) @@ -452,13 +461,6 @@ val release by tasks.creating(Task::class) { enabled = shouldPublish dependsOn(publishingTasks) - - doLast { // Only runs when shouldPublish = true - logger.lifecycle("Saving version $versionObj to .version") - val file = layout.projectDirectory.file(".version") - file.asFile.createNewFile() - file.asFile.writeText(versionObj.toString()) - } } afterEvaluate { @@ -476,9 +478,6 @@ afterEvaluate { // // //////////////////////////////////// - -fun getProjectProperty(name: String) = project.properties[name] as? String - fun nullableReplacement(string: String?): String { return if (string == null) "null" else "\"$string\""