Skip to content

Commit

Permalink
Add upload task
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Aug 19, 2024
1 parent fb9dc28 commit 63e57c5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Gradle Upload

on:
push:
branches:
- main

jobs:
upload:
name: Upload to server
runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- uses: gradle/wrapper-validation-action@v3
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 21
- name: Build with Gradle
run: ./gradlew --build-cache test build
- name: Publish
run: ./gradlew uploadJar
env:
UPLOAD_URL: ${{ secrets.UPLOAD_URL }}
Binary file modified .gradle/file-system.probe
Binary file not shown.
25 changes: 25 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import io.papermc.paperweight.userdev.ReobfArtifactConfiguration
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.nio.file.Files

plugins {
java
Expand Down Expand Up @@ -49,6 +54,26 @@ tasks {
runServer {
minecraftVersion("1.21.1")
}

register("uploadJar") {
dependsOn(jar)

doLast {
val filePath = project.tasks.jar.get().archiveFile.get().asFile.toPath()
// Add the upload api url to your repo secrets under UPLOAD_URL
// Obtain the upload url via /team api
val apiUrl = System.getenv("UPLOAD_URL")
val client = HttpClient.newHttpClient()
val request = HttpRequest.newBuilder()
.uri(URI.create(apiUrl))
.header("Content-Type", "application/octet-stream")
.POST(HttpRequest.BodyPublishers.ofByteArray(Files.readAllBytes(filePath)))
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
if (response.statusCode() != 202) throw RuntimeException("Could not upload:\n" + response.body())
println("Upload successful")
}
}
}

bukkit {
Expand Down

0 comments on commit 63e57c5

Please sign in to comment.