Skip to content

Commit

Permalink
wip: publishing & deployment updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Fran committed Jan 16, 2024
1 parent 8817ac1 commit 0a63f94
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 27 deletions.
41 changes: 41 additions & 0 deletions .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
@@ -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:
Expand Down
129 changes: 118 additions & 11 deletions 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 {
Expand All @@ -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("/", "")
Expand Down Expand Up @@ -54,14 +65,110 @@ tasks {
archiveClassifier.set("")
}

withType<KotlinCompile> {
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<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc, tasks.dokkaHtml)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
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<MavenPublication>("shadow") {

project.extensions.configure<ShadowExtension> {
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")
}
}
}
}
}
}
24 changes: 10 additions & 14 deletions simplecoreapi/build.gradle.kts
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0a63f94

Please sign in to comment.