Skip to content

Commit

Permalink
Simple refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrix-Shen committed Feb 2, 2023
1 parent 867af56 commit 53b1774
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 133 deletions.
74 changes: 26 additions & 48 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout the sources
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: ${{ matrix.java }}

- name: Cache Gradle packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
Expand All @@ -41,43 +41,32 @@ jobs:
id: get_short_sha
run: |
short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)
echo "::set-output name=short_sha::$short_sha"
- name: Read Properties mod_name
id: mod_name
uses: christian-draeger/[email protected]
with:
path: gradle.properties
property: mod_name
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
- name: Read Properties mod_version
id: mod_version
uses: christian-draeger/read-properties@1.0.1
- name: Read Properties mod info
id: mod_info
uses: christian-draeger/read-properties@1.1.1
with:
path: gradle.properties
property: mod_version
properties: "mod_name mod_version"

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Preprocess resources
env:
COMMIT_SHA: ${{ steps.get_short_sha.outputs.short_sha }}
BUILD_TYPE: "BETA"
BUILD_NUMBER: ${{ github.run_number}}
run: ./gradlew preprocessResources

- name: Build with Gradle
env:
COMMIT_SHA: ${{ steps.get_short_sha.outputs.short_sha }}
BUILD_TYPE: "BETA"
BUILD_NUMBER: ${{ github.run_number}}
run: ./gradlew build

