ci: 使用github.ref_name字段 #46
Workflow file for this run
This file contains 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: Build and Release | |
on: | |
push: | |
tags: [ '*' ] # 推送标签时触发 | |
permissions: | |
contents: write | |
jobs: | |
build: | |
name: build | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
build: [ x86_64-linux,x86_64-windows,x86_64-macos,aarch64-macos ] | |
include: | |
- build: x86_64-linux | |
os: ubuntu-latest | |
rust: nightly | |
target: x86_64-unknown-linux-gnu | |
archive-name: maimai-search-${{ github.ref_name }}-linux-x86_64.tar.gz | |
- build: x86_64-macos | |
os: macos-latest | |
rust: nightly | |
target: x86_64-apple-darwin | |
archive-name: maimai-search-${{ github.ref_name }}-macos-x86_64.tar.gz | |
- build: x86_64-windows | |
os: windows-latest | |
rust: nightly-x86_64-msvc | |
target: x86_64-pc-windows-msvc | |
archive-name: maimai-search-${{ github.ref_name }}-windows-x86_64.7z | |
- build: aarch64-macos | |
os: macos-latest | |
rust: nightly | |
target: aarch64-apple-darwin | |
archive-name: maimai-search-${{ github.ref_name }}-macos-aarch64.tar.gz | |
fail-fast: false | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get commit messages | |
id: commit_message | |
shell: bash | |
run: | | |
git fetch --tags | |
LATEST_TAG=$(git describe --tags --abbrev=0) | |
tag_pattern="^[0-9]+\.[0-9]+\.[0-9]+$" | |
tags=$(git tag | grep -E $tag_pattern | sort -Vr ) | |
PREVIOUS_TAG=$( echo "$tags" | head -n2| tail -n1 ) | |
git log $PREVIOUS_TAG...$LATEST_TAG --pretty=format:"%h - %s" -5 > commit.log | |
echo "===== Commit file =====" | |
cat commit.log | |
echo "====== files end ======" | |
echo "::set-output name=message::$(cat commit.log)" | |
- name: Rust Cache | |
uses: Swatinem/[email protected] | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: ${{ matrix.rust }} | |
profile: minimal | |
override: true | |
target: ${{ matrix.target }} | |
- name: Build binary | |
run: cargo build --verbose --release --target ${{ matrix.target }} | |
env: | |
RUST_BACKTRACE: 1 | |
- name: Strip binary (linux and macos) | |
if: matrix.build == 'aarch64-macos' || matrix.build == 'x86_64-macos' || matrix.build == 'x86_64-linux' | |
run: strip "target/${{ matrix.target }}/release/maimai-search" | |
- name: Build archive | |
shell: bash | |
run: | | |
mkdir archive | |
cp LICENSE README.md archive/ | |
cd archive | |
if [ "${{ matrix.build }}" = "x86_64-windows" ]; then | |
cp "../target/${{ matrix.target }}/release/maimai-search.exe" ./ | |
7z a "${{ matrix.archive-name }}" LICENSE README.md maimai-search.exe | |
else | |
cp "../target/${{ matrix.target }}/release/maimai-search" ./ | |
tar -czf "${{ matrix.archive-name }}" LICENSE README.md maimai-search | |
fi | |
- name: Upload archive | |
uses: actions/upload-artifact@v1 | |
with: | |
name: ${{ matrix.archive-name }} | |
path: archive/${{ matrix.archive-name }} | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
name: Release ${{ github.ref_name }} | |
body: ${{ steps.commit_message.outputs.message }} | |
files: | | |
archive/${{ matrix.archive-name }} | |
token: ${{ secrets.GITHUB_TOKEN }} |