name: Build and Release
permissions:
contents: write
on:
push:
tags:
- 'v*.*.*'
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
binary: syncbox
archive: syncbox-linux-x86_64.tar.gz
- os: macos-latest
target: x86_64-apple-darwin
binary: syncbox
archive: syncbox-macos-x86_64.tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
binary: syncbox.exe
archive: syncbox-windows-x86_64.zip
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
target: ${{ matrix.target }}
- name: Install Windows dependencies
if: matrix.os == 'windows-latest'
uses: ilammy/msvc-dev-cmd@v1
- name: Build release
run: cargo build --release --target ${{ matrix.target }}
env:
RUSTFLAGS: ${{ matrix.os == 'windows-latest' && '-C linker=link.exe' || '' }}
- name: Locate binary
id: binary-path
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
echo "path=target/${{ matrix.target }}/release/${{ matrix.binary }}" >> $GITHUB_OUTPUT
else
echo "path=target/${{ matrix.target }}/release/${{ matrix.binary }}" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Package artifact
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
# 修复 Windows 打包路径问题
powershell -Command "Compress-Archive -Path '${{ steps.binary-path.outputs.path }}' -DestinationPath '${{ matrix.archive }}' -Force"
else
tar -czf ${{ matrix.archive }} -C $(dirname ${{ steps.binary-path.outputs.path }}) $(basename ${{ steps.binary-path.outputs.path }})
fi
shell: bash
- name: Upload to Release
uses: softprops/action-gh-release@v2
with:
files: ${{ matrix.archive }}
name: Release ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}