Skip to content

Commit

Permalink
automated build script
Browse files Browse the repository at this point in the history
  • Loading branch information
tristankechlo committed Jul 30, 2024
1 parent c71b1d1 commit 17d248b
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 50 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @tristankechlo
126 changes: 126 additions & 0 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Build and Publish Release

on:
release:
types: [ published ]

env:
MODID: "livingthings"
CURSEFORGE_ID: 397252
CURSEFORGE_LINK: "https://www.curseforge.com/minecraft/mc-mods/living-things"
MODRINTH_ID: "UKDLi1GJ"
MODRINTH_LINK: "https://modrinth.com/mod/living-things"
MODRINTH_FEATURED: true # if this version should be featured on modrinth
DISCORD_COLOR: 4037621
DISCORD_MENTION: "<@&890143122913370112>"
DISCORD_TITLE: "New version for LivingThings just released :exclamation:"
DISCORD_THUMBNAIL: "https://cdn.modrinth.com/data/UKDLi1GJ/d345468b19bfd5ffffa1ed070297a6a74535e9d6.png"

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
java-version: ${{ steps.properties.outputs.java_version }}
mc-version: ${{ steps.properties.outputs.minecraft_version }}
mod-version: ${{ steps.properties.outputs.mod_version }}
version-range: ${{ steps.properties.outputs.version_range }}
steps:
- name: Checkout Sourcecode
uses: actions/checkout@v4

- name: calculate versions
id: properties
uses: christian-draeger/read-properties@1.1.1
with:
path: 'gradle.properties'
properties: 'minecraft_version mod_version version_range java_version'

- name: Changelog
shell: bash
run: |
echo "# Changelog ${{ steps.properties.outputs.minecraft_version }} - ${{ steps.properties.outputs.mod_version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${{ github.event.release.body }}" >> $GITHUB_STEP_SUMMARY
build-and-release:
needs: prepare
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Sourcecode
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ needs.prepare.outputs.java-version }}
cache: "gradle"
cache-dependency-path: "gradle.properties"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: make gradle wrapper executable
run: chmod +x ./gradlew

- name: Execute Gradle build
run: ./gradlew build

- name: copy jar-files
shell: bash
run: |
mkdir ./dist
mv ./forge/build/libs/${{ env.MODID }}-*.jar ./dist
mv ./fabric/build/libs/${{ env.MODID }}-*.jar ./dist
echo -e "$(ls -lahG ./dist)"
- name: Add files to GitHub-Release
uses: shogo82148/actions-upload-release-asset@v1.7.5
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: "./dist/${{ env.MODID }}-*.jar"
overwrite: true

- name: publish mod files
uses: tristankechlo/publish-mc-mod@v1.0.0
if: ${{ contains(github.event.release.name, '[RELEASE]') }}
with:
mc-version: ${{ needs.prepare.outputs.mc-version }}
mod-version: ${{ needs.prepare.outputs.mod-version }}
curseforge-id: ${{ env.CURSEFORGE_ID }}
modrinth-id: ${{ env.MODRINTH_ID }}
changelog: ${{ github.event.release.body }}
featured: ${{ env.MODRINTH_FEATURED }}
forge: true
fabric: true
neoforge: false
version-range: ${{ needs.prepare.outputs.version-range }}
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}

send-discord-embed:
needs: [ "prepare", "build-and-release" ]
runs-on: ubuntu-latest
steps:
- name: Make embed
uses: tristankechlo/create-discord-embed@v1.0.0
with:
released: ${{ contains(github.event.release.name, '[RELEASE]') }}
changelog: "${{ github.event.release.body }}"
version: "${{ needs.prepare.outputs.mc-version }} - ${{ needs.prepare.outputs.mod-version }}"
color: ${{ env.DISCORD_COLOR }}
content: "${{ contains(github.event.release.name, '[RELEASE]') && env.DISCORD_MENTION || 'This update will not be published!'}}"
title: ${{ env.DISCORD_TITLE }}
description: "${{ contains(github.event.release.name, '[RELEASE]') && 'The update is available for *Forge* and *Fabric*' || 'The update will *not* be released to Curseforge or Modrinth'}}"
curseforge: ${{ env.CURSEFORGE_LINK }}
modrinth: ${{ env.MODRINTH_LINK }}
github: ${{ github.event.release.html_url }}
thumbnail: ${{ env.DISCORD_THUMBNAIL }}

