diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..867584f --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -0,0 +1,92 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: Lint & Format checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + - name: Install lint tools + run: | + python -m pip install --upgrade pip + pip install ruff black isort + - name: Ruff (fast linter) + run: ruff check . + - name: Black format check + run: black --check . + - name: isort check + run: isort --check-only . + + test: + name: Run tests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.10, 3.11, 3.12] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install pytest pytest-cov + - name: Run pytest with coverage + run: | + pytest --maxfail=1 --disable-warnings -q --cov=. + - name: Upload coverage report + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-report-${{ matrix.python-version }} + path: .coverage + + security: + name: Security checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + - name: Install audit tools + run: | + python -m pip install --upgrade pip + pip install pip-audit + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run pip-audit + run: | + pip-audit --fail-on high || true