name: Release
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
id-token: write
env:
CARGO_TERM_COLOR: always
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from tag
id: version
run: |
TAG_NAME="${GITHUB_REF#refs/tags/}"
VERSION="${TAG_NAME#v}"
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Tag: $TAG_NAME"
echo "Version: $VERSION"
- name: Generate changelog
id: changelog
run: |
# 获取上一个 tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
echo "## What's Changed" > changelog.md
echo "" >> changelog.md
if [ -n "$PREV_TAG" ]; then
echo "Changes since $PREV_TAG:" >> changelog.md
git log $PREV_TAG..HEAD --pretty=format:"- %s (%h)" >> changelog.md
else
echo "Full changelog:" >> changelog.md
git log --pretty=format:"- %s (%h)" >> changelog.md
fi
echo "" >> changelog.md
echo "" >> changelog.md
echo "## Assets" >> changelog.md
echo "" >> changelog.md
cat changelog.md
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu
- name: Build x86_64-unknown-linux-gnu
run: |
cargo build --release --target x86_64-unknown-linux-gnu --workspace
mv target/x86_64-unknown-linux-gnu/release/oxcache oxcache-x86_64-linux
- name: Build aarch64-unknown-linux-gnu
run: |
cargo build --release --target aarch64-unknown-linux-gnu --workspace
mv target/aarch64-unknown-linux-gnu/release/oxcache oxcache-aarch64-linux
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag_name }}
name: Release ${{ steps.version.outputs.tag_name }}
body_path: changelog.md
files: |
oxcache-x86_64-linux
oxcache-aarch64-linux
draft: false
prerelease: false
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to crates.io
run: |
echo "Publishing to crates.io..."
cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --workspace
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}