Skip to content

Commit

Permalink
Add build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Nov 18, 2024
1 parent afceb68 commit 7cbb588
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build and Upload Release Binaries

on:
workflow_dispatch:
pull_request:
branches:
- '**' # TODO: remove

jobs:
build-and-upload:
name: ${{ matrix.os }} build
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
suffix: linux-x86_64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
suffix: linux-aarch64
- os: macos-latest
target: x86_64-apple-darwin
suffix: macos-x86_64
- os: macos-latest
target: aarch64-apple-darwin
suffix: macos-aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
suffix: windows-x86_64.exe

steps:
- uses: actions/checkout@v4

- name: Get latest tag
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags --abbrev=0)
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Install cross-compilation tools
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build binary
run: cargo build --release --target ${{ matrix.target }}

- name: Get binary name from Cargo.toml
shell: bash
run: |
BINARY_NAME=$(grep -m1 '^name' Cargo.toml | cut -d'"' -f2 | cut -d"'" -f2)
echo "BINARY_NAME=$BINARY_NAME" >> $GITHUB_ENV
- name: Rename binary
shell: bash
run: |
cd target/${{ matrix.target }}/release
if [[ "${{ runner.os }}" == "Windows" ]]; then
mv "${{ env.BINARY_NAME }}.exe" "${{ env.BINARY_NAME }}-${{ matrix.suffix }}"
else
mv "${{ env.BINARY_NAME }}" "${{ env.BINARY_NAME }}-${{ matrix.suffix }}"
fi
- name: Upload to release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.LATEST_TAG }}
files: target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}-${{ matrix.suffix }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 7cbb588

Please sign in to comment.