From c35d563ab7af57895aaec4782052ede25062d369 Mon Sep 17 00:00:00 2001 From: Ulrich Kautz Date: Wed, 15 Jan 2025 08:25:02 -0800 Subject: [PATCH] Add Github Action to build and release binaries of new tags Summary: This adds a Github Action build and release binaries for Linux, MacOS and Windows upon new new tag. # Why? Simplify usage of Scrut by making binaries available for common platforms. # What? Add Github Action that starts automatic build and release for the following targets: - x86_64-unknown-linux-musl - aarch64-unknown-linux-musl - x86_64-apple-darwin - aarch64-apple-darwin - x86_64-pc-windows-gnu The binaries will be build, archived (zip for windows, tar zst for others) and then uploaded as a a release asset for a newly created release version. Reviewed By: AndreasBackx Differential Revision: D68104600 fbshipit-source-id: 35a781e96aa33dcefcd43a9f4357b0c3dbfd7de5 --- .github/workflows/release-binaries.yml | 86 ++++++++++++++++++++++++++ Cargo.toml | 3 + 2 files changed, 89 insertions(+) create mode 100644 .github/workflows/release-binaries.yml diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml new file mode 100644 index 0000000..04e5e52 --- /dev/null +++ b/.github/workflows/release-binaries.yml @@ -0,0 +1,86 @@ +# Build and release binaries for Linux, MacOS and Windows for common architectures via Github Actions +name: Build and Release Binaries + +on: + push: + tags: + - '*' + workflow_dispatch: {} + +permissions: + contents: write + +jobs: + build-and-release: + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + # linux + - build: linux-x86_64 + os: ubuntu-24.04 + target: x86_64-unknown-linux-musl + - build: linux-aarch64 + os: ubuntu-24.04 + target: aarch64-unknown-linux-musl + + # macos + - build: macos-x86_64 + os: macos-15 + target: x86_64-apple-darwin + - build: macos-aarch64 + os: macos-15 + target: aarch64-apple-darwin + + # windows + - build: windows-x86_64 + os: windows-2022 + target: x86_64-pc-windows-gnu + + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get Version + shell: bash + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.target }} + + - name: Build Binary + run: cargo build --release + + - name: Build Archive + shell: bash + run: | + binary_name="scrut" + + dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}" + mkdir -p "$dirname" + if [ "${{ matrix.os }}" = "windows-2022" ]; then + mv "target/release/$binary_name.exe" "$dirname" + else + mv "target/release/$binary_name" "$dirname" + fi + + if [ "${{ matrix.os }}" = "windows-2022" ]; then + 7z a "$dirname.zip" "$dirname" + echo "ASSET=$dirname.zip" >> $GITHUB_ENV + else + tar --use-compress-program zstdmt -cf "$dirname.tar.zst" "$dirname" + echo "ASSET=$dirname.tar.zst" >> $GITHUB_ENV + fi + + - name: Release + uses: softprops/action-gh-release@v2 + with: + files: | + ${{ env.ASSET }} diff --git a/Cargo.toml b/Cargo.toml index 33df9d0..4aaeda4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,3 +80,6 @@ vergen = { version = "7", features = ["git"] } assert_cmd = "2.0" insta = {version = "1.21.1", features = ["json"] } predicates = "2.1" + +[profile.release] +strip = true