commit in class 01 #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI - Code Quality & Testing | ||
on: | ||
pull_request: | ||
branches: [main, develop] | ||
push: | ||
branches: [main, develop] | ||
env: | ||
PYTHON_VERSION: 3.10 | ||
jobs: | ||
code-quality: | ||
name: Code Quality Checks | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ env.PYTHON_VERSION }} | ||
- name: Cache pip dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 black isort mypy pytest pytest-cov | ||
pip install -r requirements.dev.txt | ||
- name: Run Black (Code Formatting) | ||
run: | | ||
black --check --diff streamlit-app/ training-pipeline/ tests/ | ||
- name: Run isort (Import Sorting) | ||
run: | | ||
isort --check-only --diff streamlit-app/ training-pipeline/ tests/ | ||
- name: Run Flake8 (Linting) | ||
run: | | ||
flake8 streamlit-app/ training-pipeline/ tests/ --max-line-length=88 --extend-ignore=E203,W503 | ||
- name: Run MyPy (Type Checking) | ||
run: | | ||
mypy streamlit-app/ training-pipeline/ --ignore-missing-imports | ||
unit-tests: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
needs: code-quelity | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ env.PYTHON_VERSION }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r streamlit-app/requirements.txt | ||
pip install -r training-pipeline/requirements.txt | ||
pip install -r requirements.dev.txt | ||
- name: Run unit tests | ||
run: | | ||
pytest tests/ -v --cov=streamlit-app --cov=training-pipeline --cov-report=xml | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
file: ./coverage.xml | ||
flags: unittests | ||
name: codecov-umbrella | ||
security-scan: | ||
name: Security Scan | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Run Bandit Security Scan | ||
run: | | ||
pip install bandit[toml] | ||
bandit -r streamlit-app/ training-pipeline/ -f json -o bandit-resport.json | ||
- name: Upload Bandit scan results | ||
uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: bandit-security-report | ||
path: bandit-report.json | ||
- name: Run Safety check for dependencies | ||
run: | | ||
pip install safety | ||
safety check --json --output safety-report.json | ||
- name: Upload Safety check results | ||
uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: safety-report | ||
path: safety-report.json |