Skip to content

Commit

Permalink
update build.yml
Browse files Browse the repository at this point in the history
Took 13 minutes
  • Loading branch information
xkball committed Oct 15, 2024
1 parent 376db04 commit 532bcb5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
with:
java-version: '21'
distribution: 'temurin'

- name: Apply Cache
uses: actions/cache@v4
with:
Expand All @@ -25,10 +26,15 @@ jobs:
~/.gradle/wrapper
key: $${{ runner.os }}-gradle

- name: Build with Gradle
uses: gradle/actions/setup-gradle@v3
with:
arguments: build
- name: Get Short Identifier
uses: benjlevesque/[email protected]
id: short-sha

- name: Build
id: build
env:
VERSION_IDENTIFIER: SNAPSHOT+${{ steps.short-sha.outputs.sha }}
run: ./gradlew :build :githubActionOutput --stacktrace

- name: GitHub Action Artifact
uses: actions/upload-artifact@v4
Expand Down
37 changes: 33 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import java.nio.file.CopyOption
import java.nio.file.Files
import java.nio.file.StandardCopyOption

plugins {
id 'java-library'
id 'maven-publish'
id 'net.neoforged.moddev' version '2.0.16-beta'
}


//from https://github.com/teaconmc/PowerTool/blob/1.21-neoforge/build.gradle
abstract class TeaConDumpPathToGitHub extends DefaultTask {
@Input
abstract Property<String> getPublishName()
@InputFile
abstract RegularFileProperty getTargetFile()
@TaskAction
void dump() {
if (System.env.GITHUB_ACTIONS) {
File theFile = targetFile.getAsFile().get()

def outputFile = new File(System.env.GITHUB_OUTPUT)
// Use the env-specific line separator for maximally possible compatibility
def newLine = System.getProperty('line.separator')

// Write out new env variable for later usage
outputFile << newLine << "artifact_name=${theFile.getName()}"
outputFile << newLine << "artifact_publish_name=${publishName.get()}"
outputFile << newLine << "artifact_path=${theFile.absolutePath}"
}
}
}

tasks.register("githubActionOutput", TeaConDumpPathToGitHub) { task ->
task.onlyIf {
System.env.GITHUB_ACTIONS
}
task.getPublishName().set("${jar.archiveBaseName.get()}-${version}.jar")
task.getTargetFile().set(jar.archiveFile)
}


tasks.named('wrapper', Wrapper).configure {
// Define wrapper values here so as to not have to always do so when updating gradlew.properties.
// Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with
Expand Down

0 comments on commit 532bcb5

Please sign in to comment.