From 3cd76bcbba182f7744b17947f164d339465e283a Mon Sep 17 00:00:00 2001 From: Ap_Tx <3045929398@qq.com> Date: Sat, 3 Oct 2026 15:49:31 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=96=B0=E5=A2=9E=20GitHub=20Actions=20?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=B8=8E=E5=8F=91=E5=B8=83=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit build.yml:push/PR 到 main 及手动触发时编译,产物上传 artifact。release.yml:push v* tag 或手动触发时构建并发 GitHub Release,版本号从 tag 推导(v0.1 → 0.1),用 -Pmod_version 覆盖。均用 JDK 25(temurin),直接 ./gradlew,不依赖额外 action。 --- .github/workflows/build.yml | 34 +++++++++++++++++++++ .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c76e381 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 25 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '25' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build --stacktrace + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: mod-jar + path: build/libs/*.jar + if-no-files-found: error \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..95cf365 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Release + +on: + push: + tags: + - 'v*' + workflow_dispatch: + inputs: + tag: + description: '要发布的 tag 名(如 v0.1)' + required: true + type: string + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 25 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '25' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Resolve version from tag + id: ver + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + TAG="${{ inputs.tag }}" + else + TAG="${GITHUB_REF_NAME}" + fi + VERSION="${TAG#v}" + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Build with Gradle + run: ./gradlew build -Pmod_version=${{ steps.ver.outputs.version }} --stacktrace + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.ver.outputs.tag }} + name: ${{ steps.ver.outputs.tag }} + generate_release_notes: true + files: build/libs/*.jar + draft: false + prerelease: false \ No newline at end of file