From c0e6491fefd23ae672028182dfefa97306c9a03d Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Thu, 4 Jul 2024 07:38:06 -0500 Subject: [PATCH] Ci improvements (#4) * Combine publish into main CI * Add auto-publishing to PaperMC Hangar --- .github/workflows/gradle.yml | 62 +++++++++++++++++++++-------------- .github/workflows/publish.yml | 34 ------------------- build.gradle.kts | 25 +++++++++++++- 3 files changed, 62 insertions(+), 59 deletions(-) delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f1e8b94..5cf63be 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,39 +1,53 @@ -name: Java CI +name: Gradle CI on: workflow_dispatch: push: pull_request: + release: + types: [created, prereleased] jobs: - # Build Movecraft-CoreProtect build: runs-on: ubuntu-latest permissions: contents: read + packages: write steps: - - name: Checkout Movecraft-CoreProtect - uses: actions/checkout@v4 - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '21' - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - with: - build-scan-publish: true - build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" - build-scan-terms-of-use-agree: "yes" + - name: Checkout Movecraft-CoreProtect + uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + build-scan-publish: true + build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" + build-scan-terms-of-use-agree: "yes" - - name: Build with Gradle - run: ./gradlew clean build --parallel + - name: Build with Gradle + run: ./gradlew clean build --parallel - - name: Stage jar - run: mkdir staging && cp build/libs/Movecraft-CoreProtect.jar staging && mv staging/Movecraft-CoreProtect.jar staging/Movecraft-CoreProtect_$GITHUB_SHA.jar - - name: Upload jar - uses: actions/upload-artifact@v4 - with: - name: Movecraft-CoreProtect_Dev-Build - path: staging/Movecraft-CoreProtect_*.jar + - name: Publish to GitHub Packages + run: ./gradlew publish --parallel + if: ${{ github.event_name == 'release' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to PaperMC Hangar + run: ./gradlew publishPluginPublicationToHangar --parallel + if: ${{ github.event_name == 'release' }} + env: + HANGAR_API_TOKEN: ${{ secrets.HANGAR_API_TOKEN }} + + - name: Stage jar + run: mkdir staging && cp build/libs/Movecraft-CoreProtect.jar staging && mv staging/Movecraft-CoreProtect.jar staging/Movecraft-CoreProtect_$GITHUB_SHA.jar + - name: Upload jar + uses: actions/upload-artifact@v4 + with: + name: Movecraft-CoreProtect_Dev-Build + path: staging/Movecraft-CoreProtect_*.jar diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index c9360da..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Publish package to GitHub Packages - -on: - workflow_dispatch: - release: - types: [created, prereleased] - -jobs: - # Build Movecraft-CoreProtect - build: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout Movecraft-CoreProtect - uses: actions/checkout@v4 - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '21' - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - with: - build-scan-publish: true - build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" - build-scan-terms-of-use-agree: "yes" - - - name: Build with Gradle - run: ./gradlew clean build publish --parallel - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.gradle.kts b/build.gradle.kts index 0919781..6080a9f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ plugins { `java-library` `maven-publish` id("io.github.0ffz.github-packages") version "1.2.1" + id("io.papermc.hangar-publish-plugin") version "0.1.2" } repositories { @@ -29,7 +30,6 @@ tasks.jar { archiveBaseName.set("Movecraft-CoreProtect") archiveClassifier.set("") archiveVersion.set("") - } tasks.processResources { @@ -60,3 +60,26 @@ publishing { } } } + +hangarPublish { + publications.register("plugin") { + version.set(project.version as String) + channel.set("Release") + id.set("Airship-Pirates/Movecraft-CoreProtect") + apiKey.set(System.getenv("HANGAR_API_TOKEN")) + platforms { + register(io.papermc.hangarpublishplugin.model.Platforms.PAPER) { + jar.set(tasks.jar.flatMap { it.archiveFile }) + platformVersions.set(listOf("1.18.2-1.21")) + dependencies { + hangar("Movecraft") { + required.set(true) + } + hangar("CoreProtect") { + required.set(true) + } + } + } + } + } +}