|
| 1 | +name: Python CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths-ignore: |
| 6 | + - "**.md" |
| 7 | + - "LICENSE" |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 18 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 19 | + |
| 20 | +jobs: |
| 21 | + lint: |
| 22 | + name: Lint and Format |
| 23 | + runs-on: ubuntu-latest |
| 24 | + timeout-minutes: 10 |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v6 |
| 27 | + |
| 28 | + - uses: astral-sh/setup-uv@v7 |
| 29 | + with: |
| 30 | + enable-cache: true |
| 31 | + |
| 32 | + - name: Pin Python version |
| 33 | + run: uv python pin 3.12 |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: uv sync --extra dev |
| 37 | + |
| 38 | + - name: Lint with Ruff |
| 39 | + run: uv run ruff check src/ |
| 40 | + |
| 41 | + - name: Check formatting |
| 42 | + run: uv run ruff format --check src/ |
| 43 | + |
| 44 | + type-check: |
| 45 | + name: Type Check |
| 46 | + runs-on: ubuntu-latest |
| 47 | + timeout-minutes: 10 |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v6 |
| 50 | + |
| 51 | + - uses: astral-sh/setup-uv@v7 |
| 52 | + with: |
| 53 | + enable-cache: true |
| 54 | + |
| 55 | + - name: Pin Python version |
| 56 | + run: uv python pin 3.12 |
| 57 | + |
| 58 | + - name: Install dependencies |
| 59 | + run: uv sync --extra dev |
| 60 | + |
| 61 | + - name: Type check with mypy |
| 62 | + run: uv run mypy src/promptfoo/ |
| 63 | + |
| 64 | + test: |
| 65 | + name: Test Python ${{ matrix.python-version }} |
| 66 | + runs-on: ${{ matrix.os }} |
| 67 | + timeout-minutes: 15 |
| 68 | + strategy: |
| 69 | + matrix: |
| 70 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 71 | + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v6 |
| 74 | + |
| 75 | + - uses: actions/setup-node@v4 |
| 76 | + with: |
| 77 | + node-version: "20" |
| 78 | + |
| 79 | + - uses: astral-sh/setup-uv@v7 |
| 80 | + with: |
| 81 | + enable-cache: true |
| 82 | + |
| 83 | + - name: Pin Python version |
| 84 | + run: uv python pin ${{ matrix.python-version }} |
| 85 | + |
| 86 | + - name: Install package |
| 87 | + run: uv pip install -e . |
| 88 | + |
| 89 | + - name: Test CLI can be invoked |
| 90 | + run: uv run promptfoo --version |
| 91 | + |
| 92 | + - name: Test Node.js detection |
| 93 | + run: uv run python -c "from promptfoo.cli import check_node_installed, check_npx_installed; assert check_node_installed(); assert check_npx_installed()" |
| 94 | + |
| 95 | + build: |
| 96 | + name: Build Package |
| 97 | + runs-on: ubuntu-latest |
| 98 | + timeout-minutes: 10 |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v6 |
| 101 | + |
| 102 | + - uses: astral-sh/setup-uv@v7 |
| 103 | + with: |
| 104 | + enable-cache: true |
| 105 | + |
| 106 | + - name: Pin Python version |
| 107 | + run: uv python pin 3.12 |
| 108 | + |
| 109 | + - name: Build package |
| 110 | + run: uv build |
| 111 | + |
| 112 | + - name: Upload artifacts |
| 113 | + uses: actions/upload-artifact@v6 |
| 114 | + with: |
| 115 | + name: dist |
| 116 | + path: dist/ |
| 117 | + |
| 118 | + ci-success: |
| 119 | + name: CI Success |
| 120 | + needs: [lint, type-check, test, build] |
| 121 | + if: always() |
| 122 | + runs-on: ubuntu-latest |
| 123 | + steps: |
| 124 | + - name: Check if all jobs succeeded |
| 125 | + run: | |
| 126 | + LINT_RESULT="${{ needs.lint.result }}" |
| 127 | + TYPE_CHECK_RESULT="${{ needs.type-check.result }}" |
| 128 | + TEST_RESULT="${{ needs.test.result }}" |
| 129 | + BUILD_RESULT="${{ needs.build.result }}" |
| 130 | +
|
| 131 | + echo "Job results:" |
| 132 | + echo " lint: $LINT_RESULT" |
| 133 | + echo " type-check: $TYPE_CHECK_RESULT" |
| 134 | + echo " test: $TEST_RESULT" |
| 135 | + echo " build: $BUILD_RESULT" |
| 136 | +
|
| 137 | + if [[ "$LINT_RESULT" == "failure" || "$LINT_RESULT" == "cancelled" || |
| 138 | + "$TYPE_CHECK_RESULT" == "failure" || "$TYPE_CHECK_RESULT" == "cancelled" || |
| 139 | + "$TEST_RESULT" == "failure" || "$TEST_RESULT" == "cancelled" || |
| 140 | + "$BUILD_RESULT" == "failure" || "$BUILD_RESULT" == "cancelled" ]]; then |
| 141 | + echo "Some CI checks failed!" |
| 142 | + exit 1 |
| 143 | + else |
| 144 | + echo "All CI checks passed!" |
| 145 | + exit 0 |
| 146 | + fi |
0 commit comments