mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-12-23 09:19:52 +00:00
Reduce CI job count by only running examples on Python 3.13 instead of all Python versions (3.10-3.13). This reduces the combinatorial explosion while still ensuring examples work on the latest Python version. Co-authored-by: Claude <noreply@anthropic.com>
151 lines
4.3 KiB
YAML
151 lines
4.3 KiB
YAML
name: Test
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- "main"
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -e ".[dev]"
|
|
|
|
- name: Run tests
|
|
run: |
|
|
python -m pytest tests/ -v --cov=claude_agent_sdk --cov-report=xml
|
|
|
|
- name: Upload coverage to Codecov
|
|
uses: codecov/codecov-action@v4
|
|
with:
|
|
file: ./coverage.xml
|
|
fail_ci_if_error: false
|
|
|
|
test-e2e:
|
|
runs-on: ${{ matrix.os }}
|
|
needs: test # Run after unit tests pass
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Install Claude Code (Linux/macOS)
|
|
if: runner.os == 'Linux' || runner.os == 'macOS'
|
|
run: |
|
|
curl -fsSL https://claude.ai/install.sh | bash
|
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
|
|
- name: Install Claude Code (Windows)
|
|
if: runner.os == 'Windows'
|
|
run: |
|
|
irm https://claude.ai/install.ps1 | iex
|
|
$claudePath = "$env:USERPROFILE\.local\bin"
|
|
echo "$claudePath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
|
shell: pwsh
|
|
|
|
- name: Verify Claude Code installation
|
|
run: claude -v
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -e ".[dev]"
|
|
|
|
- name: Run end-to-end tests with real API
|
|
env:
|
|
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
run: |
|
|
python -m pytest e2e-tests/ -v -m e2e
|
|
|
|
test-examples:
|
|
runs-on: ubuntu-latest
|
|
needs: test-e2e # Run after e2e tests
|
|
strategy:
|
|
matrix:
|
|
python-version: ["3.13"]
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Install Claude Code (Linux)
|
|
if: runner.os == 'Linux'
|
|
run: |
|
|
curl -fsSL https://claude.ai/install.sh | bash
|
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
|
|
- name: Install Claude Code (Windows)
|
|
if: runner.os == 'Windows'
|
|
run: |
|
|
irm https://claude.ai/install.ps1 | iex
|
|
$claudePath = "$env:USERPROFILE\.local\bin"
|
|
echo "$claudePath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
|
shell: pwsh
|
|
|
|
- name: Verify Claude Code installation
|
|
run: claude -v
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -e .
|
|
|
|
- name: Run example scripts (Linux)
|
|
if: runner.os == 'Linux'
|
|
env:
|
|
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
run: |
|
|
python examples/quick_start.py
|
|
timeout 120 python examples/streaming_mode.py all
|
|
timeout 120 python examples/hooks.py PreToolUse
|
|
timeout 120 python examples/hooks.py DecisionFields
|
|
|
|
- name: Run example scripts (Windows)
|
|
if: runner.os == 'Windows'
|
|
env:
|
|
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
run: |
|
|
python examples/quick_start.py
|
|
$job = Start-Job { python examples/streaming_mode.py all }
|
|
Wait-Job $job -Timeout 120 | Out-Null
|
|
Stop-Job $job
|
|
Receive-Job $job
|
|
|
|
$job = Start-Job { python examples/hooks.py PreToolUse }
|
|
Wait-Job $job -Timeout 120 | Out-Null
|
|
Stop-Job $job
|
|
Receive-Job $job
|
|
|
|
$job = Start-Job { python examples/hooks.py DecisionFields }
|
|
Wait-Job $job -Timeout 120 | Out-Null
|
|
Stop-Job $job
|
|
Receive-Job $job
|
|
shell: pwsh
|