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 Python code in this PR
    # 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 }}
      CODEFLASH_PR_NUMBER: ${{ github.event.number }}
    {{ working_directory }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - {{ setup_python_dependency_manager }}
      - name: Install Project Dependencies
        run: {{ install_dependencies_command }}
      - name: Run Codeflash to optimize code
        run: {{ codeflash_command }}
