feat: 更新上传到Modrinth,Curseforge平台的工作流程
This commit is contained in:
parent
9fff0c869a
commit
c45a7a9f0c
196
.github/workflows/buildAndRelease.yml
vendored
196
.github/workflows/buildAndRelease.yml
vendored
|
|
@ -83,7 +83,18 @@ jobs:
|
|||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Determine version type
|
||||
id: version_type
|
||||
run: |
|
||||
if [[ "${{ github.ref_name }}" == *"alpha"* ]]; then
|
||||
echo "type=alpha" >> $GITHUB_OUTPUT
|
||||
elif [[ "${{ github.ref_name }}" == *"beta"* ]]; then
|
||||
echo "type=beta" >> $GITHUB_OUTPUT
|
||||
elif [[ "${{ github.ref_name }}" == *"rc"* ]]; then
|
||||
echo "type=beta" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "type=release" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
|
|
@ -97,6 +108,69 @@ jobs:
|
|||
VERSION="${GITHUB_REF_NAME#v}"
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "minecraft_version=$(grep "^minecraft_version=" gradle.properties | cut -d'=' -f2)" >> $GITHUB_OUTPUT
|
||||
# 从 gradle.properties 提取 mod_id,如果没有则尝试从文件名推断
|
||||
MOD_ID=$(grep "^mod_id=" gradle.properties | cut -d'=' -f2 || echo "")
|
||||
if [ -z "$MOD_ID" ]; then
|
||||
# 尝试从现有的 jar 文件名提取 mod_id
|
||||
SAMPLE_JAR=$(ls dist/ | grep -m 1 -E ".*-(fabric|forge)-.*\.jar" || echo "")
|
||||
if [ -n "$SAMPLE_JAR" ]; then
|
||||
MOD_ID=$(echo "$SAMPLE_JAR" | sed -E 's/-(fabric|forge)-.*//')
|
||||
else
|
||||
MOD_ID="mymod" # 默认值,请根据实际情况修改
|
||||
fi
|
||||
fi
|
||||
echo "mod_id=$MOD_ID" >> $GITHUB_OUTPUT
|
||||
|
||||
# 从 gradle.properties 提取 mod_name(用于显示)
|
||||
MOD_NAME=$(grep "^mod_name=" gradle.properties | cut -d'=' -f2 || echo "My Mod")
|
||||
echo "mod_name=$MOD_NAME" >> $GITHUB_OUTPUT
|
||||
# 从 gradle.properties 提取 modrinth_id
|
||||
MODRINTH_ID=$(grep "^modrinth_id=" gradle.properties | cut -d'=' -f2 || echo "")
|
||||
echo "modrinth_id=$MODRINTH_ID" >> $GITHUB_OUTPUT
|
||||
# 从 gradle.properties 提取 curseforge_id
|
||||
CURSEFORGE_ID=$(grep "^curseforge_id=" gradle.properties | cut -d'=' -f2 || echo "")
|
||||
echo "curseforge_id=$CURSEFORGE_ID" >> $GITHUB_OUTPUT
|
||||
|
||||
# Java版本 - 使用简单格式,不用JSON
|
||||
JAVA_VERSIONS=$(grep "^java_versions=" gradle.properties | cut -d'=' -f2- || echo "21,17")
|
||||
# 清理格式,移除无效字符
|
||||
JAVA_VERSIONS=$(echo "$JAVA_VERSIONS" | sed 's/\[//g; s/\]//g; s/"//g; s/ //g; s/21a/21/g' | tr -d '\r')
|
||||
echo "java_versions=$JAVA_VERSIONS" >> $GITHUB_OUTPUT
|
||||
|
||||
# 读取发布控制布尔值(默认都为 true)
|
||||
PUBLISH_GITHUB=$(grep "^publish_github=" gradle.properties | cut -d'=' -f2 | tr '[:upper:]' '[:lower:]' | tr -d ' ' || echo "true")
|
||||
if [ "$PUBLISH_GITHUB" = "true" ] || [ "$PUBLISH_GITHUB" = "1" ] || [ "$PUBLISH_GITHUB" = "yes" ]; then
|
||||
echo "publish_github=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "publish_github=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
PUBLISH_MODRINTH=$(grep "^publish_modrinth=" gradle.properties | cut -d'=' -f2 | tr '[:upper:]' '[:lower:]' | tr -d ' ' || echo "true")
|
||||
if [ "$PUBLISH_MODRINTH" = "true" ] || [ "$PUBLISH_MODRINTH" = "1" ] || [ "$PUBLISH_MODRINTH" = "yes" ]; then
|
||||
echo "publish_modrinth=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "publish_modrinth=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
PUBLISH_CURSEFORGE=$(grep "^publish_curseforge=" gradle.properties | cut -d'=' -f2 | tr '[:upper:]' '[:lower:]' | tr -d ' ' || echo "true")
|
||||
if [ "$PUBLISH_CURSEFORGE" = "true" ] || [ "$PUBLISH_CURSEFORGE" = "1" ] || [ "$PUBLISH_CURSEFORGE" = "yes" ]; then
|
||||
echo "publish_curseforge=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "publish_curseforge=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# 读取依赖配置 - 使用简单字符串,不用JSON
|
||||
FABRIC_MODRINTH_DEPS=$(grep "^fabric_modrinth_dependencies=" gradle.properties | cut -d'=' -f2- || echo "")
|
||||
echo "fabric_modrinth_dependencies=$FABRIC_MODRINTH_DEPS" >> $GITHUB_OUTPUT
|
||||
|
||||
FORGE_MODRINTH_DEPS=$(grep "^forge_modrinth_dependencies=" gradle.properties | cut -d'=' -f2- || echo "")
|
||||
echo "forge_modrinth_dependencies=$FORGE_MODRINTH_DEPS" >> $GITHUB_OUTPUT
|
||||
|
||||
FABRIC_CURSEFORGE_DEPS=$(grep "^fabric_curseforge_dependencies=" gradle.properties | cut -d'=' -f2- || echo "")
|
||||
echo "fabric_curseforge_dependencies=$FABRIC_CURSEFORGE_DEPS" >> $GITHUB_OUTPUT
|
||||
|
||||
FORGE_CURSEFORGE_DEPS=$(grep "^forge_curseforge_dependencies=" gradle.properties | cut -d'=' -f2- || echo "")
|
||||
echo "forge_curseforge_dependencies=$FORGE_CURSEFORGE_DEPS" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Generate CZ-compliant changelog
|
||||
id: generate_changelog
|
||||
|
|
@ -139,6 +213,7 @@ jobs:
|
|||
["👷 CI"]="^(ci)(\(.*\))?:"
|
||||
["📦 依赖"]="^(chore|deps)(\(.*\))?:"
|
||||
["⏪ 回退"]="^(revert)(\(.*\))?:"
|
||||
["🛠 合并"]="^Merge "
|
||||
)
|
||||
|
||||
# 获取所有提交
|
||||
|
|
@ -250,6 +325,7 @@ jobs:
|
|||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create Release
|
||||
if: steps.version_info.outputs.publish_github == 'true'
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifacts: |
|
||||
|
|
@ -258,7 +334,121 @@ jobs:
|
|||
name: "${{ steps.version_info.outputs.minecraft_version }} - ${{ github.ref_name }}"
|
||||
body: ${{ steps.generate_changelog.outputs.changelog }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
prerelease: ${{ contains(github.ref_name, 'rc') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
allowUpdates: true
|
||||
removeArtifacts: true
|
||||
removeArtifacts: true
|
||||
# Fabric 发布到 Modrinth 和 CurseForge
|
||||
- name: Publish Fabric to Modrinth & CurseForge
|
||||
uses: Kir-Antipov/mc-publish@v3.3
|
||||
if: success() && (steps.version_info.outputs.publish_modrinth == 'true' || steps.version_info.outputs.publish_curseforge == 'true')
|
||||
continue-on-error: true
|
||||
with:
|
||||
# 文件匹配规则 - 只匹配 fabric 的文件
|
||||
files: |
|
||||
dist/${{ steps.version_info.outputs.mod_id }}-fabric-${{ steps.version_info.outputs.minecraft_version }}-${{ steps.version_info.outputs.version }}.jar
|
||||
dist/${{ steps.version_info.outputs.mod_id }}-fabric-${{ steps.version_info.outputs.minecraft_version }}-${{ steps.version_info.outputs.version }}-javadoc.jar
|
||||
dist/${{ steps.version_info.outputs.mod_id }}-fabric-${{ steps.version_info.outputs.minecraft_version }}-${{ steps.version_info.outputs.version }}-sources.jar
|
||||
|
||||
# 版本信息
|
||||
name: ${{ steps.version_info.outputs.mod_name }} ${{ steps.version_info.outputs.version }} (Fabric/${{ steps.version_info.outputs.minecraft_version }})
|
||||
version: "${{ steps.version_info.outputs.minecraft_version }}-fabric-${{ steps.version_info.outputs.version }}"
|
||||
|
||||
# 更新日志
|
||||
changelog: ${{ steps.generate_changelog.outputs.changelog }}
|
||||
|
||||
# 版本类型
|
||||
version-type: ${{ steps.version_type.outputs.type }}
|
||||
|
||||
# 只指定 Fabric 加载器
|
||||
loaders: fabric
|
||||
|
||||
# 游戏版本
|
||||
game-versions: |
|
||||
${{ steps.version_info.outputs.minecraft_version }}
|
||||
|
||||
# Java版本
|
||||
java: |
|
||||
${{ steps.version_info.outputs.java_versions }}
|
||||
|
||||
# Modrinth 配置
|
||||
modrinth-id: ${{ steps.version_info.outputs.modrinth_id }}
|
||||
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
|
||||
modrinth-featured: true
|
||||
modrinth-unfeature-mode: any
|
||||
modrinth-dependencies: ${{ steps.version_info.outputs.fabric_modrinth_dependencies }}
|
||||
# CurseForge 配置
|
||||
curseforge-id: ${{ steps.version_info.outputs.curseforge_id }}
|
||||
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
|
||||
curseforge-dependencies: ${{ steps.version_info.outputs.fabric_curseforge_dependencies }}
|
||||
|
||||
# 失败处理
|
||||
fail-mode: skip
|
||||
|
||||
# Forge 发布到 Modrinth 和 CurseForge
|
||||
- name: Publish Forge to Modrinth & CurseForge
|
||||
uses: Kir-Antipov/mc-publish@v3.3
|
||||
if: success() && (steps.version_info.outputs.publish_modrinth == 'true' || steps.version_info.outputs.publish_curseforge == 'true')
|
||||
continue-on-error: true
|
||||
with:
|
||||
# 文件匹配规则 - 只匹配 forge 的文件
|
||||
files: |
|
||||
dist/${{ steps.version_info.outputs.mod_id }}-forge-${{ steps.version_info.outputs.minecraft_version }}-${{ steps.version_info.outputs.version }}.jar
|
||||
dist/${{ steps.version_info.outputs.mod_id }}-forge-${{ steps.version_info.outputs.minecraft_version }}-${{ steps.version_info.outputs.version }}-javadoc.jar
|
||||
dist/${{ steps.version_info.outputs.mod_id }}-forge-${{ steps.version_info.outputs.minecraft_version }}-${{ steps.version_info.outputs.version }}-sources.jar
|
||||
|
||||
# 版本信息
|
||||
name: ${{ steps.version_info.outputs.mod_name }} ${{ steps.version_info.outputs.version }} (Forge/${{ steps.version_info.outputs.minecraft_version }})
|
||||
version: "${{ steps.version_info.outputs.minecraft_version }}-forge-${{ steps.version_info.outputs.version }}"
|
||||
|
||||
# 更新日志
|
||||
changelog: ${{ steps.generate_changelog.outputs.changelog }}
|
||||
|
||||
# 版本类型
|
||||
version-type: ${{ steps.version_type.outputs.type }}
|
||||
|
||||
# 只指定 Forge 加载器
|
||||
loaders: forge
|
||||
|
||||
# 游戏版本
|
||||
game-versions: |
|
||||
${{ steps.version_info.outputs.minecraft_version }}
|
||||
|
||||
# Java版本
|
||||
java: |
|
||||
${{ steps.version_info.outputs.java_versions }}
|
||||
|
||||
# Modrinth 配置
|
||||
modrinth-id: ${{ steps.version_info.outputs.modrinth_id }}
|
||||
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
|
||||
modrinth-featured: true
|
||||
modrinth-unfeature-mode: any
|
||||
modrinth-dependencies: ${{ steps.version_info.outputs.forge_modrinth_dependencies }}
|
||||
|
||||
# CurseForge 配置
|
||||
curseforge-id: ${{ steps.version_info.outputs.curseforge_id }}
|
||||
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
|
||||
curseforge-dependencies: ${{ steps.version_info.outputs.forge_curseforge_dependencies }}
|
||||
|
||||
# 失败处理
|
||||
fail-mode: skip
|
||||
|
||||
# 发布完成后列出结果
|
||||
- name: Summary
|
||||
if: always()
|
||||
run: |
|
||||
echo "## 发布结果摘要" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "### GitHub Release" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 标签: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- URL: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "### Modrinth" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 项目ID: ${{ steps.version_info.outputs.modrinth_id }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Fabric版本: ${{ steps.version_info.outputs.version }}-fabric" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Forge版本: ${{ steps.version_info.outputs.version }}-forge" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "### CurseForge" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- 项目ID: ${{ steps.version_info.outputs.curseforge_id }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Fabric版本: ${{ steps.version_info.outputs.version }}-fabric" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Forge版本: ${{ steps.version_info.outputs.version }}-forge" >> $GITHUB_STEP_SUMMARY
|
||||
|
|
@ -31,3 +31,18 @@ forge_loader_version_range=[47,)
|
|||
# Gradle
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
# Release
|
||||
publish_github=true
|
||||
publish_modrinth=false
|
||||
publish_curseforge=false
|
||||
|
||||
modrinth_id=
|
||||
curseforge_id=
|
||||
|
||||
java_versions=
|
||||
|
||||
fabric_modrinth_dependencies=
|
||||
forge_modrinth_dependencies=
|
||||
fabric_curseforge_dependencies=
|
||||
forge_curseforge_dependencies=
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user