Skip to content

Commit

Permalink
chore(deps): Cleanup of build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Oct 19, 2024
1 parent 5a6cb12 commit 5619ef6
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 149 deletions.
35 changes: 12 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
tags-ignore: [ "**" ]
pull_request:
release:
types: [ released ]
types: [ released, prereleased ]

concurrency:
group: "${{ github.workflow }}-${{ github.event.number || github.ref }}"
Expand All @@ -23,35 +23,24 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'

- name: Build Artifact
run: ./gradlew build
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Upload Test Summary
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: "test results"
junit_files: "**/build/test-results/test/TEST-*.xml"

- name: Set up Artifact Upload
id: upload
run: echo "ARTIFACT_PATH=$(./gradlew getArtifactPath -q)" >> $GITHUB_ENV
- name: Build Artifact
run: ./gradlew release

- name: Upload Artifact to Actions
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: ${{ env.ARTIFACT_PATH }}
name: "${{ github.event.repository.name }}-artifacts"
path: build/tmp/release/*.jar
if-no-files-found: error

- name: Determine Status
run: |
Expand All @@ -62,21 +51,21 @@ jobs:
fi
- name: Publish to Xpdustry
if: ${{ env.STATUS == 'release' || startsWith(github.ref, 'refs/heads/master') }}
if: ${{ env.STATUS == 'release' || startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/dev') }}
run: ./gradlew publish
env:
ORG_GRADLE_PROJECT_xpdustryUsername: "${{ secrets.XPDUSTRY_MAVEN_USERNAME }}"
ORG_GRADLE_PROJECT_xpdustryPassword: "${{ secrets.XPDUSTRY_MAVEN_PASSWORD }}"
ORG_GRADLE_PROJECT_signingKey: "${{ secrets.XPDUSTRY_MAVEN_SIGNING_KEY }}"
ORG_GRADLE_PROJECT_signingPassword: "${{ secrets.XPDUSTRY_MAVEN_SIGNING_PASSWORD }}"

- name: Upload Artifact to Release
- name: Upload Artifacts to Release
if: ${{ env.STATUS == 'release' && github.event_name == 'release' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
asset_name: ${{ github.event.repository.name }}.jar
file: ${{ env.ARTIFACT_PATH }}
file: build/tmp/release/*.jar
file_glob: true
tag: ${{ github.ref }}

- name: Update Changelog
Expand Down
3 changes: 0 additions & 3 deletions .spotless/project.importorder

This file was deleted.

194 changes: 73 additions & 121 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,89 +1,63 @@
import com.xpdustry.ksr.kotlinRelocate
import com.xpdustry.toxopid.extension.anukeXpdustry
import com.xpdustry.toxopid.spec.ModMetadata
import com.xpdustry.toxopid.spec.ModPlatform
import com.xpdustry.toxopid.task.GithubAssetDownload
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode

plugins {
kotlin("jvm") version "1.9.23"
id("com.diffplug.spotless") version "6.25.0"
id("net.kyori.indra") version "3.1.3"
id("net.kyori.indra.publishing") version "3.1.3"
id("net.kyori.indra.git") version "3.1.3"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.xpdustry.toxopid") version "4.0.0-SNAPSHOT"
id("com.xpdustry.ksr") version "2.0.0-SNAPSHOT"
id("org.jetbrains.dokka") version "1.9.20"
}

val metadata = ModMetadata.fromJson(file("plugin.json"))

// Remove the following line if you don't want snapshot versions
if (indraGit.headTag() == null) {
metadata.version += "-SNAPSHOT"
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.spotless)
alias(libs.plugins.indra.common)
alias(libs.plugins.indra.git)
alias(libs.plugins.indra.publishing)
alias(libs.plugins.shadow)
alias(libs.plugins.toxopid)
alias(libs.plugins.ksr)
alias(libs.plugins.dokka)
}

val metadata = ModMetadata.fromJson(rootProject.file("plugin.json"))
if (indraGit.headTag() == null) metadata.version += "-SNAPSHOT"
group = "com.xpdustry"
val rootPackage = "com.xpdustry.nohorny"
version = metadata.version
description = metadata.description

toxopid {
compileVersion.set("v${metadata.minGameVersion}")
platforms.add(ModPlatform.SERVER)
compileVersion = "v${metadata.minGameVersion}"
platforms = setOf(ModPlatform.SERVER)
}

repositories {
mavenCentral()

// This repository provides mindustry artifacts built by xpdustry
maven("https://maven.xpdustry.com/mindustry") {
name = "xpdustry-mindustry"
mavenContent { releasesOnly() }
}

// This repository provides xpdustry libraries, such as the distributor-api
anukeXpdustry()
maven("https://maven.xpdustry.com/releases") {
name = "xpdustry-releases"
mavenContent { releasesOnly() }
}
}

dependencies {
compileOnly(toxopid.dependencies.mindustryCore)
compileOnly(toxopid.dependencies.arcCore)
compileOnly(toxopid.dependencies.mindustryHeadless)
compileOnly(toxopid.dependencies.arcHeadless)

compileOnly(kotlin("stdlib-jdk8"))

compileOnly("org.slf4j:slf4j-api:2.0.12")
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.sksamuel.hoplite:hoplite-core:2.7.5")
implementation("com.sksamuel.hoplite:hoplite-yaml:2.7.5")

val junit = "5.10.2"
testImplementation("org.junit.jupiter:junit-jupiter-params:$junit")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit")
}

configurations.runtimeClasspath {
exclude("org.jetbrains.kotlin")
exclude("org.jetbrains.kotlinx")
compileOnly(libs.kotlinx.coroutines.core)
compileOnly(libs.kotlinx.coroutines.jdk8)
compileOnly(libs.kotlinx.serialization.json)
compileOnly(toxopid.dependencies.arcCore)
compileOnly(toxopid.dependencies.mindustryCore)
compileOnly(libs.slf4j.api)
testImplementation(libs.slf4j.simple)
compileOnly(libs.okhttp)
implementation(libs.hoplite.core)
implementation(libs.hoplite.yaml)
testImplementation(libs.junit.api)
testRuntimeOnly(libs.junit.engine)
}

kotlin {
jvmToolchain(17)
explicitApi = ExplicitApiMode.Strict
target {
compilations.configureEach {
kotlinOptions {
jvmTarget = "17"
apiVersion = "1.9"
}
}
}
signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
}

indra {
Expand All @@ -109,95 +83,73 @@ indra {
configurePublications {
pom {
organization {
name.set("xpdustry")
url.set("https://www.xpdustry.com")
name = "xpdustry"
url = "https://www.xpdustry.com"
}
}
}
}

signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
}

spotless {
kotlin {
ktfmt().dropboxStyle()
licenseHeader(
buildString {
appendLine("/*")
rootProject.file("HEADER.md").readText().lines().forEach { appendLine(" * ${it.trim()}") }
appendLine(" */")
},
)
indentWithSpaces(4)
trimTrailingWhitespace()
endWithNewline()
ktlint()
licenseHeaderFile(rootProject.file("HEADER.md"))
}
kotlinGradle {
ktlint()
}
}

