Skip to content

Commit

Permalink
pls work :(
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Oct 24, 2023
1 parent dfa364c commit 9e9666b
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 61 deletions.
36 changes: 14 additions & 22 deletions .github/workflows/build-multiver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ jobs:
with:
java-version: ${{ matrix.java }}
distribution: zulu
cache: gradle

- name: cache loom
uses: actions/cache@v3
with:
path: ~/.gradle/loom-cache
key: loom-cache-${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties') }}
restore-keys: loom-cache-${{ runner.os }}-gradle
- name: cache gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/loom-cache
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle

- name: give scripts execution permissions
run: chmod +x gradlew buildAll
Expand All @@ -55,24 +57,14 @@ jobs:
name: cu-artifacts-merged
path: artifacts/merged/*.jar

- name: get names of merged artifacts
id: get_names
run: |
echo "names=$(ls artifacts/merged/*.jar)" >> GITHUB_OUTPUT
- name: send artifacts to webhook
if: success()
uses: appleboy/discord-action@v1.0.0
with:
webhook_id: ${{ secrets.WEBHOOK_ID }}
webhook_token: ${{ secrets.WEBHOOK_TOKEN }}
args: '# Build #${{ github.run_number }}'
file: ${{ steps.get_names.outputs.names }}

- name: send failure message
if: failure()
uses: appleboy/discord-action@v1.0.0
with:
webhook_id: ${{ secrets.WEBHOOK_ID }}
webhook_token: ${{ secrets.WEBHOOK_TOKEN }}
args: '# Build #${{ github.run_number }} failed'
args: '# Build #${{ github.run_number }} failed'

- name: send artifacts to webhook
if: success()
run: ./gradlew webhook -Pwebhook_url=${{ secrets.DISCORD_WEBHOOK }}
59 changes: 28 additions & 31 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,6 @@ subprojects {
remapJar.finalizedBy(mergeJars)
}

tasks.register("moveJars", Copy) {
def unmerged = copySpec {
def subs = rootProject.subprojects
subs.remove(rootProject.project(':common'))

Map<File, String> files = [:]
subs.each {
it.buildDir.toPath().resolve('libs').toFile().listFiles().each { file ->
println "Found ${file.name} in ${it.name}"
files.put(file, it.name)
}
}

files.each { file, name ->
File newFile = new File(file.parent, file.name.replace('.jar', "-${name}.jar"))
file.renameTo(newFile)
from newFile
into "artifacts/unmerged/${rootProject.mcVer}"
}
}
def merged = copySpec {
from rootProject.file('build/libs/merged')
into 'artifacts/merged'
}

with unmerged
with merged
destinationDir = rootProject.rootDir
duplicatesStrategy(DuplicatesStrategy.WARN)
}

allprojects {
apply plugin: 'java'

Expand All @@ -73,6 +42,12 @@ allprojects {
}
}

webhook {
url = webhook_url
files = file('artifacts/merged').listFiles().collect()
message = "Build #${build_number}"
}

jar {
enabled = false
}
Expand Down Expand Up @@ -102,9 +77,31 @@ def setup() {

apply from: 'gradle/preprocessor.gradle'
apply from: 'gradle/accesswidener.gradle'
apply from: 'gradle/webhook.gradle'

println '\nPlugin versions:'
apply plugin: 'architectury-plugin'

defineMixins()

tasks.register("moveJars", Copy) {
def subs = rootProject.subprojects
subs.remove(rootProject.project(':common'))
subs.remove(rootProject.project(':forge'))

subs.each {
it.buildDir.toPath().resolve('libs').toFile().listFiles().each { file ->
File newFile = new File(file.parent, file.name.replace('.jar', "-${file.name}.jar"))
java.nio.file.Files.copy(file.toPath(), java.nio.file.Path.of("artifacts/unmerged/${rootProject.mcVer}", newFile.name))
}
}

with copySpec {
from rootProject.file('build/libs/merged')
into 'artifacts/merged'
}

destinationDir = rootProject.rootDir
duplicatesStrategy(DuplicatesStrategy.WARN)
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ maven_group = dev.rdh.createunlimited
archives_base_name = createunlimited

# compiler go brrrrr
manifold_version = 2023.1.28
manifold_version = 2023.1.29

# mixin
mixin_extras = 0.1.1
Expand Down
91 changes: 91 additions & 0 deletions gradle/webhook.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import com.google.gson.*

import java.nio.file.Files

buildscript {
repositories.mavenCentral()
dependencies {
classpath 'com.google.code.gson:gson:2.8.9'
}
}

project.extensions.add('webhook', WebhookExt)

tasks.register('webhook') {
def config = project.extensions.findByType(WebhookExt)
if(config == null) {
println 'Webhook extension not found!'
throw new GradleException()
}
doLast {
def payload = new JsonObject()
payload.add('content', new JsonPrimitive(config.message.get()))
send(config.url.get(), config.files.get(), payload)
}
}

def send(String url, List<File> files, JsonObject payload) {
def webhook = new URL(url)
def con = webhook.openConnection() as HttpURLConnection
con.requestMethod = 'POST'
con.doOutput = true
OutputStream os = con.outputStream

if(payload != null) {
con.setRequestProperty 'Content-Type', 'application/json; charset=UTF-8'
con.setRequestProperty 'User-Agent', 'Mozilla/5.0'

new PrintWriter(new OutputStreamWriter(os, 'UTF-8'), true).withCloseable {
it.println payload.toString()
}
}

con.setRequestProperty 'Content-Type', 'multipart/form-data; boundary=boundary'
con.setRequestProperty 'User-Agent', 'Mozilla/5.0'

new PrintWriter(new OutputStreamWriter(os, 'UTF-8'), true).withCloseable {
if (files != null) {
for (int i = 0; i < files.size(); i++) {
File file = files[i]
it.println """
--boundary
Content-Disposition: form-data; name="files[$i]"; filename="${file.name}"
"""
Files.copy file.toPath(), os
}
}
it.println '--boundary--'
}

def response = con.responseCode
def message = con.inputStream.text

if (response == HttpURLConnection.HTTP_OK || response == HttpURLConnection.HTTP_NO_CONTENT) {
println 'Successfully sent webhook!'
} else {
println 'Failed to send webhook!'
println 'Response code: ' + response
println 'Message: ' + message
throw new GradleException()
}
}

abstract class WebhookExt {

@Input
abstract Property<String> url

@Input
abstract ListProperty<File> files

@Input
abstract Property<String> message

WebhookExt(Project project) {
url = project.objects.property(String)
files = project.objects.listProperty(File)
files.convention([])
message = project.objects.property(String)
message.convention('')
}
}
15 changes: 8 additions & 7 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
pluginManagement {
repositories {
maven { url "https://maven.fabricmc.net/" }
maven { url "https://maven.architectury.dev/" }
maven { url "https://maven.minecraftforge.net/" }
maven { url 'https://maven.fabricmc.net/' }
maven { url 'https://maven.architectury.dev/' }
maven { url 'https://maven.minecraftforge.net/' }
gradlePluginPortal()
}
//includeBuild '../../imag'
}

include("common")
include("fabric")
include("forge")
include 'common'
include 'fabric'
include 'forge'

rootProject.name = 'Create Unlimited'

rootProject.name = "Create Unlimited"

0 comments on commit 9e9666b

Please sign in to comment.