From 63e57c54ab64cfd53e9a05f88f1c4e56a025f832 Mon Sep 17 00:00:00 2001 From: Lilly <46890129+RainbowDashLabs@users.noreply.github.com> Date: Mon, 19 Aug 2024 19:17:22 +0200 Subject: [PATCH] Add upload task --- .github/workflows/upload.yml | 26 ++++++++++++++++++++++++++ .gradle/file-system.probe | Bin 8 -> 8 bytes build.gradle.kts | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 .github/workflows/upload.yml diff --git a/.github/workflows/upload.yml b/.github/workflows/upload.yml new file mode 100644 index 0000000..229ed1a --- /dev/null +++ b/.github/workflows/upload.yml @@ -0,0 +1,26 @@ +name: Gradle Upload + +on: + push: + branches: + - main + +jobs: + upload: + name: Upload to server + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4.1.7 + - 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 }} diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 5f20e37324d87f8e8a7e475a67c4e9c531b2931a..b3bd1991ef90a9d5b8cdad4559b299852f0b151f 100644 GIT binary patch literal 8 PcmZQzV4Rq}K-UKV2NePr literal 8 PcmZQzV4Rq>b>0U62-X8Y diff --git a/build.gradle.kts b/build.gradle.kts index e05ebc7..c00f8ff 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 @@ -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 {