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 8cb6899 commit cd922cb
Show file tree
Hide file tree
Showing 4 changed files with 135 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
140 changes: 91 additions & 49 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@ apply plugin: 'maven-publish'
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.commoncapabilities"
archivesBaseName = "CommonCapabilities-${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 @@ -45,7 +47,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 @@ -199,11 +232,6 @@ runs {
}
}

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

jar {
manifest {
attributes([
Expand Down Expand Up @@ -277,45 +305,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 = "247007" // my project url is http://minecraft.curseforge.com/mc-mods/247007/

def mainFile = upload(projectId, jar)
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 = "oFXrCkDI"
versionNumber = project.minecraft_version + '-' + project.mod_version
versionType = project.release_type
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
37 changes: 24 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
mod_id=commoncapabilities
# Project
mod_version=2.9.7
group=org.cyclops.commoncapabilities
java_version=21

# Common
minecraft_version=1.21.1
neoforge_version=21.1.2
mod_name=CommonCapabilities
mod_author=rubensworks (aka kroeser)
mod_id=commoncapabilities
license=MIT
github_url=https://github.com/CyclopsMC/CommonCapabilities
issue_tracker_url=https://github.com/CyclopsMC/CommonCapabilities/issues
display_url=https://www.curseforge.com/minecraft/mc-mods/commoncapabilities
description=Capabilities that can be shared by multiple mods.
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

parchment_version=2024.07.07
parchment_minecraft_version=1.21
cyclopscore_version=1.25.1-627
release_type=release
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44
curseforge_project_id=247007
modrinth_project_id=oFXrCkDI

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

# Dependencies
cyclopscore_version=1.25.1-627
rfapi_version=1.12-2.1.0.7
enderio_version=3.0.0.40_alpha
endercore_version=0.4.0.24-alpha
Expand All @@ -21,11 +40,3 @@ cofhcore_version=1.12.2-4.6.2.25
thermalfoundation_version=1.12.2-2.6.2.26
cofhworld_version=1.12.2-1.3.0.6
codechickenlib_version=1.12.2-3.2.2.354

# 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
36 changes: 18 additions & 18 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
modLoader="javafml"
loaderVersion="[2,)"
issueTrackerURL="https://github.com/CyclopsMC/CommonCapabilities/issues"
displayURL="https://www.curseforge.com/minecraft/mc-mods/commoncapabilities"
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="commoncapabilities"
version="${file.jarVersion}"
displayName="CommonCapabilities"
updateJSONURL="https://raw.githubusercontent.com/CyclopsMC/Versions/master/neoforge_update/common-capabilities.json"
description='''
Forge Capabilities that can be shared by multiple mods.
'''
modId="${mod_id}"
version="${mod_version}"
displayName="${mod_name}"
updateJSONURL="${neoforge_update_json_url}"
description="${description}"
[[accessTransformers]]
file="META-INF/accesstransformer.cfg"
[[dependencies.commoncapabilities]]
[[mixins]]
config="mixins.${mod_id}.json"
[[dependencies.${mod_id}]]
modId="cyclopscore"
type="required"
versionRange="[1.25.1,)"
versionRange="[${cyclopscore_version_semver},)"
ordering="NONE"
side="BOTH"
[[dependencies.commoncapabilities]]
[[dependencies.${mod_id}]]
modId="neoforge"
type="required"
versionRange="[21.1.2,)"
versionRange="[${neoforge_version},)"
ordering="NONE"
side="BOTH"
[[dependencies.commoncapabilities]]
[[dependencies.${mod_id}]]
modId="minecraft"
type="required"
versionRange="[1.21.1,]"
versionRange="[${minecraft_version},]"
ordering="NONE"
side="BOTH"

0 comments on commit cd922cb

Please sign in to comment.