macnetmon 0.1.5

Network interface bandwidth monitor for macOS
name: Release

on:
  push:
    tags: ["v*"]

permissions:
  contents: write

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

jobs:
  build:
    runs-on: macos-latest
    env:
      CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
          targets: aarch64-apple-darwin,x86_64-apple-darwin

      - uses: Swatinem/rust-cache@v2

      - name: Check formatting
        run: cargo fmt --check

      - name: Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Build universal macOS binary
        run: make build-universal

      - name: Verify version
        run: |
          CARGO_PKGID=$(cargo pkgid)
          CARGO_VERSION=${CARGO_PKGID##*@}
          CARGO_VERSION=${CARGO_VERSION##*#}
          TAG_VERSION=${GITHUB_REF_NAME#v}
          if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
            echo "Version mismatch: Cargo.toml=$CARGO_VERSION, tag=$TAG_VERSION"
            exit 1
          fi

      - name: Publish to crates.io
        if: ${{ env.CARGO_REGISTRY_TOKEN != '' }}
        run: cargo publish --locked

      - name: Create tarball
        run: |
          tar -czvf macnetmon-${{ github.ref_name }}.tar.gz -C target/universal-apple-darwin/release macnetmon -C ${{ github.workspace }} README.md LICENSE

      - name: Install git-cliff
        uses: taiki-e/install-action@v2
        with:
          tool: git-cliff

      - name: Generate changelog
        run: git cliff --latest --strip header > CHANGELOG.md

      - name: Create release
        uses: softprops/action-gh-release@v3
        with:
          files: macnetmon-${{ github.ref_name }}.tar.gz
          body_path: CHANGELOG.md
          generate_release_notes: false

      - name: Update Homebrew tap
        uses: mislav/bump-homebrew-formula-action@v4
        with:
          formula-name: macnetmon
          homebrew-tap: mdsakalu/homebrew-tap
          download-url: https://github.com/mdsakalu/macnetmon/releases/download/${{ github.ref_name }}/macnetmon-${{ github.ref_name }}.tar.gz
        env:
          COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}