Add GH actions Maven publishing, improve buildscript

This commit is contained in:
comp500 2022-07-16 17:10:26 +01:00
parent 66bc4c3e29
commit fcf249166c
3 changed files with 117 additions and 27 deletions

33
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: Java Gradle Release
on:
push:
tags:
- 'v\d+.\d+.\d+'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'temurin'
cache: gradle
- name: Publish with Gradle
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ Secrets.GITHUB_TOKEN }}
BUNNYCDN_TOKEN: ${{ Secrets.BUNNYCDN_TOKEN }}
RELEASE: true
- name: Cleanup Gradle Cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties

29
.github/workflows/snapshot.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Java Gradle Snapshot
on: ["push", "pull_request"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'temurin'
cache: gradle
- name: Publish with Gradle
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ Secrets.GITHUB_TOKEN }}
BUNNYCDN_TOKEN: ${{ Secrets.BUNNYCDN_TOKEN }}
- name: Cleanup Gradle Cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties

View File

@ -22,6 +22,15 @@ repositories {
}
val r8 by configurations.creating
val shrinkJarOutput by configurations.creating {
isCanBeResolved = false
isCanBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, Usage.JAVA_RUNTIME))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling::class.java, Bundling.EMBEDDED))
}
}
dependencies {
implementation("commons-cli:commons-cli:1.5.0")
@ -35,7 +44,7 @@ dependencies {
}
application {
mainClassName = "link.infra.packwiz.installer.RequiresBootstrap"
mainClass.set("link.infra.packwiz.installer.RequiresBootstrap")
}
val gitVersion: groovy.lang.Closure<*> by extra
@ -70,9 +79,11 @@ tasks.shadowJar {
exclude("META-INF/NOTICE.txt")
}
tasks.register<JavaExec>("shrinkJar") {
val shrinkJar by tasks.registering(JavaExec::class) {
val rules = file("src/main/proguard.txt")
val r8File = tasks.shadowJar.get().archiveFile.get().asFile.run { resolveSibling(name.removeSuffix(".jar") + "-shrink.jar") }
val r8File = base.libsDirectory.file(provider {
base.archivesName.get() + "-" + project.version + "-all-shrink.jar"
})
dependsOn(configurations.named("runtimeClasspath"))
inputs.files(tasks.shadowJar, rules)
outputs.file(r8File)
@ -82,7 +93,7 @@ tasks.register<JavaExec>("shrinkJar") {
args = mutableListOf(
"--release",
"--classfile",
"--output", r8File.toString(),
"--output", r8File.get().toString(),
"--pg-conf", rules.toString(),
"--lib", System.getProperty("java.home"),
*(if (System.getProperty("java.version").startsWith("1.")) {
@ -93,48 +104,61 @@ tasks.register<JavaExec>("shrinkJar") {
)
}
artifacts {
add("shrinkJarOutput", shrinkJar) {
classifier = "dist"
}
}
// Used for vscode launch.json
tasks.register<Copy>("copyJar") {
from(tasks.named("shrinkJar"))
val copyJar by tasks.registering(Copy::class) {
from(shrinkJar)
rename("packwiz-installer-(.*)\\.jar", "packwiz-installer.jar")
into("build/libs/")
outputs.file("build/libs/packwiz-installer.jar")
into(layout.buildDirectory.dir("dist"))
outputs.file(layout.buildDirectory.dir("dist").map { file("packwiz-installer.jar") })
}
tasks.assemble {
dependsOn("shrinkJar")
dependsOn("copyJar")
tasks.build {
dependsOn(copyJar)
}
if (project.hasProperty("github.token")) {
githubRelease {
owner("comp500")
repo("packwiz-installer")
tagName("${project.version}")
releaseName("Release ${project.version}")
draft(true)
token(findProperty("github.token") as String? ?: "")
releaseAssets(tasks.jar.get().destinationDirectory.file("packwiz-installer.jar").get())
token(findProperty("github.token") as String?)
releaseAssets(copyJar)
}
tasks.githubRelease {
dependsOn(tasks.build)
}
dependsOn(copyJar)
enabled = project.hasProperty("github.token") && project.findProperty("release") == "true"
}
tasks.compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xjvm-default=all", "-Xallow-result-return-type", "-Xopt-in=kotlin.io.path.ExperimentalPathApi", "-Xlambdas=indy")
freeCompilerArgs = listOf("-Xjvm-default=all", "-Xallow-result-return-type", "-opt-in=kotlin.io.path.ExperimentalPathApi", "-Xlambdas=indy")
}
}
tasks.compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xjvm-default=all", "-Xallow-result-return-type", "-Xopt-in=kotlin.io.path.ExperimentalPathApi", "-Xlambdas=indy")
freeCompilerArgs = listOf("-Xjvm-default=all", "-Xallow-result-return-type", "-opt-in=kotlin.io.path.ExperimentalPathApi", "-Xlambdas=indy")
}
}
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.addVariantsFromConfiguration(shrinkJarOutput) {
mapToMavenScope("runtime")
mapToOptional()
}
javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
skip()
}
if (project.hasProperty("bunnycdn.token")) {
publishing {
publications {
@ -147,7 +171,11 @@ if (project.hasProperty("bunnycdn.token")) {
}
repositories {
maven {
url = uri("https://storage.bunnycdn.com/comp-maven")
url = if (project.findProperty("release") == "true") {
uri("https://storage.bunnycdn.com/comp-maven/repository/release")
} else {
uri("https://storage.bunnycdn.com/comp-maven/repository/snapshot")
}
credentials(HttpHeaderCredentials::class) {
name = "AccessKey"
value = findProperty("bunnycdn.token") as String?