ci: enable cross-compilation and test on arm64 #43
Workflow file for this run
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: Release | |
on: | |
push: | |
tags: | |
- "v[0-9]+.[0-9]+.[0-9]+" | |
# Just used for testing | |
pull_request: | |
branches: | |
- main | |
paths: | |
- ".github/workflows/release.yml" | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
permissions: | |
contents: write | |
defaults: | |
run: | |
shell: bash | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- ubuntu-latest | |
- macos-latest | |
# - windows-latest | |
arch: | |
- x86_64 | |
- aarch64 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Install Cross | |
if: matrix.arch == 'aarch64' && matrix.os == 'ubuntu-latest' | |
uses: taiki-e/install-action@v2 | |
with: | |
tool: cross | |
- name: Setup environment | |
run: | | |
if [ "${{ matrix.os }}" = "macos-latest" ]; then | |
CARGO_CMD=cargo | |
CARGO_BUILD_TARGET="${{ matrix.arch }}-apple-darwin" | |
rustup target add $CARGO_BUILD_TARGET | |
else | |
if [ "${{ matrix.arch }}" = "aarch64" ]; then | |
CARGO_CMD=cross | |
else | |
CARGO_CMD=cargo | |
fi | |
CARGO_BUILD_TARGET="${{ matrix.arch }}-unknown-linux-gnu" | |
fi | |
echo "CARGO_CMD=$CARGO_CMD" >> $GITHUB_ENV | |
echo "CARGO_BUILD_TARGET=$CARGO_BUILD_TARGET" >> $GITHUB_ENV | |
- name: Build | |
run: | | |
$CARGO_CMD build --release --locked --package maa-cli | |
- name: Checkout version branch | |
uses: actions/checkout@v3 | |
with: | |
ref: version | |
path: version | |
- name: Archive binaries, generate checksums and update version.json | |
id: archive | |
run: | | |
version_file="$PWD/version/version.json" | |
target="$CARGO_BUILD_TARGET" | |
version=$(yq -oy ".package.version" maa-cli/Cargo.toml) | |
cd "target/$target/release" || exit 1 | |
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then | |
archive_name="maa_cli-v$version-$target.tar.gz" | |
tar -czvf $archive_name maa || exit 1 | |
yq -i -oj ".maa-cli.$target.size = $(stat -c %s $archive_name)" $version_file | |
else | |
archive_name="maa_cli-v$version-$target.zip" | |
zip $archive_name maa || exit 1 | |
yq -i -oj ".maa-cli.$target.size = $(stat -f %z $archive_name)" $version_file | |
fi | |
checksum="$(shasum -a 256 $archive_name)" | |
echo "$checksum" > $archive_name.sha256sum | |
yq -i -oj ".maa-cli.$target.version = \"$version\"" $version_file | |
yq -i -oj ".maa-cli.$target.tag = \"v$version\"" $version_file | |
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" $version_file | |
yq -i -oj ".maa-cli.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file | |
echo "name=v$version" >> $GITHUB_OUTPUT | |
- name: Upload to GitHub Releases | |
if: github.event_name == 'push' && github.ref == 'refs/tags/v*' | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
release_name: ${{ steps.archive.outputs.name }} | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file_glob: true | |
file: target/*/release/maa.*z* | |
overwrite: true | |
- name: Commit and push version.json | |
if: github.event_name == 'push' && github.ref == 'refs/tags/v*' | |
run: | | |
cd version || exit 1 | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
if [ -z "$(git diff version.json)" ]; then | |
echo "No changes to commit" | |
exit 1 | |
fi | |
git commit version.json -m "Update version.json" && | |
git push | |
universal-apple-darwin: | |
runs-on: macos-latest | |
needs: build | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Get tag | |
run: | | |
echo "MAA_CLI_VERSION=$(yq -oy ".package.version" maa-cli/Cargo.toml)" >> $GITHUB_ENV | |
- name: Download artifacts from GitHub Release | |
uses: robinraju/[email protected] | |
with: | |
tag: "v${{ env.MAA_CLI_VERSION }}" | |
filename: maa_cli-v${{ env.MAA_CLI_VERSION }}-*-apple-darwin.zip | |
- name: Checkout version branch | |
uses: actions/checkout@v3 | |
with: | |
ref: version | |
path: version | |
- name: Create universal binaries, archive, generate checksums and update version.json | |
id: archive | |
run: | | |
version_file="$PWD/version/version.json" | |
version=$MAA_CLI_VERSION | |
for arch in x86_64 aarch64; do | |
mkdir -p "arch-apple-darwin" | |
unzip maa_cli-v$version-$arch-apple-darwin.zip -d arch-apple-darwin | |
done | |
target="universal-apple-darwin" | |
archive_name="maa_cli-v$version-$target.zip" | |
lipo -create -output maa x86_64-apple-darwin/release/maa aarch64-apple-darwin/release/maa && | |
zip $archive_name maa && | |
checksum=$(shasum -a 256 $archive_name) && | |
echo "$checksum" > $archive_name.sha256sum && | |
yq -i -oj ".maa-cli.$target.version = \"$version\"" $version_file && | |
yq -i -oj ".maa-cli.$target.tag = \"v$version\"" $version_file && | |
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" $version_file && | |
yq -i -oj ".maa-cli.$target.size = $(stat -f %z $archive_name)" $version_file && | |
yq -i -oj ".maa-cli.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file && | |
echo "name=v$version" >> $GITHUB_OUTPUT && | |
exit 0 | |
- name: Upload to GitHub Releases | |
uses: svenstaro/upload-release-action@v2 | |
if: github.event_name == 'push' && github.ref == 'refs/tags/v*' | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file_glob: true | |
file: target/maa*.zip* | |
overwrite: true | |
- name: Commit and push version.json | |
if: github.event_name == 'push' && github.ref == 'refs/tags/v*' | |
run: | | |
cd version || exit 1 | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
if [ -z "$(git diff version.json)" ]; then | |
echo "No changes to commit" | |
exit 0 | |
fi | |
git commit version.json -m "Update version.json" && git push |