Skip to content

更新发布文件

更新发布文件 #16

Workflow file for this run

name: Release
on:
workflow_dispatch:
push:
branches:
- master
permissions:
contents: write
jobs:
release:
name: Generate Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # 必须获取完整历史以获取 tag 范围
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Extract version from Gradle
id: version
run: |
VERSION=$(grep -E '^version\s*=' build.gradle.kts | head -n1 | sed -E 's/.*"(.+)"$/\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Check if release commit
id: check_release
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Last commit message: $COMMIT_MSG"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Manual trigger: should_release=true"
echo "should_release=true" >> $GITHUB_OUTPUT
elif echo "$COMMIT_MSG" | grep -qE '\bv[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?\b'; then
echo "Release commit detected: $COMMIT_MSG"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "No release commit detected. Skipping."
echo "should_release=false" >> $GITHUB_OUTPUT
fi
- name: Stop if not release
if: steps.check_release.outputs.should_release == 'false'
run: echo "Not a release commit, skipping job."
- name: Build project
if: steps.check_release.outputs.should_release == 'true'
run: |
chmod +x ./gradlew
./gradlew clean buildPlugin -x miraiPrepareMetadata
- name: Ensure tag exists (auto create if missing)
if: steps.check_release.outputs.should_release == 'true'
run: |
git fetch --tags
CURRENT_TAG="v${{ env.VERSION }}"
if ! git tag | grep -q "^$CURRENT_TAG$"; then
echo "Tag $CURRENT_TAG not found, creating it now."
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$CURRENT_TAG"
git push origin "$CURRENT_TAG"
else
echo "Tag $CURRENT_TAG already exists."
fi
- name: Create Mirai Plugin Package
if: steps.check_release.outputs.should_release == 'true'
run: |
VERSION="${{ env.VERSION }}"
PLUGIN_NAME="GuessCS2ProPlayer"
# 创建临时目录结构
mkdir -p temp_package/plugins
mkdir -p temp_package/data/org.bcz.guesscs2proplayer
# 复制插件本体到plugins目录
cp build/libs/*.jar temp_package/plugins/
# 复制resource目录下的资源文件到data目录
if [ -d "resource" ]; then
echo "Copying resource files..."
cp -r resource/* temp_package/data/org.bcz.guesscs2proplayer/
echo "Resource files copied successfully"
else
echo "Warning: resource directory not found"
fi
# 显示打包内容
echo "Package contents:"
find temp_package -type f
# 创建最终的zip包
cd temp_package
zip -r "../${PLUGIN_NAME}-${VERSION}.zip" .
cd ..
# 清理临时目录
rm -rf temp_package
echo "Created package: ${PLUGIN_NAME}-${VERSION}.zip"
- name: Generate Changelog
if: steps.check_release.outputs.should_release == 'true'
id: changelog
run: |
echo "## 🎮 CS2 猜职业选手小游戏 - v${{ env.VERSION }}" > release_notes.md
echo "" >> release_notes.md
echo "### �� 发布包信息" >> release_notes.md
echo "- **插件本体**: 位于 `plugins/` 目录" >> release_notes.md
echo "- **资源文件**: 位于 `data/org.bcz.guesscs2proplayer/` 目录" >> release_notes.md
echo "" >> release_notes.md
echo "## 🎨 Changelog" >> release_notes.md
echo "" >> release_notes.md
git fetch --tags
CURRENT_TAG="v${{ env.VERSION }}"
ALL_TAGS=($(git tag --list "v*" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | sort -V))
# Find index of CURRENT_TAG
CUR_INDEX=-1
for ((i=0; i<${#ALL_TAGS[@]}; i++)); do
if [[ "${ALL_TAGS[$i]}" == "$CURRENT_TAG" ]]; then
CUR_INDEX=$i
break
fi
done
if [[ $CUR_INDEX -eq -1 ]]; then
echo "Current tag $CURRENT_TAG not found in tag list: ${ALL_TAGS[*]}"
exit 1
fi
if [[ $CUR_INDEX -eq 0 ]]; then
# First tag, show all commits up to this tag
RANGE=""
echo "No previous tag found, using all commits up to $CURRENT_TAG"
else
PREV_TAG="${ALL_TAGS[$((CUR_INDEX-1))]}"
RANGE="$PREV_TAG..$CURRENT_TAG"
echo "Previous tag: $PREV_TAG"
fi
COMMITS=$(git log --pretty=format:"%s (%an)" $RANGE | grep -v 'dependabot')
# 分类处理
NEW=""
FIXED=""
REFACTOR=""
DOCS=""
IMPROVED=""
OTHER=""
while IFS= read -r line; do
if [[ "$line" == feat:* ]]; then
NEW+=$'- '"${line#feat: }"$'\n'
elif [[ "$line" == fix:* ]]; then
FIXED+=$'- '"${line#fix: }"$'\n'
elif [[ "$line" == refactor:* ]]; then
REFACTOR+=$'- '"${line#refactor: }"$'\n'
elif [[ "$line" == docs:* ]]; then
DOCS+=$'- '"${line#docs: }"$'\n'
elif [[ "$line" == style:* || "$line" == perf:* ]]; then
IMPROVED+=$'- '"${line#*: }"$'\n'
else
OTHER+=$'- '"${line}"$'\n'
fi
done <<< "$COMMITS"
[[ -n "$NEW" ]] && echo -e "### ✅ New Features\n$NEW" >> release_notes.md
[[ -n "$FIXED" ]] && echo -e "### ️ Bug Fixes\n$FIXED" >> release_notes.md
[[ -n "$REFACTOR" ]] && echo -e "### 🧽 Refactoring\n$REFACTOR" >> release_notes.md
[[ -n "$DOCS" ]] && echo -e "### 📚 Documentation\n$DOCS" >> release_notes.md
[[ -n "$IMPROVED" ]] && echo -e "### 🚀 Improvements\n$IMPROVED" >> release_notes.md
[[ -n "$OTHER" ]] && echo -e "### 🔄 Other Changes\n$OTHER" >> release_notes.md
echo "" >> release_notes.md
echo "## 🚀 安装说明" >> release_notes.md
echo "1. 下载并解压 `GuessCS2ProPlayer-${{ env.VERSION }}.zip`" >> release_notes.md
echo "2. 将 `plugins/目录下的jar文件放入Mirai Console的plugins目录" >> release_notes.md
echo "3. 将 data/org.bcz.guesscs2proplayer/ 目录放入Mirai Console的data目录" >> release_notes.md
echo "4. 重启Mirai Console即可使用" >> release_notes.md
cat release_notes.md
- name: Create GitHub Release
if: steps.check_release.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ env.VERSION }}
name: "v${{ env.VERSION }}"
body_path: release_notes.md
files: |
GuessCS2ProPlayer-${{ env.VERSION }}.zip
build/libs/*.jar
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}