|
| 1 | +name: test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["*"] |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Install uv |
| 17 | + uses: astral-sh/setup-uv@v2 |
| 18 | + |
| 19 | + - name: Set up Python |
| 20 | + run: uv python install 3.12 |
| 21 | + |
| 22 | + - name: Install dependencies |
| 23 | + run: uv pip install -e ".[dev,test]" |
| 24 | + |
| 25 | + - name: Run black |
| 26 | + run: uv run black --check src/ tests/ |
| 27 | + |
| 28 | + - name: Run ruff |
| 29 | + run: uv run ruff check src/ tests/ |
| 30 | + |
| 31 | + - name: Run mypy |
| 32 | + run: uv run mypy src/ |
| 33 | + |
| 34 | + test: |
| 35 | + runs-on: ${{ matrix.os }} |
| 36 | + strategy: |
| 37 | + fail-fast: false |
| 38 | + matrix: |
| 39 | + os: [ubuntu-latest] |
| 40 | + python-version: ["3.9", "3.10", "3.11", "3.12"] |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout code |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Install uv |
| 47 | + uses: astral-sh/setup-uv@v2 |
| 48 | + |
| 49 | + - name: Set up Python ${{ matrix.python-version }} |
| 50 | + run: uv python install ${{ matrix.python-version }} |
| 51 | + |
| 52 | + - name: Install dependencies |
| 53 | + run: uv pip install -e ".[test]" |
| 54 | + |
| 55 | + - name: Run pytest |
| 56 | + run: uv run pytest tests/unit/ -v --cov --cov-report=xml --cov-report=term-missing |
| 57 | + |
| 58 | + - name: Upload coverage to Codecov |
| 59 | + uses: codecov/codecov-action@v4 |
| 60 | + if: matrix.python-version == '3.12' |
| 61 | + with: |
| 62 | + file: ./coverage.xml |
| 63 | + fail_ci_if_error: false |
| 64 | + continue-on-error: true |
| 65 | + |
| 66 | + integration-tests: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + # Don't block PRs if integration tests fail (API may be down, rate limits, etc.) |
| 69 | + continue-on-error: true |
| 70 | + |
| 71 | + steps: |
| 72 | + - name: Checkout code |
| 73 | + uses: actions/checkout@v4 |
| 74 | + |
| 75 | + - name: Install uv |
| 76 | + uses: astral-sh/setup-uv@v2 |
| 77 | + |
| 78 | + - name: Set up Python |
| 79 | + run: uv python install 3.12 |
| 80 | + |
| 81 | + - name: Install dependencies |
| 82 | + run: uv pip install -e ".[test]" |
| 83 | + |
| 84 | + - name: Run integration tests |
| 85 | + if: ${{ secrets.GROQ_API_KEY != '' }} |
| 86 | + env: |
| 87 | + GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} |
| 88 | + run: uv run pytest tests/integration/ -m integration -v |
| 89 | + |
| 90 | + performance: |
| 91 | + runs-on: ubuntu-latest |
| 92 | + # Run on main branch commits and PRs |
| 93 | + if: github.event_name == 'push' || github.event_name == 'pull_request' |
| 94 | + |
| 95 | + steps: |
| 96 | + - name: Checkout code |
| 97 | + uses: actions/checkout@v4 |
| 98 | + with: |
| 99 | + # Fetch enough history to compare with previous commit |
| 100 | + fetch-depth: 2 |
| 101 | + |
| 102 | + - name: Install uv |
| 103 | + uses: astral-sh/setup-uv@v2 |
| 104 | + |
| 105 | + - name: Set up Python |
| 106 | + run: uv python install 3.12 |
| 107 | + |
| 108 | + - name: Install dependencies |
| 109 | + run: uv pip install -e ".[test]" |
| 110 | + |
| 111 | + - name: Create benchmarks directory |
| 112 | + run: mkdir -p .benchmarks |
| 113 | + |
| 114 | + - name: Run performance benchmarks |
| 115 | + run: | |
| 116 | + uv run pytest tests/performance/test_benchmarks.py \ |
| 117 | + --benchmark-only \ |
| 118 | + --benchmark-json=.benchmarks/current.json \ |
| 119 | + --benchmark-columns=min,max,mean,stddev,median,ops \ |
| 120 | + --benchmark-sort=name |
| 121 | +
|
| 122 | + - name: Download previous benchmark results |
| 123 | + uses: actions/cache@v4 |
| 124 | + with: |
| 125 | + path: .benchmarks/baseline.json |
| 126 | + key: benchmark-baseline-${{ github.ref }}-${{ github.sha }} |
| 127 | + restore-keys: | |
| 128 | + benchmark-baseline-${{ github.ref }}- |
| 129 | + benchmark-baseline-refs/heads/main- |
| 130 | +
|
| 131 | + - name: Compare with baseline |
| 132 | + if: hashFiles('.benchmarks/baseline.json') != '' |
| 133 | + run: | |
| 134 | + uv run pytest tests/performance/test_benchmarks.py \ |
| 135 | + --benchmark-only \ |
| 136 | + --benchmark-compare=.benchmarks/baseline.json \ |
| 137 | + --benchmark-compare-fail=mean:20% || true |
| 138 | +
|
| 139 | + - name: Store benchmark results as baseline |
| 140 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 141 | + run: | |
| 142 | + cp .benchmarks/current.json .benchmarks/baseline.json |
| 143 | +
|
| 144 | + - name: Upload benchmark results |
| 145 | + uses: actions/upload-artifact@v4 |
| 146 | + with: |
| 147 | + name: benchmark-results |
| 148 | + path: .benchmarks/current.json |
| 149 | + retention-days: 90 |
| 150 | + |
| 151 | + - name: Comment PR with benchmark results |
| 152 | + if: github.event_name == 'pull_request' |
| 153 | + uses: actions/github-script@v7 |
| 154 | + continue-on-error: true |
| 155 | + with: |
| 156 | + script: | |
| 157 | + const fs = require('fs'); |
| 158 | + const results = JSON.parse(fs.readFileSync('.benchmarks/current.json', 'utf8')); |
| 159 | +
|
| 160 | + let comment = '## 📊 Performance Benchmark Results\n\n'; |
| 161 | + comment += '| Benchmark | Mean | Ops/sec |\n'; |
| 162 | + comment += '|-----------|------|----------|\n'; |
| 163 | +
|
| 164 | + results.benchmarks.forEach(b => { |
| 165 | + const name = b.name.replace('test_benchmark_', '').replace('test_', ''); |
| 166 | + const mean = (b.stats.mean * 1000000).toFixed(2); // Convert to µs |
| 167 | + const ops = (b.stats.ops / 1000).toFixed(2); // Convert to K ops/sec |
| 168 | + comment += `| ${name} | ${mean} µs | ${ops}K |\n`; |
| 169 | + }); |
| 170 | +
|
| 171 | + comment += '\n*All benchmarks run with pytest-benchmark (100 iterations, 10 rounds)*'; |
| 172 | +
|
| 173 | + github.rest.issues.createComment({ |
| 174 | + issue_number: context.issue.number, |
| 175 | + owner: context.repo.owner, |
| 176 | + repo: context.repo.repo, |
| 177 | + body: comment |
| 178 | + }); |
0 commit comments