From 1ba7de75cb083cf8db98b7dd4f208d88333cd93d Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Wed, 11 Sep 2024 14:12:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=20hangar=20=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 57 ++++++++++++++++++++++++++------------ build.gradle.kts | 31 ++++++++++++++++++++- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2e425be2..f2813780 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,9 +7,10 @@ on: jobs: build: - # 配置权限 permissions: write-all runs-on: ubuntu-latest + outputs: + release_tag: ${{ steps.set_tag.outputs.tag }} steps: - uses: actions/checkout@v3 - name: "Set up JDK 21" @@ -20,35 +21,57 @@ jobs: cache: gradle - name: "Build with Gradle" run: ./gradlew buildPlugin - - name: "Copy jar to staging" + - name: "Prepare release artifacts" run: | - mkdir staging && cp build/libs/*.jar staging/ - - name: "Build & test" - run: | - TAG=$(echo $GITHUB_REF | sed 's/refs\/tags\///') - echo "done!" + mkdir -p staging + cp build/libs/*.jar staging/ + - name: "Set release tag" + id: set_tag + run: echo "tag=${GITHUB_REF_NAME}" >> $GITHUB_ENV + + github-release: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 - name: "GitHub Release" - uses: "marvinpinto/action-automatic-releases@latest" + uses: marvinpinto/action-automatic-releases@latest with: repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "${{ steps.build.outputs.TAG }}" + automatic_release_tag: "${{ needs.build.outputs.release_tag }}" prerelease: false files: | - staging/*.jar + build/libs/*.jar + + modrinth-release: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 - name: "Modrinth Release" uses: dsx137/modrinth-release-action@main env: MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} with: - name: ${{ env.AUTOMATIC_RELEASES_TAG }} + name: ${{ needs.build.outputs.release_tag }} project_id: vVZc7jAV loaders: bukkit,folia,paper,purpur,spigot game_versions: 1.20.1:1.20.6,1.21,1.21.1 - version_number: ${{ env.AUTOMATIC_RELEASES_TAG }} + version_number: ${{ needs.build.outputs.release_tag }} files: | - staging/*.jar - changelog: "See https://github.com/ColdeZhang/Dominion/releases/tag/${{ env.AUTOMATIC_RELEASES_TAG }}" - version_type: beta # or beta, alpha + build/libs/*.jar + changelog: "See https://github.com/ColdeZhang/Dominion/releases/tag/${{ needs.build.outputs.release_tag }}" + version_type: beta featured: false - updatable: false # default true, means updating existing version - delete_old_files: false # default true + updatable: false + delete_old_files: false + + hangar-release: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: "Hangar Release" + env: + HANGAR_TOKEN: ${{ secrets.HANGAR_API_TOKEN }} + run: ./gradlew publishPluginPublicationToHangar --stacktrace diff --git a/build.gradle.kts b/build.gradle.kts index 04e77c45..7ec8d96e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,13 @@ +import io.papermc.hangarpublishplugin.model.Platforms + plugins { id("java") id("com.github.johnrengelman.shadow") version "8.1.1" + id("io.papermc.hangar-publish-plugin") version "0.1.2" } group = "cn.lunadeer" -version = "2.6.9-beta" +version = "2.6.10-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) @@ -41,6 +44,10 @@ allprojects { tasks.processResources { outputs.upToDateWhen { false } + // copy languages folder from PROJECT_DIR/languages to core/src/main/resources + from(file("${projectDir}/languages")) { + into("languages") + } // replace @version@ in plugin.yml with project version filesMatching("**/plugin.yml") { filter { @@ -70,4 +77,26 @@ tasks.shadowJar { tasks.register("buildPlugin") { // <<<< RUN THIS TASK TO BUILD PLUGIN dependsOn(tasks.clean) dependsOn(tasks.shadowJar) +} + +hangarPublish { + publications.register("plugin") { + version.set(project.version as String) // use project version as publication version + id.set("Dominion") + channel.set("Beta") + changelog.set("See https://github.com/ColdeZhang/Dominion/releases/tag/v${project.version}") + apiKey.set(System.getenv("HANGAR_TOKEN")) + // register platforms + platforms { + register(Platforms.PAPER) { + jar.set(tasks.shadowJar.flatMap { it.archiveFile }) + println("ShadowJar: ${tasks.shadowJar.flatMap { it.archiveFile }}") + platformVersions.set(listOf("1.20.1-1.20.6","1.21.x")) + } + } + } +} + +tasks.named("publishPluginPublicationToHangar") { + dependsOn(tasks.named("jar")) } \ No newline at end of file