Skip to content

Commit

Permalink
Add releasing tasks to Gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jul 18, 2023
1 parent 338041e commit c058ca4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 7 deletions.
98 changes: 91 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
//file:noinspection all

buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.+'
}
}

plugins {
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
id "fabric-loom" version "1.3-SNAPSHOT"
id "maven-publish"
id "org.jetbrains.kotlin.jvm" version "1.9.+"

id 'com.matthewprenger.cursegradle' version '1.+'
id 'com.modrinth.minotaur' version '2.+'
}

version = project.mod_version
group = project.maven_group

import com.modrinth.minotaur.dependencies.DependencyType
import com.modrinth.minotaur.dependencies.ModDependency
import org.kohsuke.github.GHReleaseBuilder

version = mod_version
group = maven_group

repositories {
maven {
name = 'Terraformers'
url = 'https://maven.terraformersmc.com/releases/'
name = "Terraformers"
url = "https://maven.terraformersmc.com/releases/"
}
}

Expand Down Expand Up @@ -56,7 +70,7 @@ sourceSets {
main {
resources {
srcDirs += [
'src/generated/resources'
"src/generated/resources"
]
}
}
Expand Down Expand Up @@ -102,3 +116,73 @@ publishing {
repositories {
}
}


/* Releasing */

def environment = System.getenv()
def versionText = "[$major_version] $mod_name $version"
def changelogText = new File("./gradle", "CHANGELOG.md").text
def supportedVersions = Arrays.asList(supported_versions.split(","))

tasks.register("github") {
onlyIf { environment.GITHUB_TOKEN }
dependsOn(build)
doLast {
def github = GitHub.connectUsingOAuth(environment.GITHUB_TOKEN)
def repository = github.getRepository(github_repository)

def builder = new GHReleaseBuilder(repository, version)
builder.name(versionText)
builder.body(changelogText)
builder.commitish(github_branch)
builder.prerelease(release_type == "beta")
builder.create().uploadAsset(file("${buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
}
}

if (environment.MODRINTH_TOKEN) modrinth {
token = environment.MODRINTH_TOKEN
projectId = modrinth_id
versionNumber = version
versionName = versionText
versionType = release_type
changelog = changelogText
uploadFile = remapJar
gameVersions = supportedVersions
dependencies = [
new ModDependency("fabric-api", DependencyType.REQUIRED),
new ModDependency("fabric-language-kotlin", DependencyType.REQUIRED),
]
}

if (environment.CURSEFORGE_API_KEY) curseforge {
apiKey = environment.CURSEFORGE_API_KEY

project {
id = curseforge_id

addGameVersion "Fabric"

for (final def cf_ver in supportedVersions) addGameVersion cf_ver

changelog = changelogText
releaseType = release_type

mainArtifact(remapJar) {
displayName = versionText
relations {
requiredDependency "fabric-api"
requiredDependency "fabric-language-kotlin"
}
}

afterEvaluate { uploadTask.dependsOn(remapJar) }
}

options { forgeGradleIntegration = false }
}

tasks.register("releaseVersion").configure {
dependsOn("build", "modrinth", "github", "curseforge")
}
10 changes: 10 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ mod_menu_version=7.1.0

# Metadata
mod_id=hybrid-blocks
mod_name=Hybrid Blocks
release_type=release
major_version=1.20
supported_versions=1.20,1.20.1

modrinth_id=61Q9LmD0
curseforge_id=832475

github_repository=hybridlabs/hybrid-blocks
github_branch=1.20
1 change: 1 addition & 0 deletions gradle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No changelog provided.

0 comments on commit c058ca4

Please sign in to comment.