- name: Send Discord Message
uses: tsickert/discord-webhook@v6.0.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
raw-data: ./embed.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ build
# other
eclipse
run
runs
CREDITS.txt
LICENSE.txt
README.txt
Expand Down
File renamed without changes.
31 changes: 30 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

subprojects {
apply plugin: 'java'
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(java_version)

jar {
from rootProject.file('CREDITS.md')
from rootProject.file('LICENSE')
manifest {
attributes([
'Specification-Title' : mod_name,
Expand Down Expand Up @@ -40,4 +44,29 @@ subprojects {
tasks.withType(GenerateModuleMetadata) {
enabled = false
}

processResources {
def expandProps = [
"version" : "${minecraft_version}-${mod_version}",
"version_range" : version_range,
"minecraft_version" : minecraft_version,
"java_version" : java_version,
"fabric_loader_min" : fabric_loader_min,
"fabric_range_min_inclusive": fabric_range_min_inclusive,
"fabric_range_max_exclusive": fabric_range_max_exclusive,
"forge_loader_range" : forge_loader_range
]

filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml']) {
expand expandProps
}
inputs.properties(expandProps)

// minify json files
doLast {
fileTree(dir: outputs.files.asPath, include: "**/*.json").each {
File file -> file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
}
}
}
}
19 changes: 0 additions & 19 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'idea'
Expand Down Expand Up @@ -50,22 +47,6 @@ loom {

processResources {
from project(":common").sourceSets.main.resources
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
}

//filesMatching('*.mixins.json') {
// expand "refmap_target": "${archivesBaseName}-"
//}

// minify json files
doLast {
fileTree(dir: outputs.files.asPath, include: "**/*.json").each {
File file -> file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
}
}
}

tasks.withType(JavaCompile) {
Expand Down
6 changes: 3 additions & 3 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"livingthings.mixins.json"
],
"depends": {
"fabricloader": ">=0.14",
"fabricloader": ">=${fabric_loader_min}",
"fabric": "*",
"minecraft": ">=1.19.2",
"java": ">=17"
"minecraft": ">=${fabric_range_min_inclusive} <${fabric_range_max_exclusive}",
"java": ">=${java_version}"
},
"custom": {
"modmenu": {
Expand Down
22 changes: 1 addition & 21 deletions forge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net' }
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '[6.0,6.2)', changing: true
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
Expand All @@ -19,7 +16,6 @@ apply plugin: 'org.spongepowered.mixin'
version = "${minecraft_version}-${mod_version}"
archivesBaseName = "${mod_id}-forge"


mixin {
add sourceSets.main, "${mod_id}.refmap.json"
config "${mod_id}.mixins.json"
Expand Down Expand Up @@ -80,22 +76,6 @@ tasks.withType(JavaCompile) {

processResources {
from project(":common").sourceSets.main.resources
inputs.property "version", project.version

filesMatching("META-INF/mods.toml") {
expand "version": project.version
}

//filesMatching('*.mixins.json') {
// expand "refmap_target": "${mod_id}."
//}

// minify json files
doLast {
fileTree(dir: outputs.files.asPath, include: "**/*.json").each {
File file -> file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
}
}
}

jar.finalizedBy('reobfJar')
6 changes: 3 additions & 3 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modLoader="javafml"
loaderVersion="[43,)"
loaderVersion="${forge_loader_range}"
license="CC BY-NC-ND 4.0"
showAsResourcePack=false
issueTrackerURL="https://github.com/tristankechlo/LivingThings/issues"
Expand All @@ -16,13 +16,13 @@ description='''adds various new mobs to Minecraft'''
[[dependencies.livingthings]]
modId="forge"
mandatory=true
versionRange="[43.2.0,)"
versionRange="${forge_loader_range}"
ordering="NONE"
side="BOTH"

[[dependencies.livingthings]]
modId="minecraft"
mandatory=true
versionRange="[1.19.2,1.20)"
versionRange="${version_range}"
ordering="NONE"
side="BOTH"
10 changes: 8 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
group=com.tristankechlo.livingthings

# Common
java_version=17
minecraft_version=1.19.2
version_range=[1.19.2,1.19.3)
common_runs_enabled=false

# Forge
forge_version=43.2.0
forge_version=43.4.0
forge_loader_range=[43,)

# Fabric
fabric_version=0.76.0+1.19.2
fabric_version=0.77.0+1.19.2
fabric_loader_version=0.14.18
fabric_loader_min=0.14
fabric_range_min_inclusive=1.19.2
fabric_range_max_exclusive=1.19.3

# Mod options
mod_name=LivingThings
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 17d248b

Please sign in to comment.