Skip to content

Commit

Permalink
chore(ci): sort out fabric uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Jul 15, 2023
1 parent 89f8ddf commit 82d075e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
IS_RELEASE: true
run: |
# Build
./gradlew build :${{ matrix.loader }}:${{ matrix.release-task }}
./gradlew :${{ matrix.loader }}:build :${{ matrix.loader }}:${{ matrix.release-task }}
2 changes: 1 addition & 1 deletion .github/workflows/snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
# Build
./gradlew build :${{ matrix.loader }}:${{ matrix.release-task }}
./gradlew :${{ matrix.loader }}:build :${{ matrix.loader }}:${{ matrix.release-task }}
66 changes: 66 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import org.apache.http.HttpEntity
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.ContentType
import org.apache.http.entity.mime.MultipartEntityBuilder
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.apache.httpcomponents:httpmime:4.5.14"
}
}

plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
id "com.matthewprenger.cursegradle" version "1.4.0"
}

def branch = System.getenv("GITHUB_REF")
Expand Down Expand Up @@ -96,6 +115,8 @@ java {
}

jar {
archiveClassifier = 'universal'
archiveBaseName = "${archivesBaseName}${project.mc_label}-fabric"
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
Expand All @@ -119,3 +140,48 @@ publishing {
}


def getReleaseChangelog() {
def changelogFile = file('../CHANGELOG.md')
def changelog = "## [${changelogFile.text.split('\n## \\[')[1]}\n\n"// ${project.github}/blob/${branch}/CHANGELOG.md
return changelog;
}

task discordupload {
dependsOn(jar)
doLast {
String discordWebhook = System.getenv("DISCORD_WEBHOOK")

if(discordWebhook != null) {

CloseableHttpClient httpClient = HttpClients.createDefault()
HttpPost uploadFile = new HttpPost(discordWebhook)

MultipartEntityBuilder builder = MultipartEntityBuilder.create()
if(!isRelease) {
builder.addTextBody("content", "New snapshot or testing build")
} else {
builder.addTextBody("content", "New release build\n" +
"```markdown\n" +
"${getReleaseChangelog()}\n" +
"```")
}

var name = jar.archiveBaseName.get() + "-" + jar.archiveVersion.get() + ".jar"

builder.addBinaryBody("file", file(jar.archiveFile).newInputStream(), ContentType.APPLICATION_OCTET_STREAM, name)

HttpEntity multipart = builder.build()

uploadFile.setEntity(multipart)
CloseableHttpResponse response = httpClient.execute(uploadFile)
response.getEntity()

println("Posted build")

} else {
println("Discord webhook unspecified")
}
}
}


5 changes: 5 additions & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
"fabric-api": "*"
},
"suggests": {
},
"custom": {
"modmenu": {
"badges": [ "library" ]
}
}
}
7 changes: 1 addition & 6 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,7 @@ def getReleaseChangelog() {
return changelog;
}

/**
* For pre-releases and testers to be able to try the latest commits if they want.
* If the builds start exceeding 8MB then we may want to upload to s3 instead and periodically clear.
* TODO possibly add a task that announces when builds are made?
* Though add a note that it may take a while for Curse to approve the files.
*/

task discordupload {
dependsOn(jar)
doLast {
Expand Down

0 comments on commit 82d075e

Please sign in to comment.