Skip to content

Commit

Permalink
Unify publish (#154)
Browse files Browse the repository at this point in the history
* Fix checkVersion task

* Switch to modmuss's publishMods plugin

* Temporary buildscript fix
  • Loading branch information
thecatcore authored Feb 10, 2024
1 parent 450251e commit fbfdc1c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ jobs:
with:
fetch-depth: 0
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew checkVersion build publish github curseforge modrinth --stacktrace
- run: ./gradlew checkVersion build publish publishMods --stacktrace
env:
MAVEN_PUBLISH_CREDENTIALS: ${{ secrets.MAVEN_PUBLISH_CREDENTIALS }}
CURSE_API_KEY: ${{ secrets.CURSE_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
142 changes: 68 additions & 74 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
buildscript {
dependencies {
classpath "org.kohsuke:github-api:1.135"
}
}

plugins {
id "java-library"
id "eclipse"
Expand All @@ -13,19 +7,29 @@ plugins {
id "legacy-looming" version "1.3.75" apply false
id "com.diffplug.spotless" version "6.18.0"
id "org.ajoberstar.grgit" version "3.1.1"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "2.8.2"
id "signing"
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
}

def ENV = System.getenv()

setVersion("${project.base_version}")
logger.lifecycle("Building Fabric: " + version)

def supportedVersions = [
"1.12.2",
"1.11.2",
"1.10.2",
"1.9.4",
"1.8.9",
"1.8",
"1.7.10"
]
def supportedRanges = [
// ["1.8", "1.8.9", false] // third parameter is whether or not to include snapshots in the range.
]

import net.fabricmc.loom.task.RemapJarTask
import org.apache.commons.codec.digest.DigestUtils
import org.kohsuke.github.GHReleaseBuilder
//import org.apache.commons.codec.digest.DigestUtils
import net.legacyfabric.VersionHelper

static def getMCVersion(Project project) {
Expand Down Expand Up @@ -119,8 +123,8 @@ def getSubprojectVersion(Project project) {
if (latestCommits.isEmpty()) {
return version + "+uncommited"
} else {
return version + "+" + latestCommits.get(0).id.substring(0, 8) +
DigestUtils.sha256Hex("${project.name}").substring(0, 2)
return version + "+" + latestCommits.get(0).id.substring(0, 8) //+
// DigestUtils.sha256Hex("${project.name}").substring(0, 2)
}
}

Expand Down Expand Up @@ -491,74 +495,64 @@ remapJar {
}
}

curseforge {
if (project.hasProperty("curse_api_key")) {
apiKey = project.getProperty("curse_api_key")
} else if (ENV.CURSE_API_KEY) {
apiKey = ENV.CURSE_API_KEY
}
project {
id = "400281"
changelog = "A changelog can be found at https://github.com/Legacy-Fabric/fabric/commits"
releaseType = "release"
addGameVersion "Fabric"

// MinecraftVersion.VERSIONS.each {
// addGameVersion it.mc_version
// }

mainArtifact(remapJar) {
displayName = "Legacy Fabric API ${project.base_version}"
}

afterEvaluate {
uploadTask.dependsOn("remapJar")
publishMods {
file = remapJar.archiveFile
changelog = providers.environmentVariable("CHANGELOG").getOrElse("A changelog can be found at https://github.com/Legacy-Fabric/fabric/commits")
type = STABLE
displayName = "Legacy Fabric API $project.version"
modLoaders.add("fabric")
dryRun = providers.environmentVariable("CURSE_API_KEY").getOrNull() == null

curseforge {
accessToken = providers.environmentVariable("CURSE_API_KEY")
projectId = "400281"
projectSlug = "legacy-fabric-api"

minecraftVersions.addAll(supportedVersions)

if (!supportedRanges.isEmpty()) {
supportedRanges.each { range ->
minecraftVersionRange {
start = range[0]
end = range[1]
}
}
}
}
options {
forgeGradleIntegration = false
}
}

modrinth {
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
projectId = "9CJED7xi"

import org.kohsuke.github.GitHub
minecraftVersions.addAll(supportedVersions)

task github(dependsOn: remapJar) {
onlyIf {
ENV.GITHUB_TOKEN
}

doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository(ENV.GITHUB_REPOSITORY)
if (!supportedRanges.isEmpty()) {
supportedRanges.each { range ->
minecraftVersionRange {
start = range[0]
end = range[1]

def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("Legacy Fabric API $project.version")
releaseBuilder.body("A changelog can be found at https://github.com/Legacy-Fabric/fabric/commits")
releaseBuilder.commitish(getBranch())
releaseBuilder.prerelease(false)
includeSnapshots = range[2]
}
}
}
}

def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(remapJar.archiveFile.get().getAsFile(), "application/java-archive")
github {
accessToken = providers.environmentVariable("GITHUB_TOKEN")
repository = providers.environmentVariable("GITHUB_REPOSITORY").getOrElse("LegacyFabric/dryrun")
commitish = providers.environmentVariable("GITHUB_REF_NAME").getOrElse("dryrun")
}
}

modrinth {
projectId = "legacy-fabric-api"
discord {
webhookUrl = providers.environmentVariable("DISCORD_WEBHOOK")

versionNumber = "${project.version}"
versionName = "Legacy Fabric API ${project.version}"
versionType = "release"
changelog = "A changelog can be found at https://github.com/Legacy-Fabric/fabric/commits"
dryRunWebhookUrl = ""

uploadFile = remapJar
username = "Legacy Fabric Bot"

def vers = []
// MinecraftVersion.VERSIONS.each {
// vers.add it.mc_version
// }
gameVersions = vers
loaders = ["fabric"]
content = changelog.map { "# Legacy Fabric API $project.version has been released! \n" + it}
}
}

// A task to ensure that the version being released has not already been released.
Expand All @@ -567,13 +561,13 @@ task checkVersion {
def xml = new URL("https://maven.legacyfabric.net/net/legacyfabric/legacy-fabric-api/legacy-fabric-api/maven-metadata.xml").text
def metadata = new groovy.xml.XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text()
if (versions.contains(version + "+1.8.9")) {
throw new RuntimeException("${version} has already been released!")
versions.each {
if (it.startsWith(project.version + "+1.8.9")) {
throw new RuntimeException("${project.version} has already been released!")
}
}
}
}

github.mustRunAfter checkVersion
//modrinth.mustRunAfter checkVersion
tasks.publishMods.dependsOn checkVersion
publish.mustRunAfter checkVersion
project.tasks.curseforge.mustRunAfter checkVersion

0 comments on commit fbfdc1c

Please sign in to comment.