babysit 0.3.1

Wrap a shell command in a PTY and expose it to external AI agents (Claude / Codex) via subcommands
name: Release

on:
  workflow_dispatch:
  push:
    branches: [main]
    paths:
      - 'Cargo.toml'

permissions:
  contents: write

jobs:
  check-version:
    name: Check Version
    runs-on: ubuntu-latest
    outputs:
      should_release: ${{ steps.check.outputs.should_release }}
      version: ${{ steps.version.outputs.version }}
      tag: ${{ steps.version.outputs.tag }}

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Get version from Cargo.toml
        id: version
        run: |
          VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "tag=v$VERSION" >> $GITHUB_OUTPUT

      - name: Check if tag exists
        id: check
        run: |
          if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
            echo "Tag already exists, skipping release"
            echo "should_release=false" >> $GITHUB_OUTPUT
          else
            echo "New version detected, will release"
            echo "should_release=true" >> $GITHUB_OUTPUT
          fi

  publish:
    name: Publish to crates.io
    needs: check-version
    if: needs.check-version.outputs.should_release == 'true'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  build:
    name: Build ${{ matrix.target }}
    needs: check-version
    if: needs.check-version.outputs.should_release == 'true'
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: aarch64-apple-darwin
            os: macos-14
            asset: babysit-aarch64-darwin
          - target: x86_64-apple-darwin
            os: macos-15-intel
            asset: babysit-x86_64-darwin
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            asset: babysit-x86_64-linux
          - target: aarch64-unknown-linux-musl
            os: ubuntu-latest
            asset: babysit-aarch64-linux
            use_cross: true
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - name: Install musl-tools (Linux x86_64)
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: sudo apt-get update && sudo apt-get install -y musl-tools
      - name: Install cross (for cross-compilation)
        if: matrix.use_cross
        run: cargo install cross --git https://github.com/cross-rs/cross
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}
      - name: Build (native)
        if: ${{ !matrix.use_cross }}
        run: cargo build --release --target ${{ matrix.target }}
      - name: Build (cross)
        if: matrix.use_cross
        run: cross build --release --target ${{ matrix.target }}
      - name: Rename binary
        run: cp target/${{ matrix.target }}/release/babysit ${{ matrix.asset }}
      - name: Generate SHA256 checksum
        run: |
          if [[ "$RUNNER_OS" == "macOS" ]]; then
            shasum -a 256 ${{ matrix.asset }} > ${{ matrix.asset }}.sha256
          else
            sha256sum ${{ matrix.asset }} > ${{ matrix.asset }}.sha256
          fi
      - uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.asset }}
          path: |
            ${{ matrix.asset }}
            ${{ matrix.asset }}.sha256

  release:
    name: Create Release
    needs: [check-version, build]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Create tag
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git tag -a "${{ needs.check-version.outputs.tag }}" -m "Release ${{ needs.check-version.outputs.tag }}"
          git push origin "${{ needs.check-version.outputs.tag }}"

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: Prepare release files
        run: |
          mkdir -p release
          for dir in artifacts/*/; do
            cp "$dir"* release/
          done
          ls -la release/

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.check-version.outputs.tag }}
          files: release/*
          generate_release_notes: true
          draft: false
          prerelease: ${{ contains(needs.check-version.outputs.version, '-') }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}