name: Create Release
on:
push:
tags:
- "v*"
jobs:
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
environment: release permissions:
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Generate changelog
id: changelog
run: |
# 获取当前标签
CURRENT_TAG=${GITHUB_REF#refs/tags/}
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
# 获取上一个标签
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
# 生成 changelog
if [ -n "$PREVIOUS_TAG" ]; then
echo "## 🎉 新功能" > release_notes.md
echo "" >> release_notes.md
echo "### 📋 更新内容" >> release_notes.md
echo "" >> release_notes.md
# 获取提交信息并格式化
git log --pretty=format:"- %s" $PREVIOUS_TAG..HEAD | \
sed 's/^feat: /✨ /' | \
sed 's/^fix: /🐛 /' | \
sed 's/^chore: /🔧 /' | \
sed 's/^refactor: /♻️ /' | \
sed 's/^docs: /📚 /' | \
sed 's/^style: /💄 /' | \
sed 's/^test: /🧪 /' | \
sed 's/^perf: /⚡ /' | \
sed 's/^ci: /👷 /' | \
sed 's/^build: /📦 /' | \
sed 's/^revert: /⏪ /' >> release_notes.md
echo "" >> release_notes.md
echo "### 🔗 相关链接" >> release_notes.md
echo "- [GitHub Repository](https://github.com/jenkinpan/pkg-checker-rs)" >> release_notes.md
echo "- [Crates.io](https://crates.io/crates/pkg-checker)" >> release_notes.md
echo "- [Documentation](https://docs.rs/pkg-checker)" >> release_notes.md
echo "" >> release_notes.md
echo "## 📦 安装" >> release_notes.md
echo "" >> release_notes.md
echo "\`\`\`bash" >> release_notes.md
echo "cargo install pkg-checker" >> release_notes.md
echo "\`\`\`" >> release_notes.md
else
echo "## 🎉 首次发布" > release_notes.md
echo "" >> release_notes.md
echo "pkg-checker 是一个用 Rust 编写的工具,用于检查和管理全局安装的 Cargo 包更新。" >> release_notes.md
echo "" >> release_notes.md
echo "### ✨ 主要功能" >> release_notes.md
echo "- 🔍 自动检测已安装的全局 Cargo 包" >> release_notes.md
echo "- 📦 检查每个包的最新版本" >> release_notes.md
echo "- 🎨 彩色输出,清晰显示更新状态" >> release_notes.md
echo "- ⚡ 异步处理,快速检查多个包" >> release_notes.md
echo "- 🔄 默认交互式更新模式,一键更新包" >> release_notes.md
echo "- 🧠 智能预发布版本检测和询问" >> release_notes.md
echo "- 📋 详细的更新摘要功能" >> release_notes.md
echo "" >> release_notes.md
echo "## 📦 安装" >> release_notes.md
echo "" >> release_notes.md
echo "\`\`\`bash" >> release_notes.md
echo "cargo install pkg-checker" >> release_notes.md
echo "\`\`\`" >> release_notes.md
echo "" >> release_notes.md
echo "## 🔗 相关链接" >> release_notes.md
echo "- [GitHub Repository](https://github.com/jenkinpan/pkg-checker-rs)" >> release_notes.md
echo "- [Crates.io](https://crates.io/crates/pkg-checker)" >> release_notes.md
echo "- [Documentation](https://docs.rs/pkg-checker)" >> release_notes.md
fi
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
run: cargo test --workspace
- name: Check formatting
run: cargo fmt --all --check
- name: Run clippy
run: cargo clippy --workspace -- -D warnings
- name: Publish to Crates.io
uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish to Crates.io
run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.changelog.outputs.current_tag }}
name: pkg-checker ${{ steps.changelog.outputs.current_tag }} - 自动发布
body_path: release_notes.md
draft: false
prerelease: false
generate_release_notes: false
- name: Upload release notes
run: |
echo "Release created successfully!"
echo "Tag: ${{ steps.changelog.outputs.current_tag }}"
echo "Previous tag: ${{ steps.changelog.outputs.previous_tag }}"
echo ""
echo "Release notes content:"
cat release_notes.md