|
| 1 | +name: CodeConcat CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + tags: [ 'v*.*.*' ] |
| 7 | + pull_request: |
| 8 | + branches: [ "main" ] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + id-token: write # For PyPI Trusted Publishing |
| 14 | + |
| 15 | +jobs: |
| 16 | + lint-check: |
| 17 | + name: Lint & Format Check |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + - uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: '3.11' |
| 24 | + - name: Install dependencies |
| 25 | + run: | |
| 26 | + python -m pip install --upgrade pip |
| 27 | + pip install ruff |
| 28 | + - name: Run Ruff Linter |
| 29 | + run: ruff check . |
| 30 | + - name: Run Ruff Formatter Check |
| 31 | + run: ruff format --check . |
| 32 | + |
| 33 | + type-check: |
| 34 | + name: Type Check |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + - uses: actions/setup-python@v5 |
| 39 | + with: |
| 40 | + python-version: '3.11' |
| 41 | + - name: Install dependencies |
| 42 | + # Install with 'dev' extras to get mypy and types-* |
| 43 | + run: | |
| 44 | + python -m pip install --upgrade pip |
| 45 | + pip install .[dev] |
| 46 | + # Install libmagic for python-magic (needed for mypy checks too if types are strict) |
| 47 | + sudo apt-get update && sudo apt-get install -y libmagic1 |
| 48 | + - name: Run MyPy Type Checker |
| 49 | + run: mypy codeconcat tests |
| 50 | + |
| 51 | + test: |
| 52 | + name: Test & Coverage |
| 53 | + needs: [lint-check, type-check] # Depends on checks passing |
| 54 | + runs-on: ubuntu-latest |
| 55 | + strategy: |
| 56 | + matrix: |
| 57 | + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] # Test across versions |
| 58 | + |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v4 |
| 61 | + - name: Set up Python ${{ matrix.python-version }} |
| 62 | + uses: actions/setup-python@v5 |
| 63 | + with: |
| 64 | + python-version: ${{ matrix.python-version }} |
| 65 | + |
| 66 | + - name: Install dependencies including test extras |
| 67 | + run: | |
| 68 | + python -m pip install --upgrade pip |
| 69 | + pip install .[dev] # Installs pytest, pytest-cov etc. |
| 70 | + # Install libmagic required by python-magic (needed at runtime for tests) |
| 71 | + sudo apt-get update && sudo apt-get install -y libmagic1 |
| 72 | +
|
| 73 | + - name: Run Pytest with Coverage |
| 74 | + run: pytest # Reads config from pyproject.toml |
| 75 | + |
| 76 | + - name: Upload coverage reports to Codecov |
| 77 | + uses: codecov/codecov-action@v4 # Use v4 |
| 78 | + with: |
| 79 | + # token: ${{ secrets.CODECOV_TOKEN }} # Not needed for public repos on codecov.io |
| 80 | + slug: lguibr/codeconcat # Optional: verify auto-detection |
| 81 | + files: ./coverage.xml # Ensure this matches pytest output |
| 82 | + fail_ci_if_error: true |
| 83 | + env: |
| 84 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} # Needed for private repos or Codecov Enterprise |
| 85 | + |
| 86 | + publish: |
| 87 | + name: Publish to PyPI |
| 88 | + needs: test # Publish only if tests pass |
| 89 | + runs-on: ubuntu-latest |
| 90 | + if: startsWith(github.ref, 'refs/tags/v') |
| 91 | + environment: |
| 92 | + name: pypi |
| 93 | + url: https://pypi.org/p/codeconcat |
| 94 | + permissions: |
| 95 | + id-token: write # Required for trusted publishing |
| 96 | + |
| 97 | + steps: |
| 98 | + - uses: actions/checkout@v4 |
| 99 | + - uses: actions/setup-python@v5 |
| 100 | + with: |
| 101 | + python-version: '3.11' |
| 102 | + - name: Install build dependencies |
| 103 | + run: python -m pip install --upgrade pip build |
| 104 | + - name: Build package |
| 105 | + run: python -m build |
| 106 | + - name: Publish package to PyPI |
| 107 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 108 | + # Uses OIDC Trusted Publishing (no token needed) |
0 commit comments