Skip to content

Commit

Permalink
Update build.gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Feb 28, 2023
1 parent c12f883 commit 8131521
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.135'
}
}

plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'maven-publish'
}

def ENV = System.getenv()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

Expand Down Expand Up @@ -83,13 +91,35 @@ publishing {
}
}

afterEvaluate {
// Loom 0.11's devlibs folder messes with my other scripts,
// so I'm moving these files back to the old location.
tasks.named("remapJar") {
doLast {
ant.move(file:"${project.buildDir}/devlibs/${archivesBaseName}-${version}-dev.jar", tofile:"${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar")
ant.move(file:"${project.buildDir}/devlibs/${archivesBaseName}-${version}-sources.jar", tofile:"${project.buildDir}/libs/${archivesBaseName}-${version}-sources-dev.jar")
}
}
task moveDevLibs(dependsOn: [remapJar, remapSourcesJar]) {
doLast {
ant.move(file:"${project.buildDir}/devlibs/${archivesBaseName}-${version}-dev.jar", tofile:"${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar")
ant.move(file:"${project.buildDir}/devlibs/${archivesBaseName}-${version}-sources.jar", tofile:"${project.buildDir}/libs/${archivesBaseName}-${version}-sources-dev.jar")
}
}

import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub

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

doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository("Wurst-Imperium/Wurst-MCX2")
def ghVersion = version.substring(0, version.indexOf("-"))

def ghRelease = repository.getReleaseByTagName(ghVersion as String)
if(ghRelease == null) {
def releaseBuilder = new GHReleaseBuilder(repository, ghVersion as String)
ghRelease = releaseBuilder.create()
}

ghRelease.uploadAsset(remapJar.archiveFile.get().getAsFile(), "application/java-archive")
ghRelease.uploadAsset(remapSourcesJar.archiveFile.get().getAsFile(), "application/java-archive")
ghRelease.uploadAsset(new File("${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar"), "application/java-archive")
ghRelease.uploadAsset(new File("${project.buildDir}/libs/${archivesBaseName}-${version}-sources-dev.jar"), "application/java-archive")
}
}

0 comments on commit 8131521

Please sign in to comment.