Skip to content

Commit

Permalink
Modernize CI and gradle.properties usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Dec 12, 2024
1 parent eb96b47 commit da26ede
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ jobs:
if-no-files-found: error
path: build/libs/*
- name: 'Deploy to CurseForge'
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/master')
env:
CURSEFORGE_KEY_SECRET: ${{ secrets.CURSEFORGE_KEY_SECRET }}
run: ./gradlew publishCurseForge
- name: 'Deploy to Modrinth'
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/master')
env:
MODRINTH_KEY_SECRET: ${{ secrets.MODRINTH_KEY_SECRET }}
run: ./gradlew modrinth
Expand Down
142 changes: 92 additions & 50 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,33 @@ apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'jacoco'

import net.neoforged.gradle.common.tasks.PotentiallySignJar
import net.darkhax.curseforgegradle.Constants
import net.darkhax.curseforgegradle.TaskPublishCurseForge

// Determine build number
String build_number = "DEV" // this will be referenced as simply build_number from now on.
if (System.getenv().BUILD_NUMBER)
build_number = System.getenv().BUILD_NUMBER
if (System.getenv().TRAVIS_BUILD_NUMBER)
build_number = System.getenv().TRAVIS_BUILD_NUMBER
if (System.getenv().GITHUB_RUN_ID)
build_number = System.getenv().GITHUB_RUN_NUMBER
if (System.getenv().RELEASE || System.getenv().TRAVIS_TAG)
if (System.getenv().RELEASE)
build_number = "RELEASE"
logger.lifecycle "BUILDING VERSION: " + build_number

// Set mod details
version = project.mod_version
group = "org.cyclops.evilcraft"
archivesBaseName = "EvilCraft-${project.minecraft_version}-neoforge"
// Include build number in version
if (build_number.equals("RELEASE"))
version = "${project.mod_version}"
else
version = "${project.mod_version}-${build_number}"

base {
archivesName = archivesBaseName
archivesName = "${mod_id}-${minecraft_version}-neoforge"
}

// Set Java details
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
java {
toolchain.languageVersion = JavaLanguageVersion.of(java_version)
}
compileJava.options.compilerArgs << "-Xmaxerrs" << "9999"
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))

// Load secrets
def getSecrets() {
Expand All @@ -47,7 +49,38 @@ def getSecrets() {
}
return props
}
Properties secrets = getSecrets();
def getCurseforgeKey() {
if(secrets.curseforge_key) {
return secrets.curseforge_key
} else if(System.getenv().GITHUB_ACTIONS && System.getenv().CURSEFORGE_KEY_SECRET) {
return System.getenv().CURSEFORGE_KEY_SECRET
} else {
return "DUMMY"
}
}
def getModrinthKey() {
if(secrets.modrinth_key) {
return secrets.modrinth_key
} else if(System.getenv().GITHUB_ACTIONS && System.getenv().MODRINTH_KEY_SECRET) {
return System.getenv().MODRINTH_KEY_SECRET
} else {
return "DUMMY"
}
}
def getChangelog() {
if (System.getenv().RELEASE) {
return file("./resources/changelog/${project.minecraft_version}-${project.mod_version}.txt").getText();
} else {
return "Changes since last release: ${project.github_url}/compare/${project.minecraft_version}-${project.mod_version}...${System.getenv().GITHUB_SHA}"
}
}
//ext {
Properties secrets = getSecrets();
secrets.curseforgeKey = getCurseforgeKey();
secrets.modrinthKey = getModrinthKey();
secrets.changelog = getChangelog();
secrets.build_number = build_number;
//}

sourceSets {
main
Expand Down Expand Up @@ -147,11 +180,6 @@ runs {
}
}

if (build_number.equals("RELEASE"))
version = "${project.mod_version}"
else
version = "${project.mod_version}-${build_number}"

jar {
archiveClassifier.set('slim')
manifest {
Expand Down Expand Up @@ -235,45 +263,59 @@ artifacts {
archives javadocJar
}

task publishCurseForge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) {
dependsOn(tasks.jar)

if(secrets.hasProperty("curseforge_key") && secrets.hasProperty("changelog")) {
apiToken = secrets.curseforge_key
} else if(System.getenv().GITHUB_ACTIONS && System.getenv().CURSEFORGE_KEY_SECRET) {
apiToken = System.getenv().CURSEFORGE_KEY_SECRET
} else {
apiToken = "DUMMY"
// Replace properties in files
processResources {
def expandProps = [
'mod_version' : mod_version,
'group' : project.group, //Else we target the task's group.
'minecraft_version' : minecraft_version,
'mod_name' : mod_name,
'mod_author' : mod_author,
'mod_id' : mod_id,
'license' : license,
'issue_tracker_url' : issue_tracker_url,
'display_url' : display_url,
'description' : project.description,
'neoforge_version' : neoforge_version,
'neoforge_loader_version_range' : neoforge_loader_version_range,
'neoforge_update_json_url' : neoforge_update_json_url,
'java_version' : java_version,
'cyclopscore_version' : cyclopscore_version,
'cyclopscore_version_semver' : cyclopscore_version.replaceAll("-.*\$", "")
]

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

def projectId = "74610" // my project url is http://minecraft.curseforge.com/mc-mods/74610/

def mainFile = upload(projectId, shadowJar)
mainFile.releaseType = 'release'
mainFile.changelogType = "text"
mainFile.changelog = file("resources/changelog/${project.minecraft_version}-${project.version}.txt")
mainFile.addGameVersion(project.minecraft_version)
mainFile.addModLoader("NeoForge")

mainFile.addRequirement('cyclops-core')
task publishCurseForge(type: TaskPublishCurseForge) {
dependsOn(tasks.jar)
apiToken = secrets.curseforgeKey;
def mainFile = upload(project.curseforge_project_id, jar)
mainFile.releaseType = secrets.build_number.equals("RELEASE") ? Constants.RELEASE_TYPE_RELEASE : Constants.RELEASE_TYPE_BETA
mainFile.changelogType = "text"
mainFile.changelog = secrets.changelog
mainFile.addJavaVersion("Java ${project.java_version}")
mainFile.addGameVersion(project.minecraft_version)
mainFile.addModLoader("NeoForge")

mainFile.addRequirement("cyclops-core")
}

modrinth {
if(secrets.modrinth_key) {
token = secrets.modrinth_key
} else if(System.getenv().GITHUB_ACTIONS && System.getenv().MODRINTH_KEY_SECRET) {
token = System.getenv().MODRINTH_KEY_SECRET
} else {
token = "DUMMY"
}
projectId = "3ANq2btA"
versionNumber = project.minecraft_version + '-' + project.mod_version
versionType = project.release_type
uploadFile = shadowJar
token = secrets.modrinthKey;
projectId = "${modrinth_project_id}"
versionNumber = project.minecraft_version + '-' + project.version
versionName = "${project.version} for NeoForge ${project.minecraft_version}"
versionType = secrets.build_number.equals("RELEASE") ? "release" : "beta"
uploadFile = jar
gameVersions = [ project.minecraft_version ]
changelog = provider { file("resources/changelog/${project.minecraft_version}-${project.version}.txt").getText() }
dependencies { // A special DSL for creating dependencies
required.project "Z9DM0LJ4" // Cyclops Core
changelog = provider { secrets.changelog }

dependencies {
required.project "Z9DM0LJ4" // Cyclops Core
}
}

Expand Down
36 changes: 24 additions & 12 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
mod_id=evilcraft
# Project
mod_version=1.2.59
group=org.cyclops.evilcraft
java_version=21

# Common
minecraft_version=1.21.1
neoforge_version=21.1.2
mod_name=EvilCraft
mod_author=rubensworks (aka kroeser)
mod_id=evilcraft
license=MIT
github_url=https://github.com/CyclopsMC/EvilCraft
issue_tracker_url=https://github.com/CyclopsMC/EvilCraft/issues
display_url=https://www.curseforge.com/minecraft/mc-mods/evilcraft
description=An evil mod for Minecraft.
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

parchment_version=2024.07.07
parchment_minecraft_version=1.21
curseforge_project_id=74610
modrinth_project_id=3ANq2btA

# NeoForge
neoforge_version=21.1.2
neoforge_loader_version_range=[4,)
neoforge_update_json_url=https://raw.githubusercontent.com/CyclopsMC/Versions/master/neoforge_update/evilcraft.json

# Dependencies
cyclopscore_version=1.25.1-627
evilcraftcompat_version=1.1.0-70
release_type=release
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

# Workaround for Spotless bug
# https://github.com/diffplug/spotless/issues/834
org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
34 changes: 16 additions & 18 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
modLoader="javafml"
loaderVersion="[2,)"
issueTrackerURL="https://github.com/CyclopsMC/EvilCraft/issues"
displayURL="https://www.curseforge.com/minecraft/mc-mods/evilcraft"
license="MIT"
loaderVersion="${neoforge_loader_version_range}"
issueTrackerURL="${issue_tracker_url}"
displayURL="${display_url}"
license="${license}"
logoFile="logo.png"
authors="rubensworks (aka kroeser)"
authors="${mod_author}"
[[mods]]
modId="evilcraft"
version="${file.jarVersion}"
displayName="EvilCraft"
updateJSONURL="https://raw.githubusercontent.com/CyclopsMC/Versions/master/neoforge_update/evilcraft.json"
description='''
An evil mod for Minecraft.
'''
modId="${mod_id}"
version="${mod_version}"
displayName="${mod_name}"
updateJSONURL="${neoforge_update_json_url}"
description="${description}"
[[accessTransformers]]
file="META-INF/accesstransformer.cfg"
[[dependencies.evilcraft]]
[[dependencies.${mod_id}]]
modId="cyclopscore"
type="required"
versionRange="[1.25.1,)"
versionRange="[${cyclopscore_version_semver},)"
ordering="NONE"
side="BOTH"
[[dependencies.evilcraft]]
[[dependencies.${mod_id}]]
modId="neoforge"
type="required"
versionRange="[21.1.2,)"
versionRange="[${neoforge_version},)"
ordering="NONE"
side="BOTH"
[[dependencies.evilcraft]]
[[dependencies.${mod_id}]]
modId="minecraft"
type="required"
versionRange="[1.21.1,]"
versionRange="[${minecraft_version},]"
ordering="NONE"
side="BOTH"

0 comments on commit da26ede

Please sign in to comment.