sync-box 0.1.2

一个高效的目录同步工具,支持实时监听文件变化并自动同步,可通过命令行直接使用或通过配置文件管理多个同步任务。
Documentation
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 }}

      # 关键:为 Windows 安装额外依赖(MSVC 工具链)
      - name: Install Windows dependencies
        if: matrix.os == 'windows-latest'
        uses: ilammy/msvc-dev-cmd@v1  # 配置 Windows 编译环境

      - name: Build release
        run: cargo build --release --target ${{ matrix.target }}
        env:
          # 为 Windows 强制指定链接器,避免编译错误
          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 }}