lx-ls 0.10.1

The file lister with personality! 🌟
name: Release
on:
  push:
    tags: ["v*"]

jobs:
  build:
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-22.04
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            cross: true
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - name: Install cross
        if: matrix.cross
        uses: taiki-e/install-action@cross
      - name: Build (cross)
        if: matrix.cross
        run: cross build --release --features jj --target ${{ matrix.target }}
      - name: Build (native)
        if: ${{ !matrix.cross }}
        run: cargo build --release --features jj --target ${{ matrix.target }}
      - name: Rename binary with target triple
        run: |
          mkdir -p dist
          cp target/${{ matrix.target }}/release/lx dist/lx-${{ matrix.target }}
      - uses: actions/upload-artifact@v7
        with:
          name: lx-${{ matrix.target }}
          path: dist/lx-${{ matrix.target }}

  release:
    needs: [build]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v6
      - uses: actions/download-artifact@v8
        with:
          merge-multiple: true
      - name: Stage man pages for release
        run: cp man/lx.1 man/lxconfig.toml.5 .
      - uses: softprops/action-gh-release@v3
        with:
          files: |
            lx-*
            lx.1
            lxconfig.toml.5
          generate_release_notes: true

  publish-crate:
    needs: release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_LX_LS }}

  update-homebrew:
    needs: release
    runs-on: ubuntu-latest
    env:
      TAG: ${{ github.ref_name }}
    steps:
      - uses: actions/checkout@v6
        with:
          repository: wjv/homebrew-tap
          token: ${{ secrets.HOMEBREW_LX_LS }}
      - name: Update formula
        run: |
          VERSION="${TAG#v}"
          BASE="https://github.com/wjv/lx/releases/download/${TAG}"

          # Fetch checksums for release assets.
          for target in x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu x86_64-apple-darwin aarch64-apple-darwin; do
            sha=$(curl -sL "${BASE}/lx-${target}" | sha256sum | cut -d' ' -f1)
            eval "SHA_$(echo "$target" | tr '-' '_')=$sha"
          done
          SHA_MAN1=$(curl -sL "${BASE}/lx.1" | sha256sum | cut -d' ' -f1)
          SHA_MAN5=$(curl -sL "${BASE}/lxconfig.toml.5" | sha256sum | cut -d' ' -f1)

          cat > Formula/lx.rb <<RUBY
          class Lx < Formula
            desc "A modern file lister with personality"
            homepage "https://github.com/wjv/lx"
            version "${VERSION}"
            license "MIT"

            on_macos do
              if Hardware::CPU.arm?
                url "${BASE}/lx-aarch64-apple-darwin"
                sha256 "${SHA_aarch64_apple_darwin}"
              else
                url "${BASE}/lx-x86_64-apple-darwin"
                sha256 "${SHA_x86_64_apple_darwin}"
              end
            end

            on_linux do
              if Hardware::CPU.arm?
                url "${BASE}/lx-aarch64-unknown-linux-gnu"
                sha256 "${SHA_aarch64_unknown_linux_gnu}"
              else
                url "${BASE}/lx-x86_64-unknown-linux-gnu"
                sha256 "${SHA_x86_64_unknown_linux_gnu}"
              end
            end

            resource "man-lx" do
              url "${BASE}/lx.1"
              sha256 "${SHA_MAN1}"
            end

            resource "man-lxconfig" do
              url "${BASE}/lxconfig.toml.5"
              sha256 "${SHA_MAN5}"
            end

            def install
              bin.install Dir["lx-*"].first => "lx"
              chmod 0755, bin/"lx"
              resource("man-lx").stage { man1.install "lx.1" }
              resource("man-lxconfig").stage { man5.install "lxconfig.toml.5" }

              generate_completions_from_executable(bin/"lx", "--completions")
            end

            test do
              assert_match "lx #{version}", shell_output("#{bin}/lx --version")
            end
          end
          RUBY

          # Remove leading whitespace from heredoc.
          sed -i 's/^          //' Formula/lx.rb
      - name: Commit and push
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Formula/lx.rb
          git commit -m "Update lx to ${TAG#v}"
          git push