From 16a64a20359ccc4a042f1e17527dd673a610a330 Mon Sep 17 00:00:00 2001
From: modmuss50 <modmuss50@gmail.com>
Date: Wed, 1 Jul 2020 18:58:47 +0100
Subject: [PATCH] Github release publishing

---
 build.gradle | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/build.gradle b/build.gradle
index ed681b7d5..001059840 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,3 +1,9 @@
+buildscript {
+	dependencies {
+		classpath 'org.kohsuke:github-api:1.114'
+	}
+}
+
 plugins {
 	id 'java'
 	id 'eclipse'
@@ -278,3 +284,24 @@ curseforge {
 }
 
 apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/ideconfig.gradle'
+
+import org.kohsuke.github.GHReleaseBuilder
+import org.kohsuke.github.GitHub
+
+task github(dependsOn: remapMavenJar) {
+	onlyIf {
+		project.hasProperty('github_api_key')
+	}
+	doLast {
+		def github = GitHub.connectUsingOAuth(project.getProperty('github_api_key') as String)
+		def repository = github.getRepository("FabricMC/fabric")
+
+		def releaseBuilder = new GHReleaseBuilder(repository, version as String)
+		releaseBuilder.name("[$Globals.mcVersion] Fabric API $Globals.baseVersion build $ENV.BUILD_NUMBER")
+		releaseBuilder.body('A changelog can be found at https://github.com/FabricMC/fabric/commits')
+		releaseBuilder.commitish(getBranch())
+
+		def ghRelease = releaseBuilder.create()
+		ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
+	}
+}