Skip to content

Commit 12d31e0

Browse files
authored
Add build and release workflow
1 parent c2f764a commit 12d31e0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and Release Mod
2+
3+
# 触发条件
4+
on:
5+
push:
6+
branches: [ "main", "master" ] # 推送到主分支时触发日常构建
7+
tags: [ "v*" ] # 推送 v 开头的 tag 时触发自动发布 (例如 v1.0.0)
8+
pull_request:
9+
branches: [ "main", "master" ] # 收到 PR 时也会触发编译检查
10+
11+
# 权限设置:允许机器人自动创建 Release
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
build:
17+
name: Build and Deploy
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
# 1. 拉取代码
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
# 2. 设置 JDK 环境
26+
# ⚠️ 注意:Minecraft 1.20.5 及以上要求 Java 21,1.18~1.20.4 是 Java 17
27+
- name: Set up JDK 21
28+
uses: actions/setup-java@v4
29+
with:
30+
java-version: '21'
31+
distribution: 'temurin'
32+
33+
# 3. 设置 Gradle 缓存 (大幅加快后续编译速度)
34+
- name: Setup Gradle
35+
uses: gradle/actions/setup-gradle@v3
36+
37+
# 4. 赋予 gradlew 执行权限 (防止 Windows 提交的代码在 Linux 上没有运行权限)
38+
- name: Make gradlew executable
39+
run: chmod +x ./gradlew
40+
41+
# 5. 执行编译
42+
- name: Build with Gradle
43+
run: ./gradlew build
44+
45+
# 6. 上传 Artifact (日常构建也能下载打包好的 jar 测试)
46+
- name: Upload Build Artifacts
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: mod-artifacts
50+
path: build/libs/*.jar # 收集 build/libs 目录下的所有 jar 包
51+
52+
# 7. 自动创建 GitHub Release (仅在打 tag 时执行)
53+
- name: Create GitHub Release
54+
uses: softprops/action-gh-release@v2
55+
if: startsWith(github.ref, 'refs/tags/v')
56+
with:
57+
files: build/libs/*.jar # 把编译出来的 jar 包附加到 Release 中
58+
generate_release_notes: true # 自动根据提交记录生成更新日志
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)