Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

发布

发布 #2

Workflow file for this run

name: 发布
on:
workflow_dispatch:
inputs:
prerelease:
description: "标记为预发布"
type: boolean
default: false
draft:
description: "创建为草稿"
type: boolean
default: false
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
name: 构建并发布
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 设置 JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- name: 设置 Gradle
uses: gradle/actions/setup-gradle@v4
- name: 准备 RFG JDK 17 兼容包装器
shell: bash
run: |
set -euo pipefail
CI_JDK="$RUNNER_TEMP/jdk17-ignore"
mkdir -p "$CI_JDK/bin"
cp "$JAVA_HOME/release" "$CI_JDK/release"
printf '#!/usr/bin/env sh\nexec "%s/bin/java" -XX:+IgnoreUnrecognizedVMOptions "$@"\n' "$JAVA_HOME" > "$CI_JDK/bin/java"
printf '#!/usr/bin/env sh\nexec "%s/bin/javac" "$@"\n' "$JAVA_HOME" > "$CI_JDK/bin/javac"
printf '#!/usr/bin/env sh\nexec "%s/bin/javadoc" "$@"\n' "$JAVA_HOME" > "$CI_JDK/bin/javadoc"
chmod +x "$CI_JDK/bin/java" "$CI_JDK/bin/javac" "$CI_JDK/bin/javadoc"
echo "CI_JDK=$CI_JDK" >> "$GITHUB_ENV"
- name: 读取版本号
id: version
shell: bash
run: |
set -euo pipefail
VERSION="$(grep -E '^version=' gradle.properties | cut -d= -f2- | tr -d '[:space:]')"
if [[ -z "$VERSION" ]]; then
echo "::error::无法从 gradle.properties 读取版本号"
exit 1
fi
TAG="$VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "解析版本号: $VERSION(标签: $TAG)"
- name: 检查标签是否已存在
shell: bash
run: |
set -euo pipefail
TAG="${{ steps.version.outputs.tag }}"
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "::error::标签 '$TAG' 已存在,请先在 gradle.properties 中更新版本号"
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then
echo "::error::标签 '$TAG' 在远程仓库中已存在,请先在 gradle.properties 中更新版本号"
exit 1
fi
- name: 构建 Forge 1.12.2 Mod
shell: bash
env:
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx3g -Dfile.encoding=UTF-8"
run: |
set -euo pipefail
chmod +x gradlew
echo "JAVA_HOME=$JAVA_HOME"
echo "CI_JDK=$CI_JDK"
java -version
./gradlew --no-daemon --stacktrace -Dorg.gradle.java.installations.paths="$CI_JDK" reobfJar
- name: 查找构建产物
id: artifacts
shell: bash
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.version }}"
MOD_JAR="build/libs/AccountsX-${VERSION}.jar"
if [[ ! -f "$MOD_JAR" ]]; then
echo "::error::未找到期望的构建产物: $MOD_JAR"
echo "可用的 jar 文件:"
find build/libs -type f -name '*.jar' -print || true
exit 1
fi
echo "mod_jar=$MOD_JAR" >> "$GITHUB_OUTPUT"
ls -lh "$MOD_JAR"
- name: 生成更新日志
id: changelog
shell: bash
run: |
set -euo pipefail
TAG="${{ steps.version.outputs.tag }}"
PREV_TAG="$(git describe --tags --abbrev=0 2>/dev/null || true)"
{
echo "## 更新内容"
echo
if [[ -n "$PREV_TAG" ]]; then
echo "自 \`$PREV_TAG\` 以来的变更:"
echo
RANGE="${PREV_TAG}..HEAD"
else
echo "初始版本发布说明:"
echo
RANGE="HEAD"
fi
mapfile -t COMMITS < <(git log $RANGE --pretty=format:'%s|%h' --no-merges)
if [[ ${#COMMITS[@]} -eq 0 || -z "${COMMITS[0]:-}" ]]; then
echo "_此版本无提交记录。_"
else
declare -A SECTIONS
SECTIONS[feat]="### 新功能"
SECTIONS[fix]="### Bug 修复"
SECTIONS[refactor]="### 重构"
SECTIONS[perf]="### 性能优化"
SECTIONS[docs]="### 文档"
SECTIONS[chore]="### 杂项"
SECTIONS[other]="### 其他变更"
declare -A BUCKETS
for key in feat fix refactor perf docs chore other; do
BUCKETS[$key]=""
done
for line in "${COMMITS[@]}"; do
subject="${line%%|*}"
hash="${line##*|}"
if [[ "$subject" =~ ^(feat|fix|refactor|perf|docs|chore|ver|update)(\([^)]+\))?(!)?:[[:space:]]*(.+)$ ]]; then
type="${BASH_REMATCH[1]}"
body="${BASH_REMATCH[4]}"
case "$type" in
ver|update) type="chore" ;;
esac
BUCKETS[$type]+="- ${body}(\`${hash}\`)"$'\n'
else
BUCKETS[other]+="- ${subject}(\`${hash}\`)"$'\n'
fi
done
for key in feat fix refactor perf docs chore other; do
if [[ -n "${BUCKETS[$key]}" ]]; then
echo "${SECTIONS[$key]}"
echo
printf '%s' "${BUCKETS[$key]}"
echo
fi
done
fi
echo
echo "**完整变更日志**: https://github.com/${{ github.repository }}/compare/${PREV_TAG:-$(git rev-list --max-parents=0 HEAD)}...${TAG}"
} > release_notes.md
echo "----- 更新日志 -----"
cat release_notes.md
- name: 创建标签
shell: bash
run: |
set -euo pipefail
TAG="${{ steps.version.outputs.tag }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "发布 $TAG"
git push origin "refs/tags/$TAG"
- name: 创建 GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: AccountsX ${{ steps.version.outputs.version }}
body_path: release_notes.md
draft: ${{ inputs.draft }}
prerelease: ${{ inputs.prerelease }}
files: |
${{ steps.artifacts.outputs.mod_jar }}
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}