diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..056cecb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: Auto Build + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup JDK 8 + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'zulu' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Build with Gradle + run: ./gradlew shadowJar --no-daemon + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: Mcpatch-build-${{ github.sha }} + path: build/libs/*.jar + retention-days: 7 \ No newline at end of file diff --git a/.github/workflows/manual-release.yml b/.github/workflows/manual-release.yml new file mode 100644 index 0000000..7b8b246 --- /dev/null +++ b/.github/workflows/manual-release.yml @@ -0,0 +1,105 @@ +name: Manual Release + +on: + workflow_dispatch: + inputs: + version: + description: 'Release version (e.g., 1.0.0)' + required: true + type: string + prerelease: + description: 'Is this a pre-release?' + required: false + default: false + type: boolean + draft: + description: 'Create as draft?' + required: false + default: false + type: boolean + +jobs: + build-and-release: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup JDK 8 + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'zulu' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Build with Gradle + run: ./gradlew shadowJar --no-daemon + + - name: Get commit SHA + id: commit + run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Create Git tag + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "v${{ inputs.version }}" -m "Release v${{ inputs.version }}" + git push origin "v${{ inputs.version }}" + + - name: Generate changelog + id: changelog + run: | + # 获取上一个 tag + PREV_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") + + if [ -z "$PREV_TAG" ]; then + # 如果没有上一个 tag,获取所有提交 + CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges -20) + else + # 获取两个 tag 之间的提交 + CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges $PREV_TAG..HEAD) + fi + + # 保存到文件(多行内容) + echo "changelog<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + tag_name: v${{ inputs.version }} + name: Mcpatch v${{ inputs.version }} + body: | + ## Mcpatch v${{ inputs.version }} + + **构建信息:** + - 版本: ${{ inputs.version }} + - 提交: ${{ steps.commit.outputs.sha }} + - 构建时间: ${{ github.event.head_commit.timestamp }} + + **更新内容:** + ${{ steps.changelog.outputs.changelog }} + + --- + + **使用方法:** + 下载 `Mcpatch-${{ inputs.version }}.jar` 文件,按照项目说明进行部署。 + files: build/libs/*.jar + draft: ${{ inputs.draft }} + prerelease: ${{ inputs.prerelease }} + generate_release_notes: false + + - name: Upload release artifact + uses: actions/upload-artifact@v4 + with: + name: Mcpatch-v${{ inputs.version }} + path: build/libs/*.jar + retention-days: 30 \ No newline at end of file