Skip to content

Update release workflow to build aarch64 #47

Update release workflow to build aarch64

Update release workflow to build aarch64 #47

Workflow file for this run

name: Release
on:
push:
branches:
- workflow_release
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-alpha'
- 'v[0-9]+.[0-9]+.[0-9]+-beta'
env:
# Emit backtraces on panics.
RUST_BACKTRACE: full
# Enable colors in cargo output.
CARGO_TERM_COLOR: always
# Use sparse index if supported
# (probably no longer required, but cargo-culted)
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
jobs:
check_release:
name: check_release
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install toolchain
run: rustup show
shell: bash
- name: Run cargo fmt
run: cargo fmt --all -- --check
shell: bash
- name: Run cargo check
run: RUSTFLAGS="-D warnings" cargo check --workspace --locked --all-targets
shell: bash
- name: Run cargo test
run: cargo test --workspace --locked --all-targets --no-fail-fast
shell: bash
- name: Run cargo clippy
run: cargo clippy --workspace --locked --all-targets -- -Dwarnings
shell: bash
- name: Gather release info
id: info
run: |
ref_name='${{ github.ref_name }}'
echo "ref_name: $ref_name"
# is this a test release, or a real release?
if [[ "$ref_name" == 'workflow_release' ]]; then
version='v0.0.0-test'
else
version="$ref_name"
fi
echo "version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
shell: bash
outputs:
version: ${{ steps.info.outputs.version }}
build_release:
name: build_release
needs: ['check_release']
runs-on: ${{ matrix.os }}
timeout-minutes: 15
env:
# Disable incremental compilation.
CARGO_INCREMENTAL: 0
MECH3AX_VERSION: ${{ needs.check_release.outputs.version }}
TARGET_DIR: target/${{ matrix.target }}/release
STAGING_DIR: mech3ax-${{ needs.check_release.outputs.version }}-${{ matrix.target }}
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-pc-windows-msvc
- x86_64-apple-darwin
- aarch64-apple-darwin
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-apple-darwin
os: macos-13
- target: aarch64-apple-darwin
os: macos-14
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install toolchain
run: |
set -x
rustup show
rustup target add '${{ matrix.target }}'
shell: bash
- name: Create staging
run: |
set -x
echo "MECH3AX_VERSION: $MECH3AX_VERSION"
echo "TARGET_DIR: $TARGET_DIR"
echo "STAGING_DIR: $STAGING_DIR"
# create archive staging directory
mkdir "$STAGING_DIR"
# copy supporting files
cp README.md LICENSE "$STAGING_DIR/"
shell: bash
- name: Build release binary (Linux)
if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }}
run: |
cargo build --release --target='${{ matrix.target }}'
set -x
check_version=$("$TARGET_DIR/unzbd" --version | cut -d' ' -f2)
if [[ "$MECH3AX_VERSION" != "$check_version" ]]; then
echo "version mismatch: >$MECH3AX_VERSION< != >$check_version<"
exit 1
fi
cp "$TARGET_DIR/unzbd" "$TARGET_DIR/rezbd" "$STAGING_DIR/"
cp "$TARGET_DIR/libmech3ax.so" "$STAGING_DIR/libmech3ax-$MECH3AX_VERSION.so"
shell: bash
- name: Build release binary (Windows)
if: ${{ matrix.target == 'x86_64-pc-windows-msvc' }}
run: |
cargo build --release --target='${{ matrix.target }}'
set -x
check_version=$("$TARGET_DIR/unzbd.exe" --version | cut -d' ' -f2)
if [[ "$MECH3AX_VERSION" != "$check_version" ]]; then
echo "version mismatch: >$MECH3AX_VERSION< != >$check_version<"
exit 1
fi
cp "$TARGET_DIR/unzbd.exe" "$TARGET_DIR/rezbd.exe" "$STAGING_DIR/"
cp "$TARGET_DIR/mech3ax.dll" "$STAGING_DIR/mech3ax-$MECH3AX_VERSION.dll"
shell: bash
- name: Build release binary (macOS)
if: ${{ matrix.target == 'aarch64-apple-darwin' || matrix.target == 'x86_64-apple-darwin' }}
env:
MACOSX_DEPLOYMENT_TARGET: "12.0"
run: |
set -x
echo "MACOSX_DEPLOYMENT_TARGET: $MACOSX_DEPLOYMENT_TARGET"
xcodebuild -showsdks
set +x
cargo build --release --target='${{ matrix.target }}'
set -x
file "$TARGET_DIR/unzbd"
file "$TARGET_DIR/rezbd"
file "$TARGET_DIR/libmech3ax.dylib"
check_version=$("$TARGET_DIR/unzbd" --version | cut -d' ' -f2)
if [[ "$MECH3AX_VERSION" != "$check_version" ]]; then
echo "version mismatch: >$MECH3AX_VERSION< != >$check_version<"
exit 1
fi
cp "$TARGET_DIR/unzbd" "$TARGET_DIR/rezbd" "$STAGING_DIR/"
cp "$TARGET_DIR/libmech3ax.dylib" "$STAGING_DIR/libmech3ax-$MECH3AX_VERSION.dylib"
shell: bash
- name: Build archive
id: build
run: |
set -x
ls -1 "$STAGING_DIR/"
7z -mx=9 a "$STAGING_DIR.zip" "$STAGING_DIR"
shell: bash
- name: Upload the release assets
uses: actions/upload-artifact@v4
with:
name: mech3ax-${{ needs.check_release.outputs.version }}-${{ matrix.target }}
path: mech3ax-${{ needs.check_release.outputs.version }}-${{ matrix.target }}.zip
if-no-files-found: error
retention-days: 3
compression-level: 0
overwrite: false
create_release:
name: create_release
needs: ['check_release', 'build_release']
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
# IMPORTANT: mandatory for making GitHub Releases
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs#overview
contents: write
steps:
- name: Download the release assets
uses: actions/download-artifact@v4
with:
pattern: mech3ax-*
merge-multiple: true
path: assets/
- name: List the release assets
run: ls -1R assets/*
shell: bash
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
version='${{ needs.check_release.outputs.version }}'
echo "version: $version"
# empty arguments
set --
# is this a test release, or a real release?
if [[ "$version" == 'v0.0.0-test' ]]; then
set -- "$@" --target '${{ github.sha }}'
fi
# is this a pre-release (-rc*, -alpha, -beta, -test)?
if [[ "$version" == *"-"* ]]; then
set -- "$@" --prerelease
fi
date=$(env TZ=':America/Los_Angeles' date +'%Y-%m-%d')
echo "date: $date"
echo "args: $@"
set -x
gh release create \
"$version" \
assets/* \
--title "$version ($date)" \
--draft \
--repo '${{ github.repository }}' \
"$@"
shell: bash