jsonl-tui 0.1.0

Terminal explorer for JSONL files: search, filter, sort, group and export from your keyboard or mouse.
name: CI

on:
  push:
    branches: [master]
  pull_request:

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    name: Test & lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy --all-targets -- -D warnings
      - run: cargo test

  # Runs on every push to master. If the version in Cargo.toml has no matching
  # git tag yet, it publishes to crates.io and creates a GitHub release with
  # Linux binaries. Bump the version in Cargo.toml to cut a release.
  #
  # Required repository secret: CARGO_REGISTRY_TOKEN (crates.io API token).
  release:
    name: Publish & release
    needs: test
    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: x86_64-unknown-linux-gnu,x86_64-unknown-linux-musl

      - uses: Swatinem/rust-cache@v2

      - name: Read crate version
        id: version
        run: |
          V=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
          echo "version=$V" >> "$GITHUB_OUTPUT"

      - name: Check if this version is already released
        id: check
        run: |
          if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
            echo "new=false" >> "$GITHUB_OUTPUT"
            echo "v${{ steps.version.outputs.version }} already tagged — nothing to do."
          else
            echo "new=true" >> "$GITHUB_OUTPUT"
          fi

      - name: Install musl tools
        if: steps.check.outputs.new == 'true'
        run: sudo apt-get update && sudo apt-get install -y musl-tools

      - name: Build Linux binaries
        if: steps.check.outputs.new == 'true'
        run: |
          cargo build --release --locked --target x86_64-unknown-linux-gnu
          cargo build --release --locked --target x86_64-unknown-linux-musl
          mkdir -p dist
          for target in x86_64-unknown-linux-gnu x86_64-unknown-linux-musl; do
            strip "target/$target/release/jsonl-tui"
            tar -C "target/$target/release" -czf "dist/jsonl-tui-$target.tar.gz" jsonl-tui
          done
          (cd dist && sha256sum ./*.tar.gz > SHA256SUMS)

      - name: Publish to crates.io
        if: steps.check.outputs.new == 'true'
        run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Create GitHub release
        if: steps.check.outputs.new == 'true'
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{ steps.version.outputs.version }}
          name: v${{ steps.version.outputs.version }}
          files: |
            dist/*.tar.gz
            dist/SHA256SUMS
          generate_release_notes: true