rsread 0.1.4

Fast multi-language code reader: structure tree, syntax highlighting, duplicate detection and Git change markers for Python, Rust, Go and JavaScript
name: Release

# Push a tag like v0.1.0 (must match the version in Cargo.toml).
on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+*"

permissions:
  contents: write

jobs:
  verify:
    name: verify tag
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Tag must match Cargo.toml version
        run: |
          crate_ver=$(grep -m1 '^version' Cargo.toml | cut -d '"' -f2)
          tag_ver="${GITHUB_REF_NAME#v}"
          echo "Cargo.toml: $crate_ver / tag: $tag_ver"
          if [ "$crate_ver" != "$tag_ver" ]; then
            echo "::error::tag $GITHUB_REF_NAME does not match Cargo.toml version $crate_ver"
            exit 1
          fi

  build:
    needs: verify
    uses: ./.github/workflows/build.yml

  release:
    name: publish GitHub release
    # Publish whatever was built, even when some targets failed (only a cancelled run or a bad tag stops it).
    needs: [verify, build]
    if: ${{ !cancelled() && needs.verify.result == 'success' }}
    runs-on: ubuntu-latest
    steps:
      - name: Build status
        if: needs.build.result != 'success'
        run: |
          echo "::warning::some build targets failed (build result ${{ needs.build.result }}), publishing the targets that succeeded"

      - uses: actions/download-artifact@v4
        with:
          pattern: rsread-*
          merge-multiple: true
          path: dist

      - name: Require at least one artifact
        run: |
          count=$(find dist -type f | wc -l)
          echo "artifacts: $count"
          if [ "$count" -eq 0 ]; then
            echo "::error::no build produced an artifact, nothing to release"
            exit 1
          fi

      - name: Checksums
        working-directory: dist
        run: |
          sha256sum * > SHA256SUMS.txt
          cat SHA256SUMS.txt

      - uses: softprops/action-gh-release@v2
        with:
          files: dist/*
          generate_release_notes: true
          prerelease: ${{ contains(github.ref_name, '-') }}

  crates-io:
    name: publish to crates.io (optional)
    needs: release
    runs-on: ubuntu-latest
    env:
      CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Publish
        run: |
          if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
            echo "CARGO_REGISTRY_TOKEN not set, skipping crates.io publish"
            exit 0
          fi
          cargo publish --locked