- name: Upload assets to GitHub Action
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ steps.mod_name.outputs.value }} ${{ steps.mod_version.outputs.value }}.${{ github.run_number}}+${{ steps.get_short_sha.outputs.short_sha }}
name: ${{ steps.mod_info.outputs.mod_name }} ${{ steps.mod_info.outputs.mod_version }}.${{ github.run_number }}+${{ steps.get_short_sha.outputs.short_sha }}
path: |
LICENSE
fabricWrapper/build/libs/*.jar
Expand All @@ -92,22 +81,22 @@ jobs:
LICENSE
fabricWrapper/build/libs/*.jar
fabricWrapper/build/tmp/submods/META-INF/jars/*.jar
name: "[CI#${{ github.run_number}}]${{ steps.mod_name.outputs.value }} ${{ steps.mod_version.outputs.value }}.${{ github.run_number}}+${{ steps.get_short_sha.outputs.short_sha }}"
name: "[CI#${{ github.run_number}}]${{ steps.mod_info.outputs.mod_name }} ${{ steps.mod_info.outputs.mod_version }}.${{ github.run_number }}+${{ steps.get_short_sha.outputs.short_sha }}"
tag_name: dev-${{ github.run_number }}
target_commitish: ${{ github.event.ref }}
generate_release_notes: true

- name: Publish release to Curseforge
if: contains(github.event.head_commit.message, '[publish skip]') == false && contains(github.event.ref, 'refs/heads/exp') == false
uses: Kir-Antipov/mc-publish@v2.1
uses: Kir-Antipov/mc-publish@v3.2
with:
curseforge-id: 478757
curseforge-token: ${{ secrets.CF_API_TOKEN }}
files-primary: fabricWrapper/build/libs/!(*-@(dev|sources)).jar
files-secondary: fabricWrapper/build/tmp/submods/META-INF/jars/!(*-@(dev|sources)).jar

name: ''
version: ${{ steps.mod_version.outputs.value }}.${{ github.run_number}}+${{ steps.get_short_sha.outputs.short_sha }}
version: ${{ steps.mod_info.outputs.mod_version }}.${{ github.run_number }}+${{ steps.get_short_sha.outputs.short_sha }}
version-type: alpha

changelog: |
Expand Down Expand Up @@ -149,16 +138,16 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout the sources
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: ${{ matrix.java }}

- name: Cache Gradle packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
Expand All @@ -173,41 +162,30 @@ jobs:
short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)
echo "::set-output name=short_sha::$short_sha"
- name: Read Properties mod_name
id: mod_name
uses: christian-draeger/[email protected]
with:
path: gradle.properties
property: mod_name

- name: Read Properties mod_version
id: mod_version
uses: christian-draeger/[email protected]
- name: Read Properties mod info
id: mod_info
uses: christian-draeger/[email protected]
with:
path: gradle.properties
property: mod_version
properties: "mod_name mod_version"

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Preprocess resources
env:
COMMIT_SHA: ${{ steps.get_short_sha.outputs.short_sha }}
BUILD_TYPE: "RELEASE"
BUILD_NUMBER: ${{ github.run_number}}
run: ./gradlew preprocessResources

- name: Build with Gradle
env:
COMMIT_SHA: ${{ steps.get_short_sha.outputs.short_sha }}
BUILD_TYPE: "RELEASE"
BUILD_NUMBER: ${{ github.run_number}}
run: ./gradlew build

- name: Upload assets to GitHub Action
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ steps.mod_name.outputs.value }} ${{ steps.mod_version.outputs.value }}.${{ github.run_number}}+${{ steps.get_short_sha.outputs.short_sha }}
name: ${{ steps.mod_info.outputs.mod_name }} ${{ steps.mod_info.outputs.mod_version }}.${{ github.run_number }}+${{ steps.get_short_sha.outputs.short_sha }}
path: |
LICENSE
fabricWrapper/build/libs/*.jar
Expand All @@ -223,7 +201,7 @@ jobs:
tag_name: ${{ github.event.ref }}

- name: Publish to curseforge
uses: Kir-Antipov/mc-publish@v2.1
uses: Kir-Antipov/mc-publish@v3.2
with:
curseforge-id: 478757
curseforge-token: ${{ secrets.CF_API_TOKEN }}
Expand All @@ -232,7 +210,7 @@ jobs:
files-secondary: fabricWrapper/build/tmp/submods/META-INF/jars/!(*-@(dev|sources)).jar

name: ''
version: ${{ steps.mod_version.outputs.value }}.${{ github.run_number}}+${{ steps.get_short_sha.outputs.short_sha }}
version: ${{ steps.mod_info.outputs.mod_version }}.${{ github.run_number }}+${{ steps.get_short_sha.outputs.short_sha }}
version-type: 'release'

changelog: ${{ github.event.release.body }}
Expand Down Expand Up @@ -272,10 +250,10 @@ jobs:

steps:
- name: Checkout the sources
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: ${{ matrix.java }}
Expand Down
51 changes: 35 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ plugins {
id("maven-publish")
id("fabric-loom").version("1.0-SNAPSHOT").apply(false)
// https://github.com/Juuxel/LoomQuiltflower
// id("io.github.juuxel.loom-quiltflower").version("1.8.0").apply(false)
id("io.github.juuxel.loom-quiltflower").version("1.8.0").apply(false)
// https://github.com/ReplayMod/preprocessor
// https://github.com/Fallen-Breath/preprocessor
id("com.replaymod.preprocess").version("b7207cffa9")
id("org.ajoberstar.grgit").version("5.0.0")
id("net.kyori.blossom").version("1.3.1").apply(false)
}

preprocess {
Expand All @@ -14,7 +16,7 @@ preprocess {
def mc116 = createNode("1.16.5", 1_16_05, "mojang")
def mc117 = createNode("1.17.1", 1_17_01, "mojang")
def mc118 = createNode("1.18.2", 1_18_02, "mojang")
def mc119 = createNode("1.19.3", 1_19_03, "mojang") // root
def mc119 = createNode("1.19.3", 1_19_03, "mojang")

mc114.link(mc115, null)
mc115.link(mc116, null)
Expand All @@ -23,20 +25,37 @@ preprocess {
mc118.link(mc119, file("versions/mapping-1.18.2-1.19.3.txt"))
}

def ENV = System.getenv()
String realVersion = "${project.mod_version}"
String getVersionGit(List paths) {
if (grgit == null) {
return "nogit"
}
List latestCommits = paths.isEmpty() ? grgit.log(maxCommits: 1) : grgit.log(paths: paths, maxCommits: 1)
return latestCommits.isEmpty() ? "uncommited" : "${latestCommits.get(0).id.substring(0, 7)}"
}

String getBuildNumber() {
Map<String, String> ENV = System.getenv()
return ENV.GITHUB_RUN_NUMBER ? ENV.GITHUB_RUN_NUMBER : Integer.MAX_VALUE
}

String getVersionType() {
Map<String, String> ENV = System.getenv()
switch (ENV.BUILD_TYPE) {
case "RELEASE":
return "stable"
case "BETA":
return "beta"
default:
return "dev"
}
}

realVersion += "." + (ENV.BUILD_NUMBER ? "${ENV.BUILD_NUMBER}" : Integer.MAX_VALUE)
realVersion += ENV.COMMIT_SHA ? "+${ENV.COMMIT_SHA}" : ""
switch (ENV.BUILD_TYPE) {
case "RELEASE":
realVersion += "-stable"
break
case "BETA":
realVersion += "-beta"
break
default:
realVersion += "-dev"
int getVersionPatch(List paths) {
if (grgit == null) {
return 0
}
List latestCommits = paths.isEmpty() ? grgit.log() : grgit.log(paths: paths)
return latestCommits.size()
}

version = realVersion
setVersion("${project.mod_version}.${project.getBuildNumber()}+${project.getVersionGit([])}-${project.getVersionType()}")
43 changes: 26 additions & 17 deletions common.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply(plugin: "maven-publish")
apply(plugin: "fabric-loom")
// apply(plugin: "io.github.juuxel.loom-quiltflower")
apply(plugin: "io.github.juuxel.loom-quiltflower")
apply(plugin: "net.kyori.blossom")
apply(plugin: "com.replaymod.preprocess")

int mcVersion = 1
Expand Down Expand Up @@ -28,21 +29,22 @@ repositories {
}

dependencies {
// Development environment
minecraft("com.mojang:minecraft:${project.minecraft_version}")
mappings(loom.officialMojangMappings())

// Annotation processor
modCompileOnly("org.projectlombok:lombok:${project.lombok_version}")
annotationProcessor("org.projectlombok:lombok:${project.lombok_version}")
testCompileOnly("org.projectlombok:lombok:${project.lombok_version}")
testAnnotationProcessor("org.projectlombok:lombok:${project.lombok_version}")

// Dependency
def ENV = System.getenv()
modImplementation("top.hendrixshen:magiclib-${project.minecraft_version.replace(".", "_")}:${project.magiclib_version}") {
if (ENV.BUILD_NUMBER) {
exclude(group: "net.fabricmc.fabric-api", module: "fabric-api")
}
}
modImplementation("curse.maven:litematica-308892:${project.litematica_version}")
modCompileOnly("curse.maven:litematica-308892:${project.litematica_version}")
modCompileOnly("curse.maven:not-enough-crashes-353890:${project.not_enough_crashes_version}")

if (mcVersion >= 11600) {
Expand All @@ -60,9 +62,11 @@ dependencies {

loom {
runConfigs.all {
// Dump modified classes automatically.
property("mixin.debug.export", "true")
}

// We need large window.
runConfigs.client {
programArgs([
"--width",
Expand All @@ -79,6 +83,7 @@ loom {

runClient {
defaultCharacterEncoding("UTF-8")
// Set client language to zh_cn
if (!new File("${projectDir}/run/client/options.txt").exists()) {
new File("${projectDir}/run/client").mkdirs()
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("${projectDir}/run/client/options.txt"))
Expand All @@ -87,8 +92,8 @@ loom {
bufferedWriter.write("forceUnicodeFont:true\n")
bufferedWriter.write("fov:1.0\n")
bufferedWriter.write("gamma:16.0\n")
bufferedWriter.write("guiScale:2\n")
bufferedWriter.write("lang:zh_CN\n")
bufferedWriter.write("guiScale:3\n")
bufferedWriter.write("lang:${Locale.getDefault().toString()}\n")
bufferedWriter.write("maxFps:260\n")
bufferedWriter.write("renderDistance:10\n")
bufferedWriter.write("soundCategory_master:0.0")
Expand All @@ -112,18 +117,18 @@ remapJar {
remapperIsolation = true
}


setArchivesBaseName("${project.archives_base_name}-${project.minecraft_version}")
setVersion(project.parent.version)
setGroup(project.maven_group)
if (mcVersion > 11701) {
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
setSourceCompatibility(JavaVersion.VERSION_16)
setTargetCompatibility(JavaVersion.VERSION_16)
} else {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
setSourceCompatibility(JavaVersion.VERSION_1_8)
setTargetCompatibility(JavaVersion.VERSION_1_8)
}

archivesBaseName = project.archives_base_name + "-" + project.minecraft_version
version = project.parent.version
group = project.maven_group

processResources {
outputs.upToDateWhen { false }

Expand All @@ -150,7 +155,12 @@ processResources {
}
}

tasks.withType(JavaCompile) {
blossom {
replaceToken("\${mod_id}", project.mod_id)
replaceToken("\${minecraft_version_id}", project.minecraft_version.replace(".", "_"))
}

tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}

Expand All @@ -165,8 +175,7 @@ jar {
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = "${project.mod_id}-${project.minecraft_version.replace(".", "_")}"
version = project.version
artifactId("${project.mod_id}-${project.minecraft_version.replace(".", "_")}")
from(components.java)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class TweakMyClient implements ClientModInitializer {
@Getter
private static final Logger logger = LogManager.getLogger(TweakMyClientReference.getModId());
private static final Logger logger = LogManager.getLogger(TweakMyClientReference.getModIdentifier());
@Getter
@NotNull
private static final Minecraft minecraftClient = Minecraft.getInstance();
Expand Down
Loading

0 comments on commit 53b1774

Please sign in to comment.