Update gradle.yml #59
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Mod Compile Checks | |
on: | |
push: | |
branches: [ "1.20.1" ] | |
pull_request: | |
branches: [ "1.20.1" ] | |
jobs: | |
release-jar-snapshot: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get Changed Files | |
id: changed-files | |
uses: tj-actions/changed-files@v44 | |
with: | |
files_yaml: | | |
src: | |
- src/** | |
- name: Set up JDK 17 | |
if: steps.changed-files.outputs.src_any_changed == 'true' | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Setup Gradle | |
if: steps.changed-files.outputs.src_any_changed == 'true' | |
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 | |
- name: Read Properties | |
if: steps.changed-files.outputs.src_any_changed == 'true' | |
id: readproperties | |
uses: BrycensRanch/read-properties-action@v1 | |
with: | |
file: gradle.properties | |
all: true | |
- name: Truncate Git SHA | |
if: steps.changed-files.outputs.src_any_changed == 'true' | |
id: truncated | |
uses: actions/github-script@v7.0.1 | |
with: | |
script: | | |
const sha = context.sha.substring(0,7) | |
core.setOutput('sha', sha) | |
core.setOutput('versionStr', '${{steps.readproperties.outputs.mod_version}}.alpha.' + sha) | |
core.setOutput('shouldBuild', (context.eventName === "push" && "${{steps.changed-files.outputs.src_any_changed}}" == "true").toString()) | |
- name: Run Data Generation (Server, Client) | |
if: steps.changed-files.outputs.src_any_changed == 'true' | |
id: datagen | |
env: | |
MOD_VERSION: ${{ steps.truncated.outputs.versionStr }} | |
JAVA_OPTS: -Dlog4j.configuration=log4j.properties | |
run: ./gradlew runData | |
- name: Build JAR file | |
if: steps.truncated.outputs.shouldBuild == 'true' | |
env: | |
MOD_VERSION: ${{ steps.truncated.outputs.versionStr }} | |
JAVA_OPTS: -Dlog4j.configuration=log4j.properties | |
run: ./gradlew build | |
- name: Generate Checksum | |
if: steps.truncated.outputs.shouldBuild == 'true' | |
uses: jmgilman/actions-generate-checksum@v1 | |
with: | |
patterns: | | |
build/libs/* | |
- name: Fetch Last Release Checksum | |
if: steps.truncated.outputs.shouldBuild == 'true' | |
uses: robinraju/release-downloader@v1.10 | |
with: | |
latest: true | |
#fileName: checksum.txt | |
out-file-path: "lastRelease" | |
- name: Check Checksums | |
if: steps.truncated.outputs.shouldBuild == 'true' | |
id: checked | |
uses: actions/github-script@v7.0.1 | |
with: | |
script: | | |
const fs = require('fs') | |
if(fs.existsSync("lastRelease/checksum.txt")) { | |
core.setOutput('same', 'false') | |
return | |
} | |
const entriesA = fs.readFileSync("checksum.txt", "utf-8").split("\n") | |
const entriesB = fs.readFileSync("lastRelease/checksum.txt", "utf-8").split("\n") | |
if(entriesA.length != entriesB.length) { | |
core.setOutput('same', 'false') | |
return | |
} | |
const mapA = entriesA.reduce((map, sumPath)=>{ | |
const path = sumPath.split(" ") | |
map[path[1]] = path[0] | |
return map | |
}, {}) | |
var idx = 0 | |
entriesB.reduce((map, sumPath)=>{ | |
const path = sumPath.split(" ") | |
map[path[1]] = path[0] | |
return map | |
}, {}).forEach((value, key) => { | |
idx++ | |
if(mapA.get(key) != value) { | |
core.setOutput('same', 'false') | |
return | |
} | |
}) | |
if(idx != mapA.length) { | |
core.setOutput('same', 'false') | |
return | |
} | |
core.setOutput('same', 'true') | |
- name: Create Release | |
if: steps.checked.outputs.same == 'false' | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: | | |
checksum.txt | |
build/libs/* | |
tag_name: snapshot-${{ steps.truncated.outputs.sha }} | |
name: ${{steps.readproperties.outputs.mod_name}} ${{ steps.truncated.outputs.versionStr }} | |
draft: false |