onde-cli 0.2.0

Terminal UI for signing up, signing in, and managing your Onde Inference account.
name: Release crates.io

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: release-crates-${{ github.ref }}
  cancel-in-progress: false

env:
  CARGO_TERM_COLOR: always
  ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
  ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
  GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
  GRESIQ_API_SECRET: ${{ secrets.GRESIQ_API_SECRET }}

jobs:
  verify:
    name: Verify release
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.package.outputs.version }}
      tag: ${{ steps.tag.outputs.tag }}
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt

      - name: Cache cargo registry and build artifacts
        uses: Swatinem/rust-cache@v2

      - name: Read package version
        id: package
        shell: bash
        run: |
          version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)"
          if [ -z "$version" ]; then
            echo "Failed to read package version from Cargo.toml" >&2
            exit 1
          fi
          echo "version=$version" >> "$GITHUB_OUTPUT"

      - name: Read git tag version
        id: tag
        shell: bash
        run: |
          ref="${GITHUB_REF_NAME}"
          tag="${ref#v}"
          echo "tag=$tag" >> "$GITHUB_OUTPUT"

      - name: Ensure tag matches Cargo.toml version
        if: github.event_name == 'push'
        shell: bash
        run: |
          test "${{ steps.package.outputs.version }}" = "${{ steps.tag.outputs.tag }}"

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Run clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Run tests
        run: cargo test --all-features --locked --verbose

      - name: Run cargo check
        run: cargo check --locked

      - name: Verify package contents
        run: cargo package --locked --allow-dirty

  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: verify
    environment:
      name: crates-io
    permissions:
      contents: read
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo registry and build artifacts
        uses: Swatinem/rust-cache@v2

      - name: Publish crate
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --locked

  github-release:
    name: Create GitHub release
    runs-on: ubuntu-latest
    needs:
      - verify
      - publish
    if: github.event_name == 'push'
    permissions:
      contents: write
    steps:
      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{ needs.verify.outputs.version }}
          generate_release_notes: true
          name: onde-cli v${{ needs.verify.outputs.version }}