name: Codeflash

on:
  pull_request:
    paths:
      # So that this workflow only runs when code within the target module is modified
      - '{{ codeflash_module_path }}'
  workflow_dispatch:

concurrency:
  # Any new push to the PR will cancel the previous run, so that only the latest code is optimized
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true


jobs:
  optimize:
    name: Optimize new code
    # Don't run codeflash on codeflash-ai[bot] commits, prevent duplicate optimizations
    if: ${{ github.actor != 'codeflash-ai[bot]' }}
    runs-on: ubuntu-latest
    env:
      CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
    {{ working_directory }}
    steps:
      - name: 🛎️ Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: 🐍 Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - name: 📦 Setup uv
        uses: astral-sh/setup-uv@v4
      {{ setup_runtime_steps }}
      - name: 📦 Install Dependencies
        run: {{ install_dependencies_command }}
      {{ install_codeflash_step }}
      - name: ⚡️ Codeflash Optimization
        run: {{ codeflash_command }}
