feat: architecture upgrade (#1) #81
Workflow file for this run
This file contains hidden or 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: Rust Build, Test and Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| env: | |
| BINARY_NAME: proxy-convert | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.target }} | |
| runs-on: ${{ matrix.runner || matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| # Linux glibc + musl static | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| - os: ubuntu-latest | |
| target: aarch64-unknown-linux-gnu | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-musl | |
| # macOS | |
| - os: macos-14 | |
| target: x86_64-apple-darwin | |
| - os: macos-14 | |
| target: aarch64-apple-darwin | |
| # Windows (aarch64 使用 windows-11-arm runner,os 名称仍为 windows-latest) | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| - os: windows-latest | |
| target: aarch64-pc-windows-msvc | |
| runner: windows-11-arm | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@v1 | |
| with: | |
| toolchain: stable | |
| targets: ${{ matrix.target }} | |
| - name: Cache cargo | |
| uses: Swatinem/rust-cache@v2.8.2 | |
| with: | |
| key: ${{ matrix.target }} | |
| shared-key: release | |
| - name: Install Linux deps (glibc cross) | |
| if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross binutils-aarch64-linux-gnu | |
| - name: Set env for Linux aarch64 cross (glibc) | |
| if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV | |
| echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV | |
| echo "RANLIB_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ranlib" >> $GITHUB_ENV | |
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| - name: Install musl (Linux static, x86_64 only) | |
| if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-musl' | |
| run: sudo apt-get update && sudo apt-get install -y musl-tools | |
| - name: Set env for musl (x86_64) | |
| if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-musl' | |
| run: echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> $GITHUB_ENV | |
| - name: Build | |
| run: cargo build --release --target ${{ matrix.target }} --verbose | |
| - name: Test binary | |
| shell: bash | |
| run: | | |
| if [ "${{ matrix.os }}" = "windows-latest" ]; then | |
| exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" | |
| else | |
| exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}" | |
| fi | |
| if [ ! -f "$exe" ]; then | |
| echo "Binary not found: $exe" | |
| exit 1 | |
| fi | |
| # Only run binary on native target (cross-compiled binaries cannot run on host) | |
| if [ "${{ matrix.os }}" = "ubuntu-latest" ] && [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then | |
| "$exe" --version | |
| elif [ "${{ matrix.os }}" = "windows-latest" ] && { [ "${{ matrix.target }}" = "x86_64-pc-windows-msvc" ] || [ "${{ matrix.target }}" = "aarch64-pc-windows-msvc" ]; }; then | |
| "$exe" --version | |
| elif [ "${{ matrix.os }}" = "macos-14" ] && [ "${{ matrix.target }}" = "aarch64-apple-darwin" ]; then | |
| "$exe" --version | |
| else | |
| echo "Skipping execution (cross-compiled target)." | |
| fi | |
| - name: Package | |
| shell: bash | |
| run: | | |
| if [ "${{ matrix.os }}" = "windows-latest" ]; then | |
| exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" | |
| out="${{ env.BINARY_NAME }}-${{ matrix.target }}.zip" | |
| mkdir -p release | |
| cp "$exe" release/ | |
| (cd release && 7z a "$out" "${{ env.BINARY_NAME }}.exe") | |
| else | |
| exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}" | |
| out="${{ env.BINARY_NAME }}-${{ matrix.target }}.tar.gz" | |
| mkdir -p release | |
| cp "$exe" release/ | |
| (cd release && tar czvf "$out" "${{ env.BINARY_NAME }}") | |
| fi | |
| echo "PACKAGE_PATH=release/$out" >> $GITHUB_ENV | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.target }} | |
| path: ${{ env.PACKAGE_PATH }} | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| artifacts/*/*.tar.gz | |
| artifacts/*/*.zip |