iftoprs 2.22.8

Real-time bandwidth monitor — iftop clone in Rust with ratatui TUI, 31 themes, process attribution, mouse support
Documentation
name: Release

on:
  push:
    tags: ['v*']
  workflow_dispatch:
    inputs:
      tag:
        description: 'Tag to build (e.g. v2.22.5)'
        required: true
        type: string

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    # Per-target failures are tolerated on the flaky variants so the
    # downstream publish + tap job ships from whichever targets did
    # build. `needs: build` is satisfied either way.
    continue-on-error: ${{ matrix.allow_failure || false }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # --- macOS native ---
          - os: macos-latest
            target: aarch64-apple-darwin
          - os: macos-latest
            target: x86_64-apple-darwin
          # --- Linux glibc native ---
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-gnu
            # Native aarch64 runner. cross-rs's xenial-based Docker
            # image apt repos no longer ship libpcap-dev:arm64, so the
            # `pcap` crate fails to link inside the container. Native
            # arm64 runner has libpcap-dev in apt directly.
          # --- Linux musl static (portable across glibc/musl distros) ---
          # libpcap is dynamically linked on glibc; musl static builds
          # may fail without a vendored static libpcap. allow_failure
          # covers that — the glibc tarballs still ship.
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            allow_failure: true
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-musl
            allow_failure: true
    steps:
      - uses: actions/checkout@v6

      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Install musl tools
        if: contains(matrix.target, 'musl') && !matrix.use_cross
        run: sudo apt-get update && sudo apt-get install -y musl-tools

      - name: Install libpcap (Linux glibc)
        if: runner.os == 'Linux' && !contains(matrix.target, 'musl') && !matrix.use_cross
        run: sudo apt-get update && sudo apt-get install -y libpcap-dev

      - name: Install native deps for aarch64-linux-gnu (libpcap)
        if: matrix.target == 'aarch64-unknown-linux-gnu' && !matrix.use_cross
        run: |
          sudo apt-get update
          sudo apt-get install -y libpcap-dev

      - name: Install libpcap (Linux musl)
        if: contains(matrix.target, 'musl') && !matrix.use_cross
        run: sudo apt-get update && sudo apt-get install -y libpcap-dev

      - name: Install cross
        if: matrix.use_cross
        run: |
          # Prefer the prebuilt binary release over `cargo install`
          # to save ~5 min of compile time per cross-build runner.
          # libpcap-dev:arm64 is installed inside the Docker image
          # via the repo's Cross.toml `pre-build` directives.
          CROSS_VER="v0.2.5"
          curl -sSL -o /tmp/cross.tar.gz \
            "https://github.com/cross-rs/cross/releases/download/${CROSS_VER}/cross-x86_64-unknown-linux-gnu.tar.gz"
          tar -C /tmp -xzf /tmp/cross.tar.gz
          sudo install -m 755 /tmp/cross /usr/local/bin/cross

      - uses: Swatinem/rust-cache@v2
        if: '!matrix.use_cross'

      - name: Build (native)
        if: '!matrix.use_cross'
        run: cargo build --release --locked --target ${{ matrix.target }}

      - name: Build (cross)
        if: matrix.use_cross
        run: cross build --release --locked --target ${{ matrix.target }}

      - name: Package
        shell: bash
        run: |
          cd target/${{ matrix.target }}/release
          for b in iftoprs; do
            strip "$b" 2>/dev/null || true
          done
          tar czf ../../../iftoprs-${{ github.ref_name }}-${{ matrix.target }}.tar.gz iftoprs
          cd ../../..

      - uses: actions/upload-artifact@v6
        with:
          name: iftoprs-${{ matrix.target }}
          path: iftoprs-${{ github.ref_name }}-${{ matrix.target }}.tar.gz

  publish:
    name: Publish GitHub Release
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      - name: Create GitHub Release
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          gh release create ${{ github.ref_name }} \
            --title "${{ github.ref_name }}" \
            --generate-notes \
            artifacts/*.tar.gz

  homebrew:
    name: Update Homebrew tap
    needs: publish
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      - name: Compute SHA256 sums
        id: sha
        shell: bash
        run: |
          for f in artifacts/*.tar.gz; do
            base=$(basename "$f")
            sum=$(sha256sum "$f" | awk '{print $1}')
            # e.g. iftoprs-vX.Y.Z-aarch64-apple-darwin.tar.gz → aarch64_apple_darwin
            key=$(echo "$base" | sed 's/iftoprs-v[^-]*-//; s/\.tar\.gz//; s/-/_/g; s/\./_/g')
            echo "${key}=${sum}" >> "$GITHUB_OUTPUT"
          done

      - uses: actions/checkout@v6
        with:
          repository: MenkeTechnologies/homebrew-menketech
          token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
          path: tap

      - name: Update formula
        shell: bash
        env:
          VERSION: ${{ github.ref_name }}
          SHA_ARM_MACOS: ${{ steps.sha.outputs.aarch64_apple_darwin }}
          SHA_X86_MACOS: ${{ steps.sha.outputs.x86_64_apple_darwin }}
          SHA_X86_LINUX: ${{ steps.sha.outputs.x86_64_unknown_linux_gnu }}
          SHA_ARM_LINUX: ${{ steps.sha.outputs.aarch64_unknown_linux_gnu }}
          SHA_X86_LINUX_MUSL: ${{ steps.sha.outputs.x86_64_unknown_linux_musl }}
          SHA_ARM_LINUX_MUSL: ${{ steps.sha.outputs.aarch64_unknown_linux_musl }}
        run: |
          set -eu
          V="${VERSION#v}"
          BASE="https://github.com/MenkeTechnologies/iftoprs/releases/download/v${V}"
          # Helper: emit an on_arm / on_intel block when its SHA is non-empty.
          emit() { local guard="$1" arch="$2" sha="$3"; [ -n "$sha" ] || return 0; printf '    %s do\n      url "%s/iftoprs-v%s-%s.tar.gz"\n      sha256 "%s"\n    end\n' "$guard" "$BASE" "$V" "$arch" "$sha"; }
          # Build per-OS blocks first; skip the whole on_macos/on_linux
          # block if zero arches succeeded for that OS.
          mac_blocks=$( { emit on_arm aarch64-apple-darwin "$SHA_ARM_MACOS"; emit on_intel x86_64-apple-darwin "$SHA_X86_MACOS"; } )
          linux_blocks=$( { emit on_intel x86_64-unknown-linux-gnu "$SHA_X86_LINUX"; emit on_arm aarch64-unknown-linux-gnu "$SHA_ARM_LINUX"; } )
          {
            printf 'class Iftoprs < Formula\n'
            printf '  desc "Real-time bandwidth monitor — Rust iftop clone with ratatui TUI, 31 themes"\n'
            printf '  homepage "https://github.com/MenkeTechnologies/iftoprs"\n'
            printf '  license "MIT"\n'
            printf '  version "%s"\n\n' "$V"
            if [ -n "$mac_blocks" ]; then
              printf '  on_macos do\n%s\n  end\n\n' "$mac_blocks"
            fi
            if [ -n "$linux_blocks" ]; then
              printf '  on_linux do\n%s\n  end\n\n' "$linux_blocks"
            fi
            printf '  def install\n'
            printf '    bin.install "iftoprs"\n'
            printf '  end\n\n'
            printf '  test do\n'
            printf '    assert_match "iftoprs", shell_output("#{bin}/iftoprs --version")\n'
            printf '  end\n'
            # musl tarballs as trailing comment — Homebrew has no
            # on_libc gate, so static binaries are referenced by URL
            # for users targeting Alpine / scratch / distroless.
            if [ -n "$SHA_X86_LINUX_MUSL" ] || [ -n "$SHA_ARM_LINUX_MUSL" ]; then
              printf '\n  # Static musl tarballs also published at this release:\n'
              [ -n "$SHA_X86_LINUX_MUSL" ] && printf '  #   iftoprs-v%s-x86_64-unknown-linux-musl.tar.gz  sha256: %s\n' "$V" "$SHA_X86_LINUX_MUSL"
              [ -n "$SHA_ARM_LINUX_MUSL" ] && printf '  #   iftoprs-v%s-aarch64-unknown-linux-musl.tar.gz  sha256: %s\n' "$V" "$SHA_ARM_LINUX_MUSL"
            fi
            printf 'end\n'
          } > tap/Formula/iftoprs.rb

      - name: Push formula update
        run: |
          cd tap
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Formula/iftoprs.rb
          if git diff --cached --quiet; then
            echo "no changes — formula already up to date"
            exit 0
          fi
          git commit -m "iftoprs: bump to ${{ github.ref_name }}"
          git push