// Required for the GitHub actions
tasks.register("getArtifactPath") {
doLast { println(tasks.shadowJar.get().archiveFile.get().toString()) }
kotlin {
explicitApi()
}

tasks.shadowJar {
archiveFileName.set("${metadata.name}.jar")
archiveClassifier.set("plugin")
configurations.runtimeClasspath {
exclude("org.jetbrains.kotlin")
exclude("org.jetbrains.kotlinx")
}

val relocationPackage = "com.xpdustry.nohorny.shadow"
kotlinRelocate("okhttp3", "$relocationPackage.okhttp3")
kotlinRelocate("okio", "$relocationPackage.okio")
kotlinRelocate("com.sksamuel.hoplite", "$relocationPackage.hoplite")
relocate("org.yaml.snakeyaml", "$relocationPackage.snakeyaml")
val generateMetadataFile by tasks.registering {
inputs.property("metadata", metadata)
val output = temporaryDir.resolve("plugin.json")
outputs.file(output)
doLast { output.writeText(ModMetadata.toJson(metadata)) }
}

tasks.shadowJar {
archiveFileName = "${metadata.name}.jar"
archiveClassifier = "plugin"
from(generateMetadataFile)
from(rootProject.file("LICENSE.md")) { into("META-INF") }
val shadowPackage = "$rootPackage.shadow"
kotlinRelocate("com.sksamuel.hoplite", "$shadowPackage.hoplite")
relocate("org.yaml.snakeyaml", "$shadowPackage.snakeyaml")
mergeServiceFiles()
minimize {
exclude(dependency("com.sksamuel.hoplite:hoplite-.*:.*"))
}

exclude("META-INF/proguard/**")

doFirst {
val temp = temporaryDir.resolve("plugin.json")
temp.writeText(ModMetadata.toJson(metadata))
from(temp)
}

from(rootProject.file("LICENSE.md")) {
into("META-INF")
}
}

tasks.build {
dependsOn(tasks.shadowJar)
tasks.register<Copy>("release") {
dependsOn(tasks.build)
from(tasks.shadowJar)
destinationDir = temporaryDir
}

tasks.javadocJar {
from(tasks.dokkaHtml)
val downloadSlf4md by tasks.registering(GithubAssetDownload::class) {
owner = "xpdustry"
repo = "slf4md"
asset = "slf4md-simple.jar"
version = "v${libs.versions.slf4md.get()}"
}

val downloadDistributorCore =
tasks.register<GithubAssetDownload>("downloadDistributorCore") {
owner.set("xpdustry")
repo.set("distributor")
asset.set("distributor-core.jar")
version.set("v3.3.0")
}

val downloadKotlinRuntime =
tasks.register<GithubAssetDownload>("downloadKotlinRuntime") {
owner.set("xpdustry")
repo.set("kotlin-runtime")
asset.set("kotlin-runtime.jar")
version.set("v3.2.0-k.1.9.23")
}
val downloadKotlinRuntime by tasks.registering(GithubAssetDownload::class) {
owner = "xpdustry"
repo = "kotlin-runtime"
asset = "kotlin-runtime.jar"
version = "v${libs.versions.kotlin.runtime.get()}-k.${libs.versions.kotlin.core.get()}"
}

tasks.runMindustryServer {
mods.from(downloadKotlinRuntime)
mods.from(downloadSlf4md, downloadKotlinRuntime)
}
52 changes: 52 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[versions]
# platforms
kotlin-core = "2.0.20"
kotlinx-coroutines = "1.9.0"
kotlinx-serialization = "1.7.3"
kotlin-runtime = "4.0.0"

# plugins
shadow = "8.3.2"
indra = "3.1.3"
toxopid = "4.1.0"
spotless = "6.25.0"
ksr = "1.0.0"
dokka = "1.9.20"

# utilities
slf4md = "1.0.1"
slf4j = "2.0.16"
hoplite = "2.8.2"
okhttp = "4.12.0"

# testing
junit = "5.11.2"

[libraries]
# runtime
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-jdk8 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8", version.ref = "kotlinx-coroutines" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }

# utilities
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }
hoplite-core = { module = "com.sksamuel.hoplite:hoplite-core", version.ref = "hoplite" }
hoplite-yaml = { module = "com.sksamuel.hoplite:hoplite-yaml", version.ref = "hoplite" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }

# testing
junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }

[plugins]
indra-common = { id = "net.kyori.indra", version.ref = "indra" }
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
indra-publishing = { id = "net.kyori.indra.publishing", version.ref = "indra" }
indra-git = { id = "net.kyori.indra.git", version.ref = "indra" }
toxopid = { id = "com.xpdustry.toxopid", version.ref = "toxopid" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-core" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-core" }
ksr = { id = "com.xpdustry.ksr", version.ref = "ksr" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
Loading

0 comments on commit 5619ef6

Please sign in to comment.