mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Better gradlew workflow (#67)
Upload build artifacts with commit small hash inside the name
This commit is contained in:
commit
5a2c493b59
2 changed files with 71 additions and 74 deletions
78
.github/workflows/gradle.yml
vendored
78
.github/workflows/gradle.yml
vendored
|
|
@ -9,16 +9,19 @@ name: Java CI with Gradle
|
|||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
branches: [ "master", "v2.0.0" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
branches: [ "master", "v2.0.0" ]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
|
@ -40,43 +43,42 @@ jobs:
|
|||
|
||||
- name: Make gradlew executable
|
||||
run: chmod +x ./gradlew
|
||||
|
||||
- name: Get small commit hash
|
||||
run: echo "SMALL_COMMIT_HASH=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
|
||||
|
||||
- name: Build with Gradle Wrapper
|
||||
run: ./gradlew build --parallel
|
||||
|
||||
# only submit dependency on push
|
||||
- name: Generate and submit dependency graph
|
||||
uses: gradle/actions/dependency-submission@v4
|
||||
if: ${{ github.event_name == 'push' && success() }}
|
||||
continue-on-error: true
|
||||
|
||||
# Get the names of the online and offline jars
|
||||
# grep -v "offline" to exclude offline jar as the regex would catch it otherwise
|
||||
- name: Get file name for jars
|
||||
run: |
|
||||
ONLINE_JAR_PATH=$(ls build/libs/CustomAnvil-*.jar | grep -v "offline")
|
||||
OFFLINE_JAR_PATH=$(ls build/libs/CustomAnvil-*-offline.jar)
|
||||
|
||||
echo "ONLINE_JAR_NAME=$(basename $ONLINE_JAR_PATH)" >> $GITHUB_ENV
|
||||
echo "OFFLINE_JAR_NAME=$(basename $OFFLINE_JAR_PATH)" >> $GITHUB_ENV
|
||||
|
||||
# upload the named jars
|
||||
- name: Upload online JAR artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.ONLINE_JAR_NAME }}
|
||||
path: build/libs/${{ env.ONLINE_JAR_NAME }}
|
||||
|
||||
- name: Upload offline JAR file
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.OFFLINE_JAR_NAME }}
|
||||
path: build/libs/${{ env.OFFLINE_JAR_NAME }}
|
||||
|
||||
- name: Summarize tests results
|
||||
uses: jeantessier/test-summary-action@v1
|
||||
if: ${{ always() }}
|
||||
|
||||
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
|
||||
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
|
||||
#
|
||||
# - name: Setup Gradle
|
||||
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
||||
# with:
|
||||
# gradle-version: '8.9'
|
||||
#
|
||||
# - name: Build with Gradle 8.9
|
||||
# run: gradle build
|
||||
|
||||
dependency-submission:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDKs
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: |
|
||||
16
|
||||
17
|
||||
20
|
||||
21
|
||||
|
||||
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
|
||||
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
|
||||
- name: Generate and submit dependency graph
|
||||
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ plugins {
|
|||
group = "xyz.alexcrea"
|
||||
version = "1.11.3"
|
||||
|
||||
val effectiveVersion = "$version" +
|
||||
(if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "")
|
||||
|
||||
repositories {
|
||||
// EcoEnchants
|
||||
maven(url = "https://repo.auxilor.io/repository/maven-public/")
|
||||
|
|
@ -115,7 +118,8 @@ allprojects {
|
|||
|
||||
// Set target version
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
sourceCompatibility = "16" // We aim for java 16 for minecraft 1.16.5. even if it not really suported by custom anvil.
|
||||
sourceCompatibility =
|
||||
"16" // We aim for java 16 for minecraft 1.16.5. even if it not really suported by custom anvil.
|
||||
targetCompatibility = "16"
|
||||
|
||||
options.encoding = "UTF-8"
|
||||
|
|
@ -130,23 +134,13 @@ allprojects {
|
|||
|
||||
}
|
||||
|
||||
// Fat-jar builder
|
||||
val fatJar = tasks.register<Jar>("fatJar") {
|
||||
manifest {
|
||||
attributes.apply { put("Main-Class", "io.delilaheve.CustomAnvil") }
|
||||
}
|
||||
archiveFileName.set("${rootProject.name}-${project.version}.jar")
|
||||
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
|
||||
duplicatesStrategy = DuplicatesStrategy.WARN
|
||||
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
|
||||
with(tasks.jar.get() as CopySpec)
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
// Online jar (use of libraries)
|
||||
shadowJar {
|
||||
// No suffix for this jar
|
||||
archiveClassifier.set("")
|
||||
val name = "${rootProject.name}-${effectiveVersion}.jar"
|
||||
archiveFileName.set(name)
|
||||
|
||||
// Exclude kotlin std and its annotation
|
||||
exclude("**/kotlin-stdlib*.jar")
|
||||
|
|
@ -158,7 +152,7 @@ tasks {
|
|||
// Replace version and example fields in plugin.yml
|
||||
filesMatching("plugin.yml") {
|
||||
expand(
|
||||
"version" to project.version,
|
||||
"version" to effectiveVersion,
|
||||
"libraries" to " \"org.jetbrains.kotlin:kotlin-stdlib:2.1.0\" "
|
||||
)
|
||||
}
|
||||
|
|
@ -176,14 +170,15 @@ tasks {
|
|||
|
||||
// Add custom anvil compiled
|
||||
::class, fun ShadowJar.() {
|
||||
archiveClassifier.set("offline")
|
||||
val name = "${rootProject.name}-${effectiveVersion}-offline.jar"
|
||||
archiveFileName.set(name)
|
||||
|
||||
// Shadow necessary dependency
|
||||
relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.inventoryframework")
|
||||
|
||||
filesMatching("plugin.yml") {
|
||||
expand(
|
||||
"version" to "${project.version}-offline",
|
||||
"version" to "$effectiveVersion-offline",
|
||||
"libraries" to ""
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue