From 5c3f6d64125c88eea47cf6d4070992cc86f15bcc Mon Sep 17 00:00:00 2001 From: Ivin Joel Abraham Date: Sat, 8 Feb 2025 01:31:58 +0530 Subject: [PATCH] update release-binary worfklow to support multiple targets --- .github/workflows/release-binary.yml | 62 ++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release-binary.yml b/.github/workflows/release-binary.yml index 0686d94..f9cf8ec 100644 --- a/.github/workflows/release-binary.yml +++ b/.github/workflows/release-binary.yml @@ -8,26 +8,70 @@ on: jobs: release: name: Build & Release ${{ matrix.target }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} permissions: - contents: write + contents: write strategy: fail-fast: false matrix: - target: [x86_64-unknown-linux-gnu] + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + extension: "" + name: linux-x86_64 + - target: x86_64-pc-windows-msvc + os: windows-latest + extension: ".exe" + name: windows-x86_64 + - target: aarch64-apple-darwin + os: macos-latest + extension: "" + name: macos-aarch64 steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get tag name + shell: bash + run: | + echo "RELEASE_TAG=${GITHUB_REF_NAME:-v0.1.0-test}" >> $GITHUB_ENV - - name: Add targets - run: rustup target add "${{ matrix.target }}" + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} - - name: Compile binary + - name: Build binary run: cargo build --release --target ${{ matrix.target }} + env: + CARGO_TARGET_DIR: target + + - name: Prepare release assets + shell: bash + run: | + cd target/${{ matrix.target }}/release + BINARY_NAME="amd${{ matrix.extension }}" + if [ -f "$BINARY_NAME" ]; then + ARCHIVE_NAME="amd-${{ env.RELEASE_TAG }}-${{ matrix.name }}.tar.gz" + tar -czf "../../../$ARCHIVE_NAME" "$BINARY_NAME" + echo "Created archive: $ARCHIVE_NAME" + echo "ASSET_PATH=$ARCHIVE_NAME" >> $GITHUB_ENV + else + echo "Error: Binary $BINARY_NAME not found" + ls -la + exit 1 + fi + cd ../../.. - - name: Upload GitHub Release + - name: Upload Release Asset uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - files: target/${{ matrix.target }}/release/* - token: ${{ secrets.GITHUB_TOKEN }} + files: ${{ env.ASSET_PATH }} + tag_name: ${{ env.RELEASE_TAG }} + name: Release ${{ env.RELEASE_TAG }} + generate_release_notes: true