This repository was archived by the owner on Aug 30, 2026. It is now read-only.
发布 #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| REAL_JAVA_HOME="$JAVA_HOME" | |
| CI_JDK="$RUNNER_TEMP/jdk17-ignore" | |
| mkdir -p "$CI_JDK/bin" | |
| cp "$REAL_JAVA_HOME/release" "$CI_JDK/release" | |
| printf '#!/usr/bin/env sh\nexec "%s/bin/java" -XX:+IgnoreUnrecognizedVMOptions "$@"\n' "$REAL_JAVA_HOME" > "$CI_JDK/bin/java" | |
| printf '#!/usr/bin/env sh\nexec "%s/bin/javac" "$@"\n' "$REAL_JAVA_HOME" > "$CI_JDK/bin/javac" | |
| printf '#!/usr/bin/env sh\nexec "%s/bin/javadoc" "$@"\n' "$REAL_JAVA_HOME" > "$CI_JDK/bin/javadoc" | |
| chmod +x "$CI_JDK/bin/java" "$CI_JDK/bin/javac" "$CI_JDK/bin/javadoc" | |
| echo "$CI_JDK/bin" >> "$GITHUB_PATH" | |
| echo "JAVA_HOME=$CI_JDK" >> "$GITHUB_ENV" | |
| echo "CI_JDK=$CI_JDK" >> "$GITHUB_ENV" | |
| echo "JAVA_TOOL_OPTIONS=-XX:+IgnoreUnrecognizedVMOptions" >> "$GITHUB_ENV" | |
| - name: 修补 RFG 反编译 JVM 参数 | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| ./gradlew --no-daemon --stacktrace -Dorg.gradle.java.home="$CI_JDK" -Dorg.gradle.java.installations.paths="$CI_JDK" help | |
| RFG_JAR="$(find "$GRADLE_USER_HOME/caches/modules-2/files-2.1/com.gtnewhorizons/retrofuturagradle/1.4.9" -name 'retrofuturagradle-1.4.9.jar' -print -quit)" | |
| if [[ -z "$RFG_JAR" ]]; then | |
| echo "::error::未找到 RetroFuturaGradle 插件 jar" | |
| exit 1 | |
| fi | |
| PATCH_DIR="$RUNNER_TEMP/rfg-patch" | |
| rm -rf "$PATCH_DIR" | |
| mkdir -p "$PATCH_DIR" | |
| cd "$PATCH_DIR" | |
| jar xf "$RFG_JAR" com/gtnewhorizons/retrofuturagradle/mcp/DecompileTask.class | |
| node -e 'const fs = require("fs"); const path = "com/gtnewhorizons/retrofuturagradle/mcp/DecompileTask.class"; const oldValue = Buffer.from("-XX:+AggressiveOpts"); const newValue = Buffer.from("-XX:+AlwaysPreTouch"); let data = fs.readFileSync(path); const oldIndex = data.indexOf(oldValue); if (oldIndex >= 0) { newValue.copy(data, oldIndex); fs.writeFileSync(path, data); console.log("Patched RFG DecompileTask JVM argument."); process.exit(0); } if (data.indexOf(newValue) >= 0) { console.log("RFG DecompileTask JVM argument is already patched."); process.exit(0); } throw new Error("RFG DecompileTask contains neither -XX:+AggressiveOpts nor -XX:+AlwaysPreTouch");' | |
| jar uf "$RFG_JAR" com/gtnewhorizons/retrofuturagradle/mcp/DecompileTask.class | |
| - name: 清理 RFG 反编译缓存 | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| rm -rf "$GRADLE_USER_HOME/caches/retro_futura_gradle" | |
| - 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 | |
| run: | | |
| set -euo pipefail | |
| chmod +x gradlew | |
| echo "JAVA_HOME=$JAVA_HOME" | |
| echo "CI_JDK=$CI_JDK" | |
| echo "JAVA_TOOL_OPTIONS=${JAVA_TOOL_OPTIONS:-}" | |
| java -version | |
| ./gradlew --no-daemon --stacktrace -Dorg.gradle.java.home="$CI_JDK" -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: 创建标签 | |
| 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: Action构建。 | |
| draft: ${{ inputs.draft }} | |
| prerelease: ${{ inputs.prerelease }} | |
| files: | | |
| ${{ steps.artifacts.outputs.mod_jar }} | |
| fail_on_unmatched_files: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |