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 5f20e37..b3bd199 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ 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 {