name: Release
on:
push:
tags:
- "v*" workflow_dispatch:
inputs:
version:
description: "Release version (e.g., 0.4.0)"
required: true
type: string
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --all-features
- name: Run tests
run: |
for test in $(ls tests/*.rs | sed 's/tests\/\(.*\)\.rs/\1/' | grep -v ha_test); do
cargo test --verbose --test "$test"
done
cargo test --verbose --lib
publish:
needs: [check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Verify version
run: |
# 如果是 tag 推送,检查 tag 版本与 Cargo.toml 一致
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "Tag version: $TAG_VERSION"
echo "Cargo version: $CARGO_VERSION"
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
# 先发布宏 crate,再发布主 crate
cd remdb-macros
cargo publish --allow-dirty || true
cd ..
cargo publish --allow-dirty
release:
needs: [publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate release notes
id: release_notes
run: |
# 获取上一个 tag 到当前 tag 之间的 commit 记录
PREVIOUS_TAG=$(git tag --sort=-version:refname | head -2 | tail -1 || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
# 如果没有上一个 tag,获取所有 commit
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges $PREVIOUS_TAG..HEAD)
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ github.ref_name }}
body: |
## ${{ github.ref_name }}
### Changes in this release:
${{ steps.release_notes.outputs.CHANGELOG }}
draft: false
prerelease: false
generate_release_notes: false