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
116
.github/workflows/gradle.yml
vendored
116
.github/workflows/gradle.yml
vendored
|
|
@ -9,74 +9,76 @@ name: Java CI with Gradle
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "master" ]
|
branches: [ "master", "v2.0.0" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "master" ]
|
branches: [ "master", "v2.0.0" ]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Set up JDKs
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
java-version: |
|
|
||||||
16
|
|
||||||
17
|
|
||||||
20
|
|
||||||
21
|
|
||||||
distribution: 'temurin'
|
|
||||||
cache: 'gradle'
|
|
||||||
|
|
||||||
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
|
|
||||||
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
|
|
||||||
- name: Setup Gradle
|
|
||||||
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
|
||||||
|
|
||||||
- name: Make gradlew executable
|
|
||||||
run: chmod +x ./gradlew
|
|
||||||
- name: Build with Gradle Wrapper
|
|
||||||
run: ./gradlew build --parallel
|
|
||||||
|
|
||||||
- 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
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up JDKs
|
- name: Set up JDKs
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
java-version: |
|
||||||
java-version: |
|
|
||||||
16
|
16
|
||||||
17
|
17
|
||||||
20
|
20
|
||||||
21
|
21
|
||||||
|
distribution: 'temurin'
|
||||||
|
cache: 'gradle'
|
||||||
|
|
||||||
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
|
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
|
||||||
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
|
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
|
||||||
- name: Generate and submit dependency graph
|
- name: Setup Gradle
|
||||||
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
|
||||||
|
|
||||||
|
- 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() }}
|
||||||
|
|
@ -18,6 +18,9 @@ plugins {
|
||||||
group = "xyz.alexcrea"
|
group = "xyz.alexcrea"
|
||||||
version = "1.11.3"
|
version = "1.11.3"
|
||||||
|
|
||||||
|
val effectiveVersion = "$version" +
|
||||||
|
(if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "")
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
// EcoEnchants
|
// EcoEnchants
|
||||||
maven(url = "https://repo.auxilor.io/repository/maven-public/")
|
maven(url = "https://repo.auxilor.io/repository/maven-public/")
|
||||||
|
|
@ -115,7 +118,8 @@ allprojects {
|
||||||
|
|
||||||
// Set target version
|
// Set target version
|
||||||
tasks.withType<JavaCompile>().configureEach {
|
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"
|
targetCompatibility = "16"
|
||||||
|
|
||||||
options.encoding = "UTF-8"
|
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 {
|
tasks {
|
||||||
|
|
||||||
// Online jar (use of libraries)
|
// Online jar (use of libraries)
|
||||||
shadowJar {
|
shadowJar {
|
||||||
// No suffix for this jar
|
// No suffix for this jar
|
||||||
archiveClassifier.set("")
|
val name = "${rootProject.name}-${effectiveVersion}.jar"
|
||||||
|
archiveFileName.set(name)
|
||||||
|
|
||||||
// Exclude kotlin std and its annotation
|
// Exclude kotlin std and its annotation
|
||||||
exclude("**/kotlin-stdlib*.jar")
|
exclude("**/kotlin-stdlib*.jar")
|
||||||
|
|
@ -158,7 +152,7 @@ tasks {
|
||||||
// Replace version and example fields in plugin.yml
|
// Replace version and example fields in plugin.yml
|
||||||
filesMatching("plugin.yml") {
|
filesMatching("plugin.yml") {
|
||||||
expand(
|
expand(
|
||||||
"version" to project.version,
|
"version" to effectiveVersion,
|
||||||
"libraries" to " \"org.jetbrains.kotlin:kotlin-stdlib:2.1.0\" "
|
"libraries" to " \"org.jetbrains.kotlin:kotlin-stdlib:2.1.0\" "
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -176,14 +170,15 @@ tasks {
|
||||||
|
|
||||||
// Add custom anvil compiled
|
// Add custom anvil compiled
|
||||||
::class, fun ShadowJar.() {
|
::class, fun ShadowJar.() {
|
||||||
archiveClassifier.set("offline")
|
val name = "${rootProject.name}-${effectiveVersion}-offline.jar"
|
||||||
|
archiveFileName.set(name)
|
||||||
|
|
||||||
// Shadow necessary dependency
|
// Shadow necessary dependency
|
||||||
relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.inventoryframework")
|
relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.inventoryframework")
|
||||||
|
|
||||||
filesMatching("plugin.yml") {
|
filesMatching("plugin.yml") {
|
||||||
expand(
|
expand(
|
||||||
"version" to "${project.version}-offline",
|
"version" to "$effectiveVersion-offline",
|
||||||
"libraries" to ""
|
"libraries" to ""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue