Fix compilation error in CLIManager.java by adding getLogRetentionDay… #447
Workflow file for this run
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: CI-Build & Release | |
| #!!!不要把FancyHelper改成fancyhelper | |
| on: | |
| push: | |
| tags: [ 'v*' ] | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ master ] | |
| workflow_dispatch: | |
| inputs: | |
| build_type: | |
| description: '构建类型(snapshot-快照包/release-正式包)' | |
| required: true | |
| default: 'snapshot' | |
| type: choice | |
| options: | |
| - snapshot | |
| - release | |
| custom_version: | |
| description: '自定义版本号(仅release类型生效,无需带v前缀)' | |
| required: false | |
| type: string | |
| skip_checks: | |
| description: '跳过检查(仅用于紧急发布)' | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| # ==================== 单元测试 ==================== | |
| test: | |
| name: 单元测试 (Java ${{ matrix.java }}) | |
| runs-on: ubuntu-latest | |
| if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.skip_checks) }} | |
| strategy: | |
| matrix: | |
| java: [ 17, 21 ] | |
| fail-fast: false | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-java@v4 | |
| with: | |
| java-version: ${{ matrix.java }} | |
| distribution: temurin | |
| cache: maven | |
| - name: 运行单元测试 | |
| run: mvn -B test | |
| - name: 上传测试报告 | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-report-java${{ matrix.java }} | |
| path: target/surefire-reports/ | |
| # ==================== 构建和发布 ==================== | |
| build: | |
| name: 构建 | |
| runs-on: ubuntu-latest | |
| needs: [ test ] | |
| if: | | |
| always() && | |
| (needs.test.result == 'success' || needs.test.result == 'skipped') | |
| outputs: | |
| IS_RELEASE: ${{ steps.check_release.outputs.IS_RELEASE }} | |
| RELEASE_VERSION: ${{ steps.check_release.outputs.RELEASE_VERSION }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine Release Type | |
| id: check_release | |
| run: | | |
| git fetch origin master --tags | |
| IS_RELEASE=false | |
| RELEASE_VERSION="" | |
| SHORT_SHA="${GITHUB_SHA::7}" | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.build_type }}" == "release" ]]; then | |
| IS_RELEASE=true | |
| if [[ -n "${{ inputs.custom_version }}" ]]; then | |
| RELEASE_VERSION="${{ inputs.custom_version }}" | |
| else | |
| RELEASE_VERSION="$SHORT_SHA" | |
| fi | |
| elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| if git branch -r --contains ${{ github.sha }} | grep -q 'origin/master'; then | |
| IS_RELEASE=true | |
| RELEASE_VERSION=${GITHUB_REF_NAME#v} | |
| fi | |
| elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then | |
| TAG=$(git tag --points-at HEAD | grep '^v' | head -n 1) | |
| if [[ -n "$TAG" ]]; then | |
| IS_RELEASE=true | |
| RELEASE_VERSION=${TAG#v} | |
| fi | |
| fi | |
| echo "IS_RELEASE=$IS_RELEASE" >> $GITHUB_OUTPUT | |
| echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT | |
| - uses: actions/setup-java@v4 | |
| with: | |
| java-version: 17 | |
| distribution: temurin | |
| cache: maven | |
| - name: 生成短 SHA | |
| id: sha | |
| run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| - name: 版本设置与构建打包 | |
| run: | | |
| # 统一处理版本设置逻辑,解决原先多个 if 步骤导致的混乱 | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| if [[ "${{ inputs.build_type }}" == "release" ]]; then | |
| VERSION="${{ inputs.custom_version }}" | |
| [[ -z "$VERSION" ]] && VERSION="${{ steps.sha.outputs.SHORT_SHA }}" | |
| SKIP_TESTS="-DskipTests" | |
| else | |
| VERSION="#${{ steps.sha.outputs.SHORT_SHA }}" | |
| SKIP_TESTS="" | |
| fi | |
| elif [[ "${{ steps.check_release.outputs.IS_RELEASE }}" == "true" ]]; then | |
| VERSION="${{ steps.check_release.outputs.RELEASE_VERSION }}" | |
| SKIP_TESTS="-DskipTests" | |
| else | |
| VERSION="#${{ steps.sha.outputs.SHORT_SHA }}" | |
| SKIP_TESTS="" | |
| fi | |
| mvn -B versions:set -DnewVersion="$VERSION" -DgenerateBackupPoms=false | |
| mvn -B package $SKIP_TESTS | |
| - name: 上传构建产物 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: FancyHelper-build-${{ github.run_id }} | |
| path: target/FancyHelper-*.jar | |
| # ==================== AI 生成发行注记 ==================== | |
| generate-overview: | |
| name: AI 生成发行注记 | |
| runs-on: ubuntu-latest | |
| needs: [ build ] | |
| if: needs.build.outputs.IS_RELEASE == 'true' | |
| outputs: | |
| release_body_path: ${{ steps.compose_body.outputs.BODY_PATH }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: 调用 Cloudflare AI 生成内容 | |
| id: ai_gen | |
| env: | |
| CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }} | |
| CLOUDFLARE_ACCOUNT_ID: "867520dfa43947e67f0416d72989a2af" | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ needs.build.outputs.RELEASE_VERSION }} | |
| run: | | |
| LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| # 获取变更信息 | |
| if [[ -n "$LAST_TAG" ]]; then | |
| COMMITS=$(git log $LAST_TAG..HEAD --pretty=format:"- %s" --no-merges) | |
| PRS=$(gh api "repos/${{ github.repository }}/pulls?state=closed" --jq '.[] | select(.merged_at != null and .merged_at > "'$(git log -1 --format=%cI $LAST_TAG)'") | "- \(.title)"') | |
| else | |
| COMMITS=$(git log -20 --pretty=format:"- %s" --no-merges) | |
| PRS="" | |
| fi | |
| # 构建 prompt 并写入文件 | |
| echo "你是一个专业的版本发布助手。请根据以下 Pull Request 和 Commit 信息,为 FancyHelper Minecraft 插件生成中文的发行注记 Overview。" > /tmp/prompt.txt | |
| echo "" >> /tmp/prompt.txt | |
| echo "版本号:v$VERSION" >> /tmp/prompt.txt | |
| echo "" >> /tmp/prompt.txt | |
| echo "PR 列表:" >> /tmp/prompt.txt | |
| echo "$PRS" >> /tmp/prompt.txt | |
| echo "" >> /tmp/prompt.txt | |
| echo "Commit 列表:" >> /tmp/prompt.txt | |
| echo "$COMMITS" >> /tmp/prompt.txt | |
| echo "" >> /tmp/prompt.txt | |
| echo "要求:" >> /tmp/prompt.txt | |
| echo "1. 用中文撰写" >> /tmp/prompt.txt | |
| echo "2. 必须使用以下格式(严格遵守):" >> /tmp/prompt.txt | |
| echo " ## Overview" >> /tmp/prompt.txt | |
| echo " * 第一条变更说明" >> /tmp/prompt.txt | |
| echo " * 第二条变更说明" >> /tmp/prompt.txt | |
| echo " * 第三条变更说明" >> /tmp/prompt.txt | |
| echo "3. 每条变更必须以 \"* \" 开头(星号 + 空格),不要使用其他符号" >> /tmp/prompt.txt | |
| echo "4. 简洁明了,每条控制在 10-30 字" >> /tmp/prompt.txt | |
| echo "5. 突出主要功能更新、bug 修复和重要改动" >> /tmp/prompt.txt | |
| echo "6. 不要添加 emoji" >> /tmp/prompt.txt | |
| echo "7. 直接输出内容,不要有开场白" >> /tmp/prompt.txt | |
| echo "8. 总条目控制在 3-6 条" >> /tmp/prompt.txt | |
| echo "" >> /tmp/prompt.txt | |
| echo "请生成发行注记 Overview:" >> /tmp/prompt.txt | |
| # 获取 Cloudflare Account ID | |
| ACCOUNT_ID="${CLOUDFLARE_ACCOUNT_ID}" | |
| if [[ -z "$ACCOUNT_ID" || "$ACCOUNT_ID" == "null" ]]; then | |
| echo "未配置 CloudFlare Account ID,跳过生成 Overview" | |
| echo "## Overview" > /tmp/overview.md | |
| echo "* 自动生成的版本 v$VERSION 发行说明" >> /tmp/overview.md | |
| exit 0 | |
| fi | |
| echo "Account ID: $ACCOUNT_ID" | |
| # 构建请求体 | |
| PROMPT_CONTENT=$(cat /tmp/prompt.txt) | |
| REQUEST_BODY=$(jq -n \ | |
| --arg model "@cf/meta/llama-3-8b-instruct" \ | |
| --arg prompt "$PROMPT_CONTENT" \ | |
| '{ | |
| "model": $model, | |
| "messages": [ | |
| { | |
| "role": "system", | |
| "content": "你是一个专业的技术文档撰写助手。请生成简洁、专业的发行说明 Overview 部分。" | |
| }, | |
| { | |
| "role": "user", | |
| "content": $prompt | |
| } | |
| ] | |
| }') | |
| # 调用 Cloudflare AI API | |
| RESPONSE=$(curl -s -X POST \ | |
| "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai/run/@cf/meta/llama-3-8b-instruct" \ | |
| -H "Authorization: Bearer $CLOUDFLARE_API_KEY" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$REQUEST_BODY") | |
| echo "API 响应:" | |
| echo "$RESPONSE" | head -c 2000 | |
| echo "" | |
| # 解析响应 | |
| AI_CONTENT=$(echo "$RESPONSE" | jq -r '.result.response // empty') | |
| if [[ -n "$AI_CONTENT" ]]; then | |
| echo "$AI_CONTENT" > /tmp/overview.md | |
| echo "AI 生成内容已写入 /tmp/overview.md" | |
| else | |
| echo "AI 响应为空,使用默认内容" | |
| echo "## Overview" > /tmp/overview.md | |
| echo "* 自动生成的版本 v$VERSION 发行说明" >> /tmp/overview.md | |
| fi | |
| # 获取 GitHub 自动生成的 Notes 作为补充 | |
| gh api "repos/${{ github.repository }}/releases/generate-notes" \ | |
| -f tag_name="v$VERSION" \ | |
| -f target_commitish="${{ github.sha }}" \ | |
| --jq '.body' > /tmp/github_notes.md || echo "" > /tmp/github_notes.md | |
| - name: 组合 Release Body | |
| id: compose_body | |
| run: | | |
| cat /tmp/overview.md > /tmp/release_body.md | |
| echo "" >> /tmp/release_body.md | |
| cat /tmp/github_notes.md >> /tmp/release_body.md | |
| echo "BODY_PATH=/tmp/release_body.md" >> $GITHUB_OUTPUT | |
| - name: 上传 Release Body | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-body | |
| path: /tmp/release_body.md | |
| # ==================== 发布正式 Release ==================== | |
| release: | |
| name: 发布 Release | |
| runs-on: ubuntu-latest | |
| needs: [ build, generate-overview ] | |
| if: needs.build.outputs.IS_RELEASE == 'true' | |
| steps: | |
| - name: 下载构建产物 | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: FancyHelper-build-* | |
| path: target/ | |
| merge-multiple: true | |
| - name: 下载 Release Body | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: release-body | |
| path: ./ | |
| - name: 发布正式 Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| files: target/FancyHelper-*.jar | |
| tag_name: v${{ needs.build.outputs.RELEASE_VERSION }} | |
| name: Release v${{ needs.build.outputs.RELEASE_VERSION }} | |
| body_path: ./release_body.md | |
| make_latest: true |