From 1f5da4b1d3cc480152d55b6ba3216e3f9ccf1ff3 Mon Sep 17 00:00:00 2001 From: Ally Mitchell Date: Tue, 9 Jul 2024 18:54:05 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Add=20maven=20publishing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yaml | 48 ++++++++++++++++++++++++++++++++++ build.gradle | 27 +++++++++++++++++++ gradle.properties | 6 ++++- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..a0f252f --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,48 @@ +name: Publish with Gradle + +on: + push: + branches: [ '1.20.1' ] + +env: + CACHE_REV: "1" + +jobs: + publish: + runs-on: ubuntu-22.04 + env: + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + ${{ github.workspace}}/build/ + ${{ github.workspace}}/.gradle/ + key: "${{ runner.os }}-build-${{ env.CACHE_REV }}-${{ hashFiles('**/*.gradle*') }}" + restore-keys: | + ${{ runner.os }}-build-${{ env.CACHE_REV }}- + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Setup workspace + run: | + echo "GIT_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV + echo "GIT_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV + - name: Publish Snapshot + if: ${{ github.ref_name == 'develop' }} + run: | + chmod +x ./gradlew && ./gradlew "-PpistonVersion=${{ steps.calver.outputs.release }}-SNAPSHOT" "-Pmaven.auth.username=${MAVEN_USERNAME}" "-Pmaven.auth.password=${MAVEN_PASSWORD}" publish --stacktrace + - name: Publish Release + if: ${{ github.ref_name == 'production' }} + run: | + chmod +x ./gradlew && ./gradlew "-Pmaven.auth.username=${{ secrets.MAVEN_USERNAME }}" "-Pmaven.auth.password=${{ secrets.MAVEN_PASSWORD }}" publish --stacktrace \ No newline at end of file diff --git a/build.gradle b/build.gradle index 43ebd66..109e890 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ plugins { id 'net.neoforged.gradle' version '[6.0.18,6.2)' id 'org.spongepowered.mixin' version '0.7.+' id 'org.parchmentmc.librarian.forgegradle' version '1.+' + id 'maven-publish' } group = 'cn.leomc' @@ -173,4 +174,30 @@ jar.finalizedBy('reobfJar') tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation +} + +publishing { + publications { + register("maven", MavenPublication) { + from components.java + } + } + + repositories { + maven { + url = uri("${getVariable("maven.repo.url")}") + credentials { + username = getVariable("maven.auth.username") + password = getVariable("maven.auth.password") + } + } + } +} + +String getVariable(String variable) { + if(project.ext.get(variable) != null) { + return project.ext.get(variable) + } else { + return property(variable) + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 67bb9cb..a1755ab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,8 @@ org.gradle.daemon=false mc_version=1.20.1 -forge_version=47.1.79 \ No newline at end of file +forge_version=47.1.79 + +maven.repo.url=https://repo.modrealms.net/repository/maven-releases +maven.auth.username= +maven.auth.password= \ No newline at end of file