cc-switch 0.1.27

A CLI tool for managing multiple Claude API configurations and automatically switching between them
Documentation
name: Release

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

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

permissions:
  contents: write

jobs:
  build:
    name: Build for ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            artifact_name: cc-switch-x86_64-unknown-linux-gnu.tar.gz
            binary_name: cc-switch
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            artifact_name: cc-switch-aarch64-unknown-linux-gnu.tar.gz
            binary_name: cc-switch
          - target: x86_64-apple-darwin
            os: macos-latest
            artifact_name: cc-switch-x86_64-apple-darwin.tar.gz
            binary_name: cc-switch
          - target: aarch64-apple-darwin
            os: macos-latest
            artifact_name: cc-switch-aarch64-apple-darwin.tar.gz
            binary_name: cc-switch
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            artifact_name: cc-switch-x86_64-pc-windows-msvc.zip
            binary_name: cc-switch.exe
          - target: aarch64-pc-windows-msvc
            os: windows-latest
            artifact_name: cc-switch-aarch64-pc-windows-msvc.zip
            binary_name: cc-switch.exe

    steps:
    - uses: actions/checkout@v4

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

    - name: Cache cargo + target
      uses: Swatinem/rust-cache@v2
      with:
        key: ${{ matrix.target }}

    - name: Add Linux dependencies
      if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu'
      run: |
        sudo apt-get update
        sudo apt-get install -y gcc-aarch64-linux-gnu

    - name: Set up cross compilation environment
      if: matrix.target == 'aarch64-unknown-linux-gnu'
      run: |
        echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV

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

    - name: Package artifacts (Unix)
      if: matrix.os != 'windows-latest'
      shell: bash
      run: |
        mkdir -p dist/${{ matrix.target }}
        cp target/${{ matrix.target }}/release/${{ matrix.binary_name }} dist/${{ matrix.target }}/${{ matrix.binary_name }}
        cd dist/${{ matrix.target }}
        tar -czf ../../${{ matrix.artifact_name }} ${{ matrix.binary_name }}

    - name: Package artifacts (Windows)
      if: matrix.os == 'windows-latest'
      shell: pwsh
      run: |
        $stage = "dist/${{ matrix.target }}"
        New-Item -ItemType Directory -Force -Path $stage | Out-Null
        Copy-Item "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "$stage/${{ matrix.binary_name }}"
        Compress-Archive -Path "$stage/${{ matrix.binary_name }}" -DestinationPath "${{ matrix.artifact_name }}" -Force

    - name: Generate SHA256 sidecar (Unix)
      if: matrix.os != 'windows-latest'
      shell: bash
      run: |
        shasum -a 256 ${{ matrix.artifact_name }} | awk '{print $1}' > ${{ matrix.artifact_name }}.sha256

    - name: Generate SHA256 sidecar (Windows)
      if: matrix.os == 'windows-latest'
      shell: pwsh
      run: |
        $hash = (Get-FileHash -Algorithm SHA256 "${{ matrix.artifact_name }}").Hash.ToLower()
        Set-Content -Path "${{ matrix.artifact_name }}.sha256" -Value $hash -NoNewline

    - name: Upload artifacts
      uses: actions/upload-artifact@v4
      with:
        name: ${{ matrix.artifact_name }}
        path: |
          ${{ matrix.artifact_name }}
          ${{ matrix.artifact_name }}.sha256

  release:
    name: Create Release
    needs: build
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')
    permissions:
      contents: write

    steps:
    - uses: actions/checkout@v4

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

    - name: Generate Release Notes
      id: notes
      run: |
        VERSION="${GITHUB_REF#refs/tags/}"
        PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")

        echo "version=$VERSION" >> $GITHUB_OUTPUT

        # Build changelog
        CHANGELOG="## What's Changed in $VERSION"
        CHANGELOG="$CHANGELOG\n"

        if [ -n "$PREV_TAG" ]; then
          # Get commits between previous tag and current
          FEAT_LOG=""
          FIX_LOG=""
          OTHER_LOG=""

          while IFS= read -r line; do
            hash=$(echo "$line" | cut -d' ' -f1)
            msg=$(echo "$line" | cut -d' ' -f2-)

            case "$msg" in
              feat\(*\)*|feat:*)
                FEAT_LOG="$FEAT_LOG\n- $msg (\`$hash\`)"
                ;;
              fix\(*\)*|fix:*)
                FIX_LOG="$FIX_LOG\n- $msg (\`$hash\`)"
                ;;
              chore:*|chore\(*\)*)
                # Skip chore commits (version bumps, lock updates)
                ;;
              *)
                OTHER_LOG="$OTHER_LOG\n- $msg (\`$hash\`)"
                ;;
            esac
          done < <(git log ${PREV_TAG}..HEAD --oneline --no-merges)

          if [ -n "$FEAT_LOG" ]; then
            CHANGELOG="$CHANGELOG\n### New Features\n$FEAT_LOG\n"
          fi
          if [ -n "$FIX_LOG" ]; then
            CHANGELOG="$CHANGELOG\n### Bug Fixes\n$FIX_LOG\n"
          fi
          if [ -n "$OTHER_LOG" ]; then
            CHANGELOG="$CHANGELOG\n### Other Changes\n$OTHER_LOG\n"
          fi

          CHANGELOG="$CHANGELOG\n**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${VERSION}"
        else
          CHANGELOG="$CHANGELOG\nInitial release."
        fi

        # Write to file for multiline body
        echo -e "$CHANGELOG" > release_notes.md

    - name: Create Release
      uses: softprops/action-gh-release@v1
      with:
        files: |
          artifacts/**/*.tar.gz
          artifacts/**/*.zip
          artifacts/**/*.sha256
        draft: false
        prerelease: false
        body_path: release_notes.md
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    - name: Create Release Summary
      run: |
        echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
        echo "" >> $GITHUB_STEP_SUMMARY
        echo "### 📦 Built Artifacts" >> $GITHUB_STEP_SUMMARY
        echo "" >> $GITHUB_STEP_SUMMARY
        echo "| Target | File |" >> $GITHUB_STEP_SUMMARY
        echo "|--------|------|" >> $GITHUB_STEP_SUMMARY
        
        shopt -s nullglob globstar
        for artifact in artifacts/**/*.tar.gz artifacts/**/*.zip; do
          if [ -f "$artifact" ]; then
            filename=$(basename "$artifact")
            target_name=$(echo "$filename" | sed -E 's/\.(tar\.gz|zip)$//')
            echo "| $target_name | $filename |" >> $GITHUB_STEP_SUMMARY
          fi
        done