formula-example 0.0.1

Simple example binary for Homebrew formula testing
name: CI

on:
    push:
        branches: ["main"]
        tags: ["v[0-9]+.[0-9]+.[0-9]+-?*"]

concurrency:
    cancel-in-progress: false
    group: "${{ github.workflow }}-${{ github.ref }}"

env:
    CARGO_TERM_COLOR: "always"
    RUSTUP_MAX_RETRIES: "10"
    NAME: "formula-example"
    RUST_VERSION: "1.63"

jobs:
    check:
        defaults:
            run:
                shell: bash
        permissions:
            contents: write
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v4

            - uses: actions-rust-lang/setup-rust-toolchain@v1
              with:
                  components: clippy, rustfmt
                  toolchain: "${{ env.RUST_VERSION }}"

            - name: Check
              run: |
                  cargo clippy --all-features --all-targets --locked -- --deny warnings
                  cargo fmt --all --check

    build:
        if: github.ref_type == 'tag'
        defaults:
            run:
                shell: bash
        runs-on: "${{ matrix.os }}"
        strategy:
            fail-fast: false
            matrix:
                include:
                    - os: macos-15
                      rust-target: aarch64-apple-darwin
                    - os: ubuntu-24.04-arm
                      rust-target: aarch64-unknown-linux-gnu
                    - os: macos-13
                      rust-target: x86_64-apple-darwin
                    - os: ubuntu-24.04
                      rust-target: x86_64-unknown-linux-gnu
        steps:
            - uses: actions/checkout@v4
            - uses: actions-rust-lang/setup-rust-toolchain@v1
              with:
                  target: "${{ matrix.rust-target }}"
                  toolchain: "${{ env.RUST_VERSION }}"

            - name: Build
              run: cargo build --locked --release --target '${{ matrix.rust-target }}'
            - name: Package
              run: |
                  DIST_PATH="dist/native/${NAME}-${{ matrix.rust-target }}-${{ github.ref_name }}.tgz"

                  mkdir -p dist/native/
                  tar -vvczf "${DIST_PATH}" -C 'target/${{ matrix.rust-target }}/release' "${NAME}"
                  openssl 'sha256' "${DIST_PATH}" \
                  | jq -cR '{ "sha256-${{ matrix.rust-target }}": .[-64:] }' \
                  > "${DIST_PATH}.meta.json"

            - uses: actions/upload-artifact@v4
              with:
                  name: "native-${{ matrix.rust-target }}"
                  path: dist/native/

    publish:
        if: github.ref_type == 'tag'
        defaults:
            run:
                shell: bash
        needs: ["build", "check"]
        permissions:
            contents: write
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v4
            - uses: actions/download-artifact@v4
              with:
                  path: dist/
                  pattern: native-*

            - name: Publish to github.com
              env:
                  GH_TOKEN: "${{ github.token }}"
              run: |
                  gh release delete --yes '${{ github.ref_name }}' || true
                  gh release create --generate-notes '${{ github.ref_name }}' dist/native-*/*.tgz

            - id: homebrew-prepare
              name: Publish to Homebrew (Prepare)
              run: |
                  ( printf 'inputs=' && \
                    cargo metadata --format-version 1 --locked \
                      --manifest-path Cargo.toml --no-deps \
                    | jq -cs '
                      [ ( .[0].packages.[0]
                          | { description, homepage, license,
                              name, repository, version } ),
                        ( .[1:] | add ) ]
                      | add
                      | with_entries(select(.value != null))
                      | { dict: . | debug | @json, name }' \
                      - dist/native-*/*.tgz.meta.json ) \
                  >> "${GITHUB_OUTPUT}"
            - name: Publish to Homebrew
              uses: the-actions-org/workflow-dispatch@v4
              with:
                  display-workflow-run-url-interval: 10s
                  inputs: "${{ steps.homebrew-prepare.outputs.inputs }}"
                  ref: main
                  repo: AsherJingkongChen/homebrew--
                  token: "${{ secrets.HOMEBREW_TOKEN }}"
                  wait-for-completion-interval: 30s
                  wait-for-completion: true
                  workflow-logs: ignore
                  workflow: publish.yml

            - name: Publish to crates.io
              env:
                  CARGO_REGISTRY_TOKEN: "${{ secrets.CRATE_TOKEN }}"
              run: cargo publish --locked --package "${NAME}" --no-verify --verbose