Add workflow to build and publish rust binaries #10
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: Build and Publish Rust Binaries | |
| on: | |
| pull_request: | |
| branches: | |
| - dev | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| env: | |
| CARGO_TERM_COLOR: always | |
| BUILD_PROFILE: dist | |
| ARTIFACT_DIR: artifacts | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Rust | |
| run: | | |
| rustup update stable | |
| rustup target add ${{ matrix.target }} | |
| - name: Get binary name and extension | |
| id: binary_info | |
| shell: bash | |
| run: | | |
| # Get the binary name from Cargo.toml | |
| BINARY_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name') | |
| # Set binary extension based on target | |
| if [[ "${{ matrix.target }}" == *"windows"* ]]; then | |
| BINARY_EXT=".exe" | |
| else | |
| BINARY_EXT="" | |
| fi | |
| echo "binary_name=${BINARY_NAME}" >> $GITHUB_OUTPUT | |
| echo "binary_ext=${BINARY_EXT}" >> $GITHUB_OUTPUT | |
| - name: Build binary | |
| run: | | |
| cargo build --profile $BUILD_PROFILE --target ${{ matrix.target }} | |
| - name: Prepare binary | |
| shell: bash | |
| run: | | |
| BINARY_NAME="${{ steps.binary_info.outputs.binary_name }}" | |
| BINARY_EXT="${{ steps.binary_info.outputs.binary_ext }}" | |
| TARGET="${{ matrix.target }}" | |
| mkdir -p "$ARTIFACT_DIR" | |
| cp "target/${TARGET}/${BUILD_PROFILE}/${BINARY_NAME}${BINARY_EXT}" "$ARTIFACT_DIR/" | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.target }}-binary | |
| path: ${{ env.ARTIFACT_DIR }} | |
| release: | |
| name: Create GitHub Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: downloaded-artifacts | |
| - name: Create GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create "${GITHUB_REF#refs/tags/}" \ | |
| --title "${GITHUB_REF#refs/tags/}" \ | |
| --notes "Automated release for ${GITHUB_REF#refs/tags/}" \ | |
| downloaded-artifacts/**/* \ | |
| --draft=false \ | |
| --prerelease=false |