droidtui 0.2.6

A beautiful Terminal User Interface (TUI) for Android development and ADB commands
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  packages: write

jobs:
  test:
    name: Test on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

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

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2

      - name: Check formatting
        if: matrix.os == 'ubuntu-latest'
        run: cargo fmt --all -- --check

      - name: Run clippy
        run: cargo clippy -- -D warnings -A deprecated

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

  build:
    name: Build and release
    needs: test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2

      - name: Install cliff
        run: cargo install git-cliff

      - name: Update version and generate changelog
        run: |
          # Extract version from tag (remove 'v' prefix)
          VERSION=${GITHUB_REF_NAME#v}
          echo "Updating version to: $VERSION"

          # Update Cargo.toml version
          sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml

          # Update full changelog with git-cliff
          git-cliff --config cliff.toml --latest --output CHANGELOG.md

          # Generate release notes with git-cliff
          LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")

          # Generate release changelog using git-cliff
          if [ -n "$LAST_TAG" ]; then
            # Generate changelog between tags
            git-cliff --config cliff.toml ${LAST_TAG}..${{ github.ref_name }} --strip header > CLIFF_CHANGES.md
          else
            # Generate changelog for first release
            git-cliff --config cliff.toml --tag ${{ github.ref_name }} --strip header > CLIFF_CHANGES.md
          fi

          # Create the release note template
          echo "# DroidTUI ${VERSION}" > RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "## 🚀 What's New" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md

          if [ -n "$LAST_TAG" ]; then
            echo "### 📝 Changes since ${LAST_TAG}:" >> RELEASE_CHANGELOG.md
            echo "" >> RELEASE_CHANGELOG.md
          else
            echo "### 🎉 Initial Release" >> RELEASE_CHANGELOG.md
            echo "" >> RELEASE_CHANGELOG.md
          fi

          # Add the git-cliff generated changes to the release notes
          cat CLIFF_CHANGES.md >> RELEASE_CHANGELOG.md

          # Add installation and quick start info
          echo "" >> RELEASE_CHANGELOG.md
          echo "## 📦 Installation" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "```bash" >> RELEASE_CHANGELOG.md
          echo "cargo install droidtui" >> RELEASE_CHANGELOG.md
          echo "```" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "## 🚀 Quick Start" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "```bash" >> RELEASE_CHANGELOG.md
          echo "# Run DroidTUI" >> RELEASE_CHANGELOG.md
          echo "droidtui" >> RELEASE_CHANGELOG.md
          echo "" >> RELEASE_CHANGELOG.md
          echo "# Navigate with vim-style keys" >> RELEASE_CHANGELOG.md
          echo "# Use j/k or arrow keys to navigate" >> RELEASE_CHANGELOG.md
          echo "# Press Enter or → to enter sub-menus" >> RELEASE_CHANGELOG.md
          echo "# Press Esc or q to quit" >> RELEASE_CHANGELOG.md
          echo "```" >> RELEASE_CHANGELOG.md

          # Show the generated release notes
          echo "Generated release notes:"
          cat RELEASE_CHANGELOG.md

      - name: Build release
        run: cargo build --release

      - name: Package binary
        run: |
          tar -C target/release -czvf droidtui-${{ github.ref_name }}-linux-x86_64.tar.gz droidtui

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v1
        with:
          body_path: RELEASE_CHANGELOG.md
          files: |
            droidtui-${{ github.ref_name }}-linux-x86_64.tar.gz
            LICENSE
            README.md
            CHANGELOG.md
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Publish to crates.io
        if: env.CRATES_IO_TOKEN != ''
        env:
          CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
        run: |
          echo "Publishing to crates.io..."
          cargo publish --token $CRATES_IO_TOKEN --allow-dirty

      - name: Skip crates.io publish
        if: env.CRATES_IO_TOKEN == ''
        env:
          CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
        run: |
          echo "⚠️  CRATES_IO_TOKEN not set. Skipping crates.io publication."
          echo "To publish to crates.io, add CRATES_IO_TOKEN to your GitHub secrets."