|
| 1 | +name: Code Quality |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, dev/jmlr ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, dev/jmlr ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + code-quality: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python 3.9 |
| 16 | + uses: actions/setup-python@v4 |
| 17 | + with: |
| 18 | + python-version: "3.9" |
| 19 | + |
| 20 | + - name: Cache pip dependencies |
| 21 | + uses: actions/cache@v3 |
| 22 | + with: |
| 23 | + path: ~/.cache/pip |
| 24 | + key: ${{ runner.os }}-pip-quality-${{ hashFiles('pyproject.toml') }} |
| 25 | + restore-keys: | |
| 26 | + ${{ runner.os }}-pip-quality- |
| 27 | + ${{ runner.os }}-pip- |
| 28 | +
|
| 29 | + - name: Install dependencies |
| 30 | + run: | |
| 31 | + python -m pip install --upgrade pip |
| 32 | + pip install -e ".[dev, security, linting]" |
| 33 | + # pip install ruff mypy bandit safety |
| 34 | + |
| 35 | + - name: Check code formatting with Black |
| 36 | + run: | |
| 37 | + black --check --diff torchsom/ tests/ |
| 38 | +
|
| 39 | + - name: Check import sorting with isort |
| 40 | + run: | |
| 41 | + isort --check-only --diff torchsom/ tests/ |
| 42 | +
|
| 43 | + - name: Lint with Ruff |
| 44 | + run: | |
| 45 | + ruff check torchsom/ tests/ --output-format=github |
| 46 | +
|
| 47 | + - name: Type checking with MyPy |
| 48 | + run: | |
| 49 | + mypy torchsom/ --ignore-missing-imports --strict |
| 50 | + continue-on-error: true |
| 51 | + |
| 52 | + - name: Check for security issues with Bandit (library code) |
| 53 | + run: | |
| 54 | + bandit -r torchsom/ -f json -o bandit-report-library.json --skip B101,B311,B601 |
| 55 | + continue-on-error: true |
| 56 | + |
| 57 | + - name: Check for security issues with Bandit (tests) |
| 58 | + run: | |
| 59 | + bandit -r tests/ -f json -o bandit-report-tests.json --skip B101,B311,B601 |
| 60 | + continue-on-error: true |
| 61 | + |
| 62 | + # - name: Check for known security vulnerabilities |
| 63 | + # run: | |
| 64 | + # safety check --json --output safety-report.json |
| 65 | + # continue-on-error: true |
| 66 | + |
| 67 | + - name: Upload security reports |
| 68 | + uses: actions/upload-artifact@v4 |
| 69 | + if: always() |
| 70 | + with: |
| 71 | + name: security-reports |
| 72 | + path: | |
| 73 | + bandit-report-library.json |
| 74 | + bandit-report-tests.json |
| 75 | + # safety-report.json |
| 76 | + |
| 77 | + docstring-quality: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Set up Python 3.9 |
| 83 | + uses: actions/setup-python@v4 |
| 84 | + with: |
| 85 | + python-version: "3.9" |
| 86 | + |
| 87 | + - name: Cache pip dependencies |
| 88 | + uses: actions/cache@v3 |
| 89 | + with: |
| 90 | + path: ~/.cache/pip |
| 91 | + key: ${{ runner.os }}-pip-quality-${{ hashFiles('pyproject.toml') }} |
| 92 | + restore-keys: | |
| 93 | + ${{ runner.os }}-pip-quality- |
| 94 | + ${{ runner.os }}-pip- |
| 95 | +
|
| 96 | + - name: Install dependencies |
| 97 | + run: | |
| 98 | + python -m pip install --upgrade pip |
| 99 | + pip install -e ".[dev, docs]" |
| 100 | + # pip install pydocstyle interrogate |
| 101 | + |
| 102 | + - name: Check docstring style |
| 103 | + run: | |
| 104 | + pydocstyle torchsom/ --convention=google |
| 105 | + continue-on-error: true |
| 106 | + |
| 107 | + - name: Check docstring coverage |
| 108 | + run: | |
| 109 | + interrogate torchsom/ --verbose --ignore-init-method --ignore-magic --ignore-module --fail-under=80 |
| 110 | + continue-on-error: true |
| 111 | + |
| 112 | + complexity-analysis: |
| 113 | + runs-on: ubuntu-latest |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v4 |
| 116 | + |
| 117 | + - name: Set up Python 3.9 |
| 118 | + uses: actions/setup-python@v4 |
| 119 | + with: |
| 120 | + python-version: "3.9" |
| 121 | + |
| 122 | + - name: Cache pip dependencies |
| 123 | + uses: actions/cache@v3 |
| 124 | + with: |
| 125 | + path: ~/.cache/pip |
| 126 | + key: ${{ runner.os }}-pip-quality-${{ hashFiles('pyproject.toml') }} |
| 127 | + restore-keys: | |
| 128 | + ${{ runner.os }}-pip-quality- |
| 129 | + ${{ runner.os }}-pip- |
| 130 | +
|
| 131 | + - name: Install dependencies |
| 132 | + run: | |
| 133 | + python -m pip install --upgrade pip |
| 134 | + pip install -e ".[dev, linting]" |
| 135 | + # pip install radon |
| 136 | + |
| 137 | + - name: Analyze code complexity |
| 138 | + run: | |
| 139 | + radon cc torchsom/ --show-complexity --min B |
| 140 | + radon mi torchsom/ --show --min B |
| 141 | + continue-on-error: true |
| 142 | + |
| 143 | + check-dependencies: |
| 144 | + runs-on: ubuntu-latest |
| 145 | + steps: |
| 146 | + - uses: actions/checkout@v4 |
| 147 | + |
| 148 | + - name: Set up Python 3.9 |
| 149 | + uses: actions/setup-python@v4 |
| 150 | + with: |
| 151 | + python-version: "3.9" |
| 152 | + |
| 153 | + - name: Cache pip dependencies |
| 154 | + uses: actions/cache@v3 |
| 155 | + with: |
| 156 | + path: ~/.cache/pip |
| 157 | + key: ${{ runner.os }}-pip-quality-${{ hashFiles('pyproject.toml') }} |
| 158 | + restore-keys: | |
| 159 | + ${{ runner.os }}-pip-quality- |
| 160 | + ${{ runner.os }}-pip- |
| 161 | +
|
| 162 | + - name: Install pip-tools |
| 163 | + run: | |
| 164 | + python -m pip install --upgrade pip |
| 165 | + pip install -e ".[security]" |
| 166 | + # pip install pip-tools |
| 167 | + |
| 168 | + - name: Check for dependency conflicts |
| 169 | + run: | |
| 170 | + pip-compile pyproject.toml --dry-run --verbose |
| 171 | + continue-on-error: true |
0 commit comments