From 0a63f94d8d443b80e904f06e04955e5db06e0ef0 Mon Sep 17 00:00:00 2001 From: Francisco Solis <30329003+Im-Fran@users.noreply.github.com> Date: Tue, 16 Jan 2024 00:38:37 -0300 Subject: [PATCH] wip: publishing & deployment updates --- .github/workflows/deploy-development.yml | 41 ++++++ .../{deploy.yml => deploy-production.yml} | 4 +- build.gradle.kts | 129 ++++++++++++++++-- simplecoreapi/build.gradle.kts | 24 ++-- 4 files changed, 171 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/deploy-development.yml rename .github/workflows/{deploy.yml => deploy-production.yml} (96%) diff --git a/.github/workflows/deploy-development.yml b/.github/workflows/deploy-development.yml new file mode 100644 index 00000000..2fd0d1c7 --- /dev/null +++ b/.github/workflows/deploy-development.yml @@ -0,0 +1,41 @@ +#name: "Build and Deploy [development]" +#on: +# push: +# paths: [ 'simplecoreapi/**' ] +#jobs: +# build: +# name: "Build and Deploy [development]" +# if: ${{ github.ref != 'refs/heads/master' && !contains(github.event.head_commit.message, '[skip ci]') }} +# # Set up the OS +# runs-on: ubuntu-latest +# env: +# # Sonatype Credentials & GitHub token +# SONATYPE_USERNAME: '${{ secrets.SONATYPE_USERNAME }}' +# SONATYPE_PASSWORD: '${{ secrets.SONATYPE_PASSWORD }}' +# GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' +# # Set environment +# ENV: 'dev' +# steps: +# # Checkout the Code +# - name: Checkout Code +# uses: actions/checkout@v4 +# # Set up git hashes environment variables +# - name: Git Hashes +# uses: Im-Fran/git-hashes-action@v1.0.3 +# # Set up the JDK +# - name: Set up JDK 11 +# uses: actions/setup-java@v4 +# with: +# distribution: adopt +# java-version: 11 +# # Clean, Test, Publish and Build (in that order to save the artifact to the action) +# - name: Build with Gradle +# uses: gradle/gradle-build-action@v2 +# with: +# arguments: clean test shadowJar dokkaHtml publish publishToSonatype closeAndReleaseSonatypeStagingRepository +# # Now we store the artifact in the action +# - name: Upload the artifact +# uses: actions/upload-artifact@v5 +# with: +# name: SimpleCoreAPI +# path: ./simplecoreapi/build/libs/SimpleCoreAPI-${{ env.GIT_COMMIT_SHORT_HASH }}.jar diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy-production.yml similarity index 96% rename from .github/workflows/deploy.yml rename to .github/workflows/deploy-production.yml index 0b930977..9cb0fc09 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy-production.yml @@ -1,10 +1,10 @@ -name: "Build and Deploy" +name: "Build and Deploy [production]" on: release: types: [published,edited] jobs: build: - name: "Build and Deploy" + name: "Build and Deploy [production]" # Set up the OS runs-on: ubuntu-latest env: diff --git a/build.gradle.kts b/build.gradle.kts index f103680d..ab18cec0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,15 @@ + +import com.github.jengelman.gradle.plugins.shadow.ShadowExtension import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.util.* plugins { + `maven-publish` + id("com.github.johnrengelman.shadow") version "8.1.1" // ShadowJar id("cl.franciscosolis.gradledotenv") version "1.0.1" // .env support - kotlin("jvm") version "1.9.21" // Kotlin + kotlin("jvm") version "1.9.22" // Kotlin + id("org.jetbrains.dokka") version "1.9.10" // Dokka (Kotlin Docs) } allprojects { @@ -14,7 +19,13 @@ allprojects { plugin("org.jetbrains.kotlin.jvm") } - val projectVersion = (env["VERSION"] ?: "1.0.0") + /* + The project version can be: + - environment variable VERSION or the manually added version + - If the environment variable ENV is set to dev, the project + version will have appended the git commit short hash + SNAPSHOT + */ + val projectVersion = (env["VERSION"] ?: "1.0.0") + (if(env["ENV"] == "dev") "-${env["GIT_COMMIT_SHORT_HASH"] ?: UUID.randomUUID().toString().replace("-", "").split("").shuffled().joinToString("").substring(0,8)}-SNAPSHOT" else "") group = "xyz.theprogramsrc" version = projectVersion.replaceFirst("v", "").replace("/", "") @@ -54,14 +65,110 @@ tasks { archiveClassifier.set("") } - withType { - kotlinOptions { - jvmTarget = "11" - } + compileKotlin { + kotlinOptions.jvmTarget = "11" + } + + compileTestKotlin { + kotlinOptions.jvmTarget = "11" + } + + compileJava { + options.encoding = "UTF-8" + } + + java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + withSourcesJar() + withJavadocJar() } + + jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + + copy { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + + dokkaHtml { + outputDirectory.set(layout.buildDirectory.dir("dokka/")) + } +} + +val dokkaJavadocJar by tasks.register("dokkaJavadocJar") { + dependsOn(tasks.dokkaJavadoc, tasks.dokkaHtml) + from(tasks.dokkaJavadoc.flatMap { it.outputDirectory }) + archiveClassifier.set("javadoc") } -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file +publishing { + repositories { + if (env["ENV"] == "prod" || env["ENV"] == "dev") { + if (env["GITHUB_ACTOR"] != null && env["GITHUB_TOKEN"] != null) { + maven { + name = "GithubPackages" + url = uri("https://maven.pkg.github.com/TheProgramSrc/SimpleCoreAPI") + credentials { + username = env["GITHUB_ACTOR"] + password = env["GITHUB_TOKEN"] + } + } + } + + if(env["SONATYPE_USERNAME"] != null && env["SONATYPE_PASSWORD"] != null) { + maven { + name = "Sonatype" + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") + credentials { + username = env["SONATYPE_USERNAME"] + password = env["SONATYPE_PASSWORD"] + } + } + } + } + + if(env["ENV"] != "prod") { + mavenLocal() + } + } + + publications { + create("shadow") { + + project.extensions.configure { + artifactId = rootProject.name.lowercase() + + component(this@create) + artifact(dokkaJavadocJar) + artifact(tasks.kotlinSourcesJar) + + pom { + name.set(rootProject.name) + description.set(project.description) + url.set("https://github.com/TheProgramSrc/SimpleCoreAPI") + + licenses { + license { + name.set("GNU GPL v3") + url.set("https://github.com/TheProgramSrc/SimpleCoreAPI/blob/master/LICENSE") + } + } + + developers { + developer { + id.set("ImFran") + name.set("Francisco Solis") + email.set("imfran@duck.com") + } + } + + scm { + url.set("https://github.com/TheProgramSrc/SimpleCoreAPI") + } + } + } + } + } +} diff --git a/simplecoreapi/build.gradle.kts b/simplecoreapi/build.gradle.kts index a934ef53..b832601c 100644 --- a/simplecoreapi/build.gradle.kts +++ b/simplecoreapi/build.gradle.kts @@ -2,7 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar dependencies { /* Api */ - implementation(project(":build-info")) + compileOnly(project(":build-info")) /* Runtimes */ compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") @@ -59,29 +59,25 @@ tasks { useJUnitPlatform() } - java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - withSourcesJar() - withJavadocJar() - } - compileKotlin { - kotlinOptions { - jvmTarget = "11" - } + kotlinOptions.jvmTarget = "11" } compileTestKotlin { - kotlinOptions { - jvmTarget = "11" - } + kotlinOptions.jvmTarget = "11" } compileJava { options.encoding = "UTF-8" } + java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + withSourcesJar() + withJavadocJar() + } + jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE }