Merge pull request #20 from glowcoil/update-actions #261
This file contains 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: Automated Builds | |
on: | |
push: | |
branches: | |
- '**' | |
tags: | |
# Run when pushing version tags, since otherwise it's impossible to | |
# restart a successful build after pushing a tag | |
- '*.*.*' | |
pull_request: | |
branches: | |
- master | |
defaults: | |
run: | |
# This otherwise gets run under dash which does not support brace expansion | |
shell: bash | |
jobs: | |
# This builds the binaries and uploads them to GitHub Actions. A second job | |
# builds a universal binary out of the macOS binaries. | |
package: | |
strategy: | |
matrix: | |
include: | |
- { name: ubuntu-22.04, os: ubuntu-22.04, cross-target: '' } | |
- { name: macos-12-x86_64, os: macos-12, cross-target: '' } | |
- { name: macos-12-aarch64, os: macos-12, cross-target: aarch64-apple-darwin } | |
- { name: windows, os: windows-latest, cross-target: '' } | |
name: Build binary | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Fetch all git history | |
run: git fetch --force --prune --tags --unshallow | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ matrix.name }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Set up Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
# The macOS AArch64 build is done from an x86_64 macOS CI runner, so | |
# it needs to be cross compiled | |
targets: ${{ matrix.cross-target }} | |
- name: Build the binary | |
if: '!matrix.cross-target' | |
run: | | |
export MACOSX_DEPLOYMENT_TARGET=10.13 | |
cargo build --release | |
- name: Build the binary | |
if: matrix.cross-target | |
run: | | |
export MACOSX_DEPLOYMENT_TARGET=10.13 | |
cargo build --release --target="${{ matrix.cross-target }}" | |
- name: Determine the build archive name | |
run: | | |
echo "ARCHIVE_NAME=clap-validator-$(git describe --always)-${{ matrix.name }}" >> "$GITHUB_ENV" | |
# GitHub _very helpfully_ strips out the executable bit. Thanks GitHub, very cool. | |
- name: Create tarball | |
if: startsWith(matrix.os, 'ubuntu') || (startsWith(matrix.os, 'macos') && !matrix.cross-target) | |
run: | | |
tar -C target/release -caf "$ARCHIVE_NAME.tar.gz" clap-validator | |
- name: Create tarball | |
if: startsWith(matrix.os, 'macos') && matrix.cross-target | |
run: | | |
tar -C target/${{ matrix.cross-target }}/release -caf "$ARCHIVE_NAME.tar.gz" clap-validator | |
- uses: actions/upload-artifact@v4 | |
if: "!startsWith(matrix.os, 'windows')" | |
with: | |
name: ${{ env.ARCHIVE_NAME }} | |
path: ${{ env.ARCHIVE_NAME }}.tar.gz | |
# On Windows we can just upload the .exe file directly since Windows | |
# doesn't have an executable bit | |
- uses: actions/upload-artifact@v4 | |
if: startsWith(matrix.os, 'windows') | |
with: | |
name: ${{ env.ARCHIVE_NAME }} | |
path: target/release/clap-validator.exe | |
universal-binary: | |
name: Build a universal macOS binary | |
runs-on: macos-12 | |
needs: package | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Fetch all git history | |
run: git fetch --force --prune --tags --unshallow | |
- name: Determine the previously build archive names | |
run: | | |
echo "X86_64_ARCHIVE_NAME=clap-validator-$(git describe --always)-macos-12-x86_64" >> "$GITHUB_ENV" | |
echo "AARCH64_ARCHIVE_NAME=clap-validator-$(git describe --always)-macos-12-aarch64" >> "$GITHUB_ENV" | |
- name: Determine archive name for the universal binary | |
run: | | |
echo "ARCHIVE_NAME=clap-validator-$(git describe --always)-macos-universal" >> "$GITHUB_ENV" | |
- name: Download the previously built x86_64 binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.X86_64_ARCHIVE_NAME }} | |
path: binaries/x86_64 | |
- name: Download the previously built AArch64 binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.AARCH64_ARCHIVE_NAME }} | |
path: binaries/aarch64 | |
- name: Combine the binaries | |
run: | | |
# There's only a single file in the directory, so that makes it easier | |
tar -C binaries/x86_64 -xvf binaries/x86_64/*.tar.gz | |
rm binaries/x86_64/*.tar.gz | |
tar -C binaries/aarch64 -xvf binaries/aarch64/*.tar.gz | |
rm binaries/aarch64/*.tar.gz | |
lipo -create -output binaries/clap-validator binaries/x86_64/clap-validator binaries/aarch64/clap-validator | |
tar -caf "$ARCHIVE_NAME.tar.gz" binaries/clap-validator | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARCHIVE_NAME }} | |
path: ${{ env.ARCHIVE_NAME }}.tar.gz |