Skip to content

ci: workflow to update homebrew #3

ci: workflow to update homebrew

ci: workflow to update homebrew #3

name: Publish Homebrew
on:
release:
types: [published]
pull_request:
branches:
- main
paths:
- ".github/workflows/publish-homebrew.yml"
workflow_dispatch:
inputs:
dryrun:
description: Don't create PR to homebrew
default: true
required: true
type: boolean
defaults:
run:
shell: bash
permissions:
contents: read
jobs:
meta:
runs-on: ubuntu-latest
outputs:
dryrun: ${{ steps.dryrun.outputs.dryrun }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if Dryrun
id: dryrun
run: |
if [ "$GITHUB_EVENT_NAME" = "release" ]; then
dryrun=false
elif [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
dryrun=${{ inputs.dryrun }}
else
dryrun=true
fi
echo "Dryrun: $dryrun"
echo "dryrun=$dryrun" >> $GITHUB_OUTPUT
- name: Get Version
id: version
run: |
CARGO_VERSION=$(yq -oy ".package.version" maa-cli/Cargo.toml)
# check if version is equal to tag if not PR
if [ "$GITHUB_EVENT_NAME" != "pull_request" ]; then
REF=${{ github.ref }}
REF_VERSION=${REF#refs/tags/v}
if [ "$REF_VERSION" != "$CARGO_VERSION" ]; then
echo "Version mismatch: $REF_VERSION != $CARGO_VERSION"
fi
fi
echo "Get version: $CARGO_VERSION"
echo "version=$CARGO_VERSION" >> $GITHUB_OUTPUT
build:
name: Build and Release Cask
runs-on: macos-latest
needs: meta
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
run: |
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
- name: Build
run: >
cargo build --release --locked --package maa-cli
--no-default-features
--target x86_64-apple-darwin --target aarch64-apple-darwin
- name: Create Universal Binary
working-directory: target
run: >
lipo -create -output maa
x86_64-apple-darwin/release/maa
aarch64-apple-darwin/release/maa
- name: Tarball Binary and Share
run: |
version=${{ needs.meta.outputs.version }}
mkdir maa
cp -vR target/maa maa-cli/share maa/
tar -czf maa-cli-v$version-cask.tar.gz maa
- name: Upload to Release
if: ${{ needs.meta.outputs.dryrun }} == false
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.meta.outputs.version }}
files: maa-cli-v${{ needs.meta.outputs.version }}-cask.tar.gz
fail_on_unmatched_files: true
- name: Upload to Artifact (Dryrun)
if: ${{ needs.meta.outputs.dryrun }} == true
uses: actions/upload-artifact@v3
with:
name: homebrew-cask
path: maa-cli-v${{ needs.meta.outputs.version }}-cask.tar.gz
retention-days: 1
bump-cask:
name: Bump Cask and Open PR
runs-on: macos-latest
needs: [meta, build]
steps:
- name: Update Homebrew Cask
uses: wangl-cc/action-homebrew-bump-cask@master
with:
token: ${{secrets.MAA_HOMEBREW_BUMP_PR}}
tap: MaaAssistantArknights/homebrew-tap
cask: maa-cli-bin
tag: v${{ needs.meta.outputs.version }}
no_fork: true
force: false
dryrun: ${{ needs.meta.outputs.dryrun }}
bump-formula:
name: Bump Formula and Open PR
runs-on: macos-latest
needs: [meta]
steps:
- name: Update Homebrew Formula
uses: dawidd6/action-homebrew-bump-formula@v3
with:
token: ${{secrets.MAA_HOMEBREW_BUMP_PR}}
tap: MaaAssistantArknights/homebrew-tap
formula: maa-cli
tag: v${{ needs.meta.outputs.version }}
no_fork: true
force: false
dyrun: ${{ needs.meta.outputs.dryrun }}