|
1 | | -name: CI Pipeline |
| 1 | +# .github/workflows/ci.yml |
| 2 | +# Apex Technical Authority Standard CI/CD Pipeline (Python/uv/Ruff/Pytest) |
| 3 | + |
| 4 | +name: CI | Build, Test, and Lint |
2 | 5 |
|
3 | | -# Trigger the workflow on push events to the main branch and pull requests targeting the main branch. |
4 | 6 | on: |
5 | 7 | push: |
6 | | - branches: [ main ] |
| 8 | + branches: ["main"] |
7 | 9 | pull_request: |
8 | | - branches: [ main ] |
| 10 | + branches: ["main"] |
| 11 | + workflow_dispatch: |
9 | 12 |
|
10 | | -# Define environment variables for the workflow |
11 | | -env: |
12 | | - PYTHON_VERSION: '3.10' |
13 | | - REPO_NAME: 'Academic-Python-Lab-Solutions-Toolkit' |
14 | | - OWNER_NAME: 'chirag127' |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 15 | + cancel-in-progress: true |
15 | 16 |
|
16 | 17 | jobs: |
17 | 18 | build-and-test: |
18 | | - name: Build and Test |
19 | | - runs-on: ubuntu-latest # Use the latest Ubuntu runner |
| 19 | + name: Python ${{ matrix.python-version }} on ${{ matrix.os }} |
| 20 | + runs-on: ${{ matrix.os }} |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + os: [ubuntu-latest] |
| 25 | + python-version: ["3.10", "3.11", "3.12"] |
20 | 26 |
|
21 | 27 | steps: |
22 | | - # Step 1: Checkout the repository code |
23 | | - - name: Checkout repository |
| 28 | + - name: 1. | Check out repository |
24 | 29 | uses: actions/checkout@v4 |
25 | | - with: |
26 | | - fetch-depth: 0 # Fetch all history for accurate blame/coverage analysis |
27 | 30 |
|
28 | | - # Step 2: Set up Python environment |
29 | | - - name: Set up Python ${{ env.PYTHON_VERSION }} |
| 31 | + - name: 2. | Set up Python ${{ matrix.python-version }} |
30 | 32 | uses: actions/setup-python@v5 |
31 | 33 | with: |
32 | | - python-version: ${{ env.PYTHON_VERSION }} |
33 | | - cache: 'uv' |
| 34 | + python-version: ${{ matrix.python-version }} |
34 | 35 |
|
35 | | - # Step 3: Install dependencies using uv |
36 | | - - name: Install dependencies with uv |
37 | | - run: | |
38 | | - python -m uv pip install --system --upgrade pip |
39 | | - python -m uv pip install --system --all-extras # Installs all extras, including dev dependencies |
| 36 | + - name: 3. | Install uv (Ultra-Fast Python Package Manager) |
| 37 | + uses: astral-sh/install-uv-action@v1 |
40 | 38 |
|
41 | | - # Step 4: Lint and format code with Ruff |
42 | | - - name: Lint and format with Ruff |
| 39 | + - name: 4. | Install project dependencies via uv |
43 | 40 | run: | |
44 | | - python -m uv exec ruff format --check . |
45 | | - python -m uv exec ruff check . |
| 41 | + # Create a virtual environment |
| 42 | + uv venv |
| 43 | + # Install main and dev dependencies |
| 44 | + if [ -f requirements-dev.txt ]; then |
| 45 | + uv pip install -r requirements.txt -r requirements-dev.txt |
| 46 | + else |
| 47 | + uv pip install -r requirements.txt |
| 48 | + fi |
| 49 | + shell: bash |
46 | 50 |
|
47 | | - # Step 5: Run tests with Pytest |
48 | | - - name: Run tests with Pytest |
49 | | - run: | |
50 | | - python -m uv exec pytest --cov=${{ env.REPO_NAME }} --cov-report=xml |
51 | | - # The --cov=${{ env.REPO_NAME }} flag enables coverage collection for the package itself. |
52 | | - # The --cov-report=xml generates a coverage report in XML format, suitable for Codecov. |
| 51 | + - name: 5. | Lint with Ruff |
| 52 | + run: uv run ruff check . |
| 53 | + |
| 54 | + - name: 6. | Check formatting with Ruff |
| 55 | + run: uv run ruff format --check . |
| 56 | + |
| 57 | + - name: 7. | Run tests and generate coverage report |
| 58 | + run: uv run pytest --cov=./ --cov-report=xml |
53 | 59 |
|
54 | | - # Step 6: Upload coverage report to Codecov |
55 | | - # This step assumes you have a CODECOV_TOKEN set in your GitHub repository secrets. |
56 | | - - name: Upload coverage to Codecov |
| 60 | + - name: 8. | Upload coverage to Codecov |
57 | 61 | uses: codecov/codecov-action@v4 |
58 | | - if: github.ref == 'refs/heads/main' || github.ref == 'refs/pull/${{ github.event.number }}/merge' |
59 | 62 | with: |
60 | 63 | token: ${{ secrets.CODECOV_TOKEN }} |
61 | | - # This token is required for uploading coverage reports to Codecov. |
62 | | - # It should be configured as a secret in your GitHub repository settings. |
| 64 | + fail_ci_if_error: true |
| 65 | + verbose: true |
0 commit comments