Skip to content

Commit 4301003

Browse files
committed
feat: github action builder
1 parent bb7d21c commit 4301003

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Publish Fabric Builds
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish-fabric:
9+
name: Publish Fabric Builds
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
14+
PROJECT_ID: A0VZd1kW
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # 获取所有分支
21+
22+
- name: Set up Java
23+
uses: actions/setup-java@v4
24+
with:
25+
java-version: 21
26+
distribution: temurin
27+
cache: gradle
28+
29+
- name: Cache Gradle
30+
uses: actions/cache@v3
31+
with:
32+
path: |
33+
~/.gradle/caches
34+
~/.gradle/wrapper
35+
key: gradle-${{ runner.os }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
36+
restore-keys: gradle-${{ runner.os }}-
37+
38+
- name: List Fabric branches
39+
id: list_branches
40+
run: |
41+
readarray -t branches <<< "$(git ls-remote --heads origin 'Fabric-*' | awk '{print $2}' | sed 's|refs/heads/||')"
42+
echo "branches=${branches[*]}" >> $GITHUB_OUTPUT
43+
44+
- name: Build and publish each Fabric branch
45+
run: |
46+
set -e
47+
IFS=' ' read -r -a branches <<< "${{ steps.list_branches.outputs.branches }}"
48+
for branch in "${branches[@]}"; do
49+
echo "=== Processing $branch ==="
50+
git checkout "$branch"
51+
52+
# 构建并获取 artifact
53+
if [ -f pom.xml ]; then
54+
mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false
55+
mvn -B clean package --file pom.xml
56+
artifact=$(ls target/*.jar | head -n1)
57+
elif [ -f build.gradle ] || [ -f build.gradle.kts ]; then
58+
chmod +x ./gradlew
59+
./gradlew clean build
60+
artifact=$(ls build/libs/*.jar | head -n1)
61+
else
62+
echo "No recognized build file found in $branch"
63+
continue
64+
fi
65+
66+
echo "Built artifact: $artifact"
67+
68+
# 解析文件名得到 version(去掉 .jar)
69+
filename=$(basename "$artifact")
70+
version="${filename%.jar}"
71+
echo "Version: $version"
72+
73+
# 根据 Fabric 版本生成 JSON 数组形式 game-versions
74+
fabric_ver=$(echo "$version" | sed 's/^Fabric-//')
75+
case "$fabric_ver" in
76+
1.16.5) game_versions='["1.16.x"]';;
77+
1.17.1) game_versions='["1.17.x"]';;
78+
1.18.2) game_versions='["1.18.x"]';;
79+
1.19.4) game_versions='["1.19.x"]';;
80+
1.20.1) game_versions='["1.20.1","1.20.2","1.20.3","1.20.4","1.20.5"]';;
81+
1.20.6) game_versions='["1.20.6"]';;
82+
1.21.1) game_versions='["1.21.1","1.21.2","1.21.3"]';;
83+
1.21.4) game_versions='["1.21.4","1.21.5"]';;
84+
1.21.6) game_versions='["1.21.6","1.21.7","1.21.8","1.21.9"]';;
85+
1.21.10) game_versions='["1.21.10"]';;
86+
*) echo "Unknown Fabric version: $fabric_ver"; continue;;
87+
esac
88+
echo "Game versions: $game_versions"
89+
90+
# 上传到 GitHub Release
91+
gh release upload ${{ github.event.release.tag_name }} "$artifact" --clobber
92+
93+
# 上传到 Modrinth
94+
if [ -n "$MODRINTH_TOKEN" ]; then
95+
echo "Uploading to Modrinth..."
96+
# 使用 cloudnode-pro/modrinth-publish@v2 Action
97+
gh workflow run cloudnode-pro/modrinth-publish@v2 \
98+
--inputs "token=$MODRINTH_TOKEN,project=$PROJECT_ID,name=${{ github.event.release.name }},version=$version,game-versions=$game_versions,loaders=['Fabric'],files=$artifact,changelog=${{ github.event.release.body }}"
99+
fi
100+
done

0 commit comments

Comments
 (0)