name: end-to-end-test

on:
  pull_request:
  workflow_dispatch:

jobs:
  bubble-sort-optimization-pytest-no-git:
    runs-on: ubuntu-latest
    env:
      CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
      COLUMNS: 110
      CODEFLASH_END_TO_END: 1
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Set up Python 3.11
        uses: actions/setup-python@v5
        with:
          python-version: 3.11.6
      - name: Remove .git
        run: |
          if [ -d ".git" ]; then
            echo ".git directory exists!"
            sudo rm -rf .git
            if [ -d ".git" ]; then
              echo ".git directory still exists after removal attempt!"
              exit 1
            else
              echo ".git directory successfully removed."
            fi
          else
            echo ".git directory does not exist. Nothing to remove."
            exit 1
          fi
      - name: Install dependencies
        run: |
          cd ./cli
          python -m pip install --upgrade pip
          pip install poetry
          poetry install --with dev

      - name: Run Codeflash to optimize code
        id: optimize_code
        run: |
          cd ./cli
          poetry env use python
          poetry run python tests/scripts/end_to_end_test_bubblesort_pytest.py