cc-switch 0.1.37

Switch between multiple Claude / Codex configurations. Optional daemon proxies traffic to a built-in dashboard — requests, conversations, token stats. Cross-platform.
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@v5

    - 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@v5
      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@v5
      with:
        fetch-depth: 0

    - name: Download all artifacts
      uses: actions/download-artifact@v5
      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
          BREAK_LOG=""
          FEAT_LOG=""
          FIX_LOG=""
          OTHER_LOG=""

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

            # Conventional Commits breaking marker: `<type>!:` or `<type>(<scope>)!:`
            if echo "$msg" | grep -qE '^[a-z]+(\([^)]*\))?!:'; then
              BREAK_LOG="$BREAK_LOG\n- $msg (\`$hash\`)"
              continue
            fi

            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 "$BREAK_LOG" ]; then
            CHANGELOG="$CHANGELOG\n> ⚠️ **This release contains breaking changes.** Review the items below before upgrading.\n\n### 💥 Breaking Changes\n$BREAK_LOG\n"
          fi
          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@v2
      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

    - name: Update Homebrew formula
      env:
        GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
      run: |
        VERSION="${GITHUB_REF#refs/tags/v}"

        # Read sha256 from sidecar files
        SHA_AARCH64_DARWIN=$(cat artifacts/cc-switch-aarch64-apple-darwin.tar.gz/cc-switch-aarch64-apple-darwin.tar.gz.sha256)
        SHA_X86_64_DARWIN=$(cat artifacts/cc-switch-x86_64-apple-darwin.tar.gz/cc-switch-x86_64-apple-darwin.tar.gz.sha256)
        SHA_AARCH64_LINUX=$(cat artifacts/cc-switch-aarch64-unknown-linux-gnu.tar.gz/cc-switch-aarch64-unknown-linux-gnu.tar.gz.sha256)
        SHA_X86_64_LINUX=$(cat artifacts/cc-switch-x86_64-unknown-linux-gnu.tar.gz/cc-switch-x86_64-unknown-linux-gnu.tar.gz.sha256)

        # Generate formula
        cat > /tmp/cc-switch.rb <<FORMULA
        class CcSwitch < Formula
          desc "A CLI tool for managing multiple Claude API configurations and automatically switching between them"
          homepage "https://github.com/Linuxdazhao/cc_auto_switch"
          version "${VERSION}"
          license "MIT"

          if OS.mac?
            if Hardware::CPU.arm?
              url "https://github.com/Linuxdazhao/cc_auto_switch/releases/download/v#{version}/cc-switch-aarch64-apple-darwin.tar.gz"
              sha256 "${SHA_AARCH64_DARWIN}"
            else
              url "https://github.com/Linuxdazhao/cc_auto_switch/releases/download/v#{version}/cc-switch-x86_64-apple-darwin.tar.gz"
              sha256 "${SHA_X86_64_DARWIN}"
            end
          elsif OS.linux?
            if Hardware::CPU.arm?
              url "https://github.com/Linuxdazhao/cc_auto_switch/releases/download/v#{version}/cc-switch-aarch64-unknown-linux-gnu.tar.gz"
              sha256 "${SHA_AARCH64_LINUX}"
            else
              url "https://github.com/Linuxdazhao/cc_auto_switch/releases/download/v#{version}/cc-switch-x86_64-unknown-linux-gnu.tar.gz"
              sha256 "${SHA_X86_64_LINUX}"
            end
          end

          def install
            bin.install "cc-switch"
          end

          test do
            assert_match "cc-switch", shell_output("#{bin}/cc-switch --help")
            assert_match version.to_s, shell_output("#{bin}/cc-switch --version")
          end

          def caveats
            <<~EOS
              To use cc-switch effectively:

              1. Add configurations:
                 cc-switch add my-config TOKEN_HERE https://api.anthropic.com

              2. Switch between configurations:
                 cc-switch use my-config

              3. Interactive mode:
                 cc-switch current

              4. Shell completion:
                 # For fish
                 cc-switch completion fish > ~/.config/fish/completions/cc-switch.fish

                 # For zsh
                 cc-switch completion zsh > ~/.zsh/completions/_cc-switch

                 # For bash
                 cc-switch completion bash > ~/.bash_completion.d/cc-switch

              For more information, visit: https://github.com/Linuxdazhao/cc_auto_switch
            EOS
          end
        end
        FORMULA

        # Remove leading whitespace (heredoc indentation)
        sed -i 's/^        //' /tmp/cc-switch.rb

        # Push to homebrew tap repo via API
        CONTENT=$(base64 -w 0 /tmp/cc-switch.rb)
        EXISTING_SHA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
          "https://api.github.com/repos/Linuxdazhao/homebrew-cc-switch/contents/Formula/cc-switch.rb" \
          | jq -r '.sha')

        curl -s -X PUT \
          -H "Authorization: token $GITHUB_TOKEN" \
          -H "Content-Type: application/json" \
          "https://api.github.com/repos/Linuxdazhao/homebrew-cc-switch/contents/Formula/cc-switch.rb" \
          -d "{\"message\":\"chore: bump cc-switch to ${VERSION}\",\"content\":\"${CONTENT}\",\"sha\":\"${EXISTING_SHA}\"}" \
          | jq -r '.commit.sha'

        echo "✅ Homebrew formula updated to ${VERSION}"