Skip to content

ci: fix release workflow #49

ci: fix release workflow

ci: fix release workflow #49

Workflow file for this run

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"
defaults:
run:
shell: bash
permissions:
contents: read
jobs:
version:
name: Get Version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get Version
run: |
VERSION=$(yq -oy ".package.version" maa-cli/Cargo.toml)
echo "version=$VERSION" >> $GITHUB_ENV
build:
name: Build
runs-on: ${{ matrix.os }}
needs: version
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 and Archive
run: |
$CARGO_CMD build --release --locked --package maa-cli
cd "target/$CARGO_BUILD_TARGET/release"
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
archive_name="maa_cli-v$version-$target.tar.gz"
tar -czvf $archive_name maa
else
archive_name="maa_cli-v$version-$target.zip"
zip $archive_name maa
fi
echo "file_path=$PWD/$archive_name" >> $GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: maa_cli-v${{ needs.version.outputs.version }}-${{ env.CARGO_BUILD_TARGET }}
path: ${{ steps.archive.outputs.file_path }}
retention-days: 1
build-universal:
name: Build macOS universal binary
runs-on: macos-latest
needs: [version, build]
steps:
# download all artifacts, even if not all are used,
# because this action don't support wildcards
- name: Download Artifacts
uses: actions/download-artifact@v3
- name: Create universal binaries and Archive
id: archive
run: |
version=${{ needs.version.outputs.version }}
for arch in x86_64 aarch64; do
target="$arch-apple-darwin"
zipfile="maa_cli-v$version-$target.zip"
mkdir "$target" && unzip -d "$target" "$zipfile"
done
target="universal-apple-darwin"
archive_name="maa_cli-v$version-$target.zip"
lipo -create -output maa x86_64-apple-darwin/maa aarch64-apple-darwin/maa
zip $archive_name maa
echo "file_path=$PWD/$archive_name" >> $GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: maa_cli-v${{ needs.version.outputs.version }}-universal-apple-darwin
path: ${{ steps.archive.outputs.file_path }}
retention-days: 1
release:
runs-on: ubuntu-latest
needs: [version, build, build-universal-apple-darwin]

Check failure on line 121 in .github/workflows/release.yml

View workflow run for this annotation

GitHub Actions / Release

Invalid workflow file

The workflow is not valid. .github/workflows/release.yml (Line: 121, Col: 29): Job 'release' depends on unknown job 'build-universal-apple-darwin'.
permissions:
contents: write
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
- name: Checkout version branch (Release)
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: actions/checkout@v3
with:
ref: version
path: version
- name: Checkout version branch (Test)
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
with:
ref: version-test
path: version
- name: Extract files, Generate checksums and Update version.json
run: |
version=${{ needs.version.outputs.version }}
for target in x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu universal-apple-darwin; do
if [ "$target" == "universal-apple-darwin" ]; then
archive_name="maa_cli-v$version-$target.zip"
else
archive_name="maa_cli-v$version-$target.tar.gz"
fi
checksum=$(sha256sum $archive_name)
size=$(stat -c%s $archive_name)
checksum_hash=$(echo $checksum | cut -d ' ' -f 1)
echo $checksum > $archive_name.sha256sum
version_file="version/version.json"
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 = $size" $version_file
yq -i -oj ".maa-cli.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file
done
- name: Create Release
uses: softprops/action-gh-release@v1
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
with:
name: v${{ needs.version.outputs.version }}
body: |
# maa-cli v${{ needs.version.outputs.version }}
## Changelog
$(git log --pretty=format:"* %s" $(git describe --tags --abbrev=0)..HEAD)
fail_on_unmatched_files: true
files: |
maa_cli-v${{ needs.version.outputs.version }}-x86_64-unknown-linux-gnu.tar.gz*
maa_cli-v${{ needs.version.outputs.version }}-aarch64-unknown-linux-gnu.tar.gz*
maa_cli-v${{ needs.version.outputs.version }}-universal-apple-darwin.zip*
- name: Commit version.json and Push
run: |
cd version
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit version.json -m "Update version.json"
git push