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 e089d00 commit 742eefe
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 88 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
148 changes: 97 additions & 51 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,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.integratedscripting"
archivesBaseName = "IntegratedScripting-${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 @@ -46,7 +48,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 @@ -164,11 +197,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 @@ -248,47 +276,65 @@ 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("-.*\$", ""),
'commoncapabilities_version' : commoncapabilities_version,
'commoncapabilities_version_semver' : commoncapabilities_version.replaceAll("-.*\$", ""),
'integrateddynamics_version' : integrateddynamics_version,
'integrateddynamics_version_semver' : integrateddynamics_version.replaceAll("-.*\$", "")
]

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

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

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')
mainFile.addRequirement('integrated-dynamics')
task publishCurseForge(type: TaskPublishCurseForge) {
dependsOn(tasks.jar)
apiToken = secrets.curseforgeKey;
def mainFile = upload(project.curseforge_project_id, shadowJar)
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")
mainFile.addRequirement('integrated-dynamics')
}

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 = "uDJkuFRe"
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 = shadowJar
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
required.project "yYzdQHJI" // Integrated Dynamics
changelog = provider { secrets.changelog }

dependencies {
required.project "Z9DM0LJ4" // Cyclops Core
required.project "yYzdQHJI" // Integrated Dynamics
}
}

Expand Down
37 changes: 24 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
mod_id=integratedscripting
# Project
mod_version=1.0.7
group=org.cyclops.integratedscripting
java_version=21

# Common
minecraft_version=1.21.1
neoforge_version=21.1.2
mod_name=IntegratedScripting
mod_author=rubensworks (aka kroeser)
mod_id=integratedscripting
license=MIT
github_url=https://github.com/CyclopsMC/IntegratedScripting
issue_tracker_url=https://github.com/CyclopsMC/IntegratedScripting/issues
display_url=https://www.curseforge.com/minecraft/mc-mods/integrated-scripting
description=Create scripts for handling operations in Integrated Dynamics.
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

parchment_version=2024.07.07
parchment_minecraft_version=1.21
curseforge_project_id=889785
modrinth_project_id=uDJkuFRe

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

# Dependencies
cyclopscore_version=1.25.1-627
integrateddynamics_version=1.23.2-832
release_type=release
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

commoncapabilities_version=2.9.3-147

# 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
42 changes: 20 additions & 22 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
modLoader="javafml"
loaderVersion="[2,)"
issueTrackerURL="https://github.com/CyclopsMC/IntegratedScripting/issues"
displayURL="https://www.curseforge.com/minecraft/mc-mods/integrated-scripting"
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="integratedscripting"
version="${file.jarVersion}"
displayName="IntegratedScripting"
updateJSONURL="https://raw.githubusercontent.com/CyclopsMC/Versions/master/neoforge_update/integrated-scripting.json"
description='''
Create scripts for handling operations in Integrated Dynamics.
'''
[[dependencies.integratedscripting]]
modId="${mod_id}"
version="${mod_version}"
displayName="${mod_name}"
updateJSONURL="${neoforge_update_json_url}"
description="${description}"
[[dependencies.${mod_id}]]
modId="cyclopscore"
type="required"
versionRange="[1.25.1,)"
versionRange="[${cyclopscore_version_semver},)"
ordering="NONE"
side="BOTH"
[[dependencies.integratedscripting]]
[[dependencies.${mod_id}]]
modId="commoncapabilities"
type="required"
versionRange="[2.9.3,)"
versionRange="[${commoncapabilities_version_semver},)"
ordering="NONE"
side="BOTH"
[[dependencies.integratedscripting]]
[[dependencies.${mod_id}]]
modId="integrateddynamics"
type="required"
versionRange="[1.23.2,)"
versionRange="[${integrateddynamics_version_semver},)"
ordering="NONE"
side="BOTH"
[[dependencies.integratedscripting]]
[[dependencies.${mod_id}]]
modId="neoforge"
type="required"
versionRange="[21.1.2,)"
versionRange="[${neoforge_version},)"
ordering="NONE"
side="BOTH"
[[dependencies.integratedscripting]]
[[dependencies.${mod_id}]]
modId="minecraft"
type="required"
versionRange="[1.21.1,]"
versionRange="[${minecraft_version},]"
ordering="NONE"
side="BOTH"

0 comments on commit 742eefe

Please sign in to comment.