click-rs 1.0.2

A Rust port of Python's Click library for creating command-line interfaces
Documentation
name: release

on:
  push:
    tags:
      - "v*"

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Tests
        env:
          CARGO_INCREMENTAL: "0"
        run: cargo test --all-features

  parity:
    runs-on: ubuntu-latest
    # Parity vs Python is a dev/PR quality check, not a release gate (and the harness
    # references the pre-rename `click` package). Non-blocking so releases aren't gated on it.
    continue-on-error: true
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Install Python dependencies
        run: python3 -m pip install --upgrade pip && python3 -m pip install -r tests/parity/requirements.txt
      - name: Parity tests
        env:
          CARGO_INCREMENTAL: "0"
        run: |
          bash tests/parity/run_parity.sh phase1
          bash tests/parity/run_parity.sh phase2
          bash tests/parity/run_parity.sh phase3
          bash tests/parity/run_parity.sh phase4
          bash tests/parity/run_parity.sh phase5
          bash tests/parity/run_parity.sh phase6

  package:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Package (dry run)
        env:
          CARGO_INCREMENTAL: "0"
        run: cargo package

  publish:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
    needs: [test, package]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Read crate version
        id: crate_version
        run: |
          set -euo pipefail
          version=$(cargo metadata --no-deps --format-version 1 | \
            python3 -c "import json,sys; pkgs=json.load(sys.stdin)['packages']; print(next(p['version'] for p in pkgs if p['name']=='click-rs'))")
          echo "version=$version" >> "$GITHUB_OUTPUT"
      - name: Check if version exists on crates.io
        id: version_check
        run: |
          set -euo pipefail
          version="${{ steps.crate_version.outputs.version }}"
          if curl -sfL -A "release-workflow (https://github.com/mrsaraiva)" "https://crates.io/api/v1/crates/click-rs/${version}"; then
            echo "exists=true" >> "$GITHUB_OUTPUT"
          else
            echo "exists=false" >> "$GITHUB_OUTPUT"
          fi
      - name: Skip publish (version exists)
        if: steps.version_check.outputs.exists == 'true'
        run: echo "crate version already published; skipping cargo publish"
      - name: Authenticate with crates.io
        id: auth
        uses: rust-lang/crates-io-auth-action@v1
        if: steps.version_check.outputs.exists != 'true'
      # NOTE: click-derive must already be published to crates.io (it is a dependency of
      # click-rs). Publish it once manually, then this workflow publishes click-rs on tags.
      - name: Publish to crates.io
        env:
          CARGO_INCREMENTAL: "0"
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
        run: cargo publish -p click-rs --locked
        if: steps.version_check.outputs.exists != 'true'

  create-release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    needs: [test, package, publish]
    steps:
      - uses: actions/checkout@v4
      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true