|
| 1 | +name: Codeflash Optimization |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + paths: |
| 5 | + - 'pydantic_ai_slim/pydantic_ai/**' |
| 6 | + workflow_dispatch: |
| 7 | +concurrency: |
| 8 | + # Any new push to the PR will cancel the previous run, so that only the latest code is optimized |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | +jobs: |
| 12 | + optimize: |
| 13 | + name: Optimize new Python code |
| 14 | + # Don't run codeflash on codeflash-ai[bot] commits, prevent duplicate optimizations |
| 15 | + if: ${{ github.actor != 'codeflash-ai[bot]' }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }} |
| 19 | + steps: |
| 20 | + - name: 🛎️ Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + - name: 🐍 Setup UV |
| 25 | + uses: astral-sh/setup-uv@v6 |
| 26 | + with: |
| 27 | + enable-cache: true |
| 28 | + - uses: denoland/setup-deno@v2 |
| 29 | + with: |
| 30 | + deno-version: v2.x |
| 31 | + - name: 📦 Install Dependencies |
| 32 | + run: uv sync --frozen --all-extras --all-packages --group lint --group docs |
| 33 | + - name: Functions to Optimize |
| 34 | + id: discover_step |
| 35 | + run: | |
| 36 | + uv run python -c " |
| 37 | + from codeflash.cli_cmds.cli import parse_args, process_pyproject_config |
| 38 | + from codeflash.verification.verification_utils import TestConfig |
| 39 | + from codeflash.discovery.functions_to_optimize import get_functions_to_optimize |
| 40 | + import os |
| 41 | + args = process_pyproject_config(parse_args()) |
| 42 | + t = TestConfig(tests_root=args.tests_root, tests_project_rootdir=args.test_project_root, project_root_path=args.project_root, test_framework=args.test_framework, pytest_cmd=args.pytest_cmd,) |
| 43 | + f = get_functions_to_optimize(test_cfg=t, ignore_paths=args.ignore_paths, project_root=args.project_root, module_root=args.module_root,optimize_all=None, replay_test=None, file=None, only_get_this_function=None) |
| 44 | + functions = ' '.join([fto.function_name for ftol in f[0].values() for fto in ftol]) |
| 45 | + open(os.environ.get('GITHUB_OUTPUT'), 'a').write(f'functions_to_optimize={functions}') |
| 46 | + " |
| 47 | + - name: ⚡️Codeflash Optimization |
| 48 | + run: uv run codeflash optimize --only-functions ${{ steps.discover_step.outputs.functions_to_optimize }} -m pytest --inline-snapshot=disable tests/test_examples.py |
0 commit comments