askr 0.1.7

Interactive CLI input tool with real-time validation and choice menus
Documentation
name: Release

on:
  push:
    tags:
      - 'v*.*.*'

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  create-release:
    name: Create Release
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.get_version.outputs.version }}
    steps:
    - name: Get version from tag
      id: get_version
      run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

    - name: Create Release
      id: create_release
      uses: softprops/action-gh-release@v1
      with:
        tag_name: ${{ github.ref }}
        name: Release ${{ github.ref }}
        draft: false
        prerelease: false

  build-assets:
    name: Build release assets
    needs: create-release
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            asset_name: askr-linux-x86_64
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            asset_name: askr-linux-x86_64-musl
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            asset_name: askr-windows-x86_64.exe
          - os: macos-latest
            target: x86_64-apple-darwin
            asset_name: askr-macos-x86_64
          - os: macos-latest
            target: aarch64-apple-darwin
            asset_name: askr-macos-aarch64

    steps:
    - uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}

    - name: Install musl tools
      if: matrix.target == 'x86_64-unknown-linux-musl'
      run: sudo apt-get update && sudo apt-get install -y musl-tools

    - name: Build
      run: cargo build --release --target ${{ matrix.target }}

    - name: Prepare asset (Unix)
      if: matrix.os != 'windows-latest'
      run: |
        cp target/${{ matrix.target }}/release/askr ${{ matrix.asset_name }}
        strip ${{ matrix.asset_name }} || true

    - name: Prepare asset (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        copy target\${{ matrix.target }}\release\askr.exe ${{ matrix.asset_name }}

    - name: Upload Release Asset
      uses: softprops/action-gh-release@v1
      with:
        files: ./${{ matrix.asset_name }}

  publish-crate:
    name: Publish to crates.io
    needs: create-release
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Wait for CI workflow to complete
      run: |
        echo "Waiting for CI workflow to complete..."
        sleep 30

        # Check if CI workflow completed successfully using gh CLI
        MAX_ATTEMPTS=30
        ATTEMPT=0

        while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
          CI_STATUS=$(gh run list --workflow=ci --commit=${{ github.sha }} --json status,conclusion --jq '.[0].conclusion' || echo "pending")
          echo "Attempt $((ATTEMPT + 1)): CI workflow status: $CI_STATUS"

          if [ "$CI_STATUS" = "success" ]; then
            echo "CI workflow completed successfully!"
            break
          elif [ "$CI_STATUS" = "failure" ] || [ "$CI_STATUS" = "cancelled" ]; then
            echo "CI workflow failed with status: $CI_STATUS"
            exit 1
          fi

          echo "Waiting 10 seconds before checking again..."
          sleep 10
          ATTEMPT=$((ATTEMPT + 1))
        done

        if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
          echo "Timeout waiting for CI workflow to complete"
          exit 1
        fi
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

    - name: Publish to crates.io
      run: cargo publish
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}