From a52da2144965b0f1383d801fbaf0f5355b0326db Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Thu, 4 Jul 2024 19:53:47 -0500 Subject: [PATCH] Update CI and build for publishing --- .github/workflows/gradle.yml | 62 ++++++++++++++---------------------- build.gradle.kts | 54 +++++++++++++++++-------------- 2 files changed, 54 insertions(+), 62 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 053ae71..4f4da30 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,72 +1,58 @@ -name: Java CI +name: Gradle CI on: workflow_dispatch: push: pull_request: + release: + types: [created, prereleased] jobs: - # Build AP-Turrets build: runs-on: ubuntu-latest permissions: - contents: read + contents: write + packages: write steps: - name: Checkout AP-Turrets uses: actions/checkout@v4 - with: - path: AP-Turrets - name: Set up JDK 21 uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '21' - - name: Checkout Movecraft-Combat - uses: actions/checkout@v3 - with: - repository: 'APDevTeam/Movecraft-Combat' - path: Movecraft-Combat - ref: 'main' - - name: Checkout Movecraft-WorldGuard - uses: actions/checkout@v3 - with: - repository: 'APDevTeam/Movecraft-WorldGuard' - path: Movecraft-WorldGuard - ref: 'main' - 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: Cache Maven packages - id: cacheMain - uses: actions/cache@v3 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2 - restore-keys: ${{ runner.os }}-m2 - # Build Movecraft-Combat - - name: Build Movecraft-Combat - run: mvn -B package -T 1C --file Movecraft-Combat/pom.xml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build with Gradle + run: ./gradlew clean reobfJar --parallel - # Build Movecraft-WorldGuard - - name: Build Movecraft-WorldGuard - run: mvn -B package -T 1C --file Movecraft-WorldGuard/pom.xml + - name: Publish to GitHub Packages + if: ${{ github.event_name == 'release' }} + run: ./gradlew publish --parallel env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Build AP-Turrets - run: cd AP-Turrets && ./gradlew clean build - - - name: Stage jar - run: mkdir staging && cp AP-Turrets/build/libs/AP-Turrets.jar staging && mv staging/AP-Turrets.jar staging/AP-Turrets_$GITHUB_SHA.jar - - name: Upload jar + - name: Stage jar for Actions + if: ${{ github.event_name != 'release' }} + run: mkdir staging && cp build/libs/AP-Turrets.jar staging && mv staging/AP-Turrets.jar staging/AP-Turrets_$GITHUB_SHA.jar + - name: Upload jar to Actions + if: ${{ github.event_name != 'release' }} uses: actions/upload-artifact@v4 with: name: AP-Turrets_Dev-Build path: staging/AP-Turrets_*.jar + + - name: Stage jar for Release + if: ${{ github.event_name == 'release' }} + run: mkdir staging && cp build/libs/AP-Turrets.jar staging && mv staging/AP-Turrets.jar staging/AP-Turrets_${{ github.event.release.tag_name }}.jar + - name: Upload jar to Release + if: ${{ github.event_name == 'release' }} + uses: softprops/action-gh-release@v2 + with: + files: staging/AP-Turrets_${{ github.event.release.tag_name }}.jar diff --git a/build.gradle.kts b/build.gradle.kts index 68aab05..f4cae61 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,43 +8,27 @@ plugins { repositories { gradlePluginPortal() mavenLocal() - githubPackage("apdevteam/movecraft") - maven { - url = uri("https://repo.maven.apache.org/maven2/") - } - maven { - url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") - } - maven { - url = uri("https://oss.sonatype.org/content/repositories/snapshots") - } - maven { - url = uri("https://maven.enginehub.org/repo/") - } - maven { - url = uri("https://jitpack.io") - } + mavenCentral() + maven("https://repo.papermc.io/repository/maven-public/") + maven { githubPackage("apdevteam/movecraft")(this) } + maven { githubPackage("apdevteam/movecraft-worldguard")(this) } + maven("https://jitpack.io") } dependencies { api("org.jetbrains:annotations-java5:24.1.0") paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") compileOnly("net.countercraft:movecraft:+") - compileOnly(files("../Movecraft-WorldGuard/target/Movecraft-WorldGuard.jar")) + compileOnly("net.countercraft.movecraft.worldguard:movecraft-worldguard:+") compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.7") compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") } -group = "snowleapord.github.com" -version = "3.0.0_beta-2" +group = "com.snowleopard" +version = "3.0.0_beta-2_gradle" description = "APTurrets" - java.toolchain.languageVersion = JavaLanguageVersion.of(17) -tasks.assemble { - dependsOn(tasks.reobfJar) -} - tasks.reobfJar { outputJar = layout.buildDirectory.file("libs/AP-Turrets.jar") } @@ -55,3 +39,25 @@ tasks.processResources { expand(mapOf("projectVersion" to project.version)) } } + +publishing { + publications { + create("maven") { + groupId = "com.snowleopard" + artifactId = "ap-turrets" + version = "${project.version}" + + artifact(tasks.reobfJar) + } + } + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/apdevteam/ap-turrets") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } +}