|
| 1 | +name: CI Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + |
| 9 | +env: |
| 10 | + PYTHON_VERSION: '3.11' |
| 11 | + NODE_VERSION: '18' |
| 12 | + |
| 13 | +jobs: |
| 14 | + lint-python: |
| 15 | + name: Python Linting |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v4 |
| 24 | + with: |
| 25 | + python-version: ${{ env.PYTHON_VERSION }} |
| 26 | + |
| 27 | + - name: Cache pip dependencies |
| 28 | + uses: actions/cache@v3 |
| 29 | + with: |
| 30 | + path: ~/.cache/pip |
| 31 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} |
| 32 | + restore-keys: | |
| 33 | + ${{ runner.os }}-pip- |
| 34 | +
|
| 35 | + - name: Install dependencies |
| 36 | + run: | |
| 37 | + python -m pip install --upgrade pip |
| 38 | + pip install -r requirements.txt |
| 39 | + pip install -r requirements-dev.txt |
| 40 | +
|
| 41 | + - name: Run Black (Code Formatting) |
| 42 | + run: | |
| 43 | + black --check --diff scripts/python/ |
| 44 | +
|
| 45 | + - name: Run isort (Import Sorting) |
| 46 | + run: | |
| 47 | + isort --check-only --diff --profile=black scripts/python/ |
| 48 | +
|
| 49 | + - name: Run Pylint (Code Quality) |
| 50 | + run: | |
| 51 | + pylint scripts/python/ --exit-zero --reports=no --output-format=colorized |
| 52 | +
|
| 53 | + - name: Run MyPy (Type Checking) |
| 54 | + continue-on-error: true |
| 55 | + run: | |
| 56 | + mypy --explicit-package-bases scripts/python/ |
| 57 | +
|
| 58 | + lint-bash: |
| 59 | + name: Bash Linting |
| 60 | + runs-on: ubuntu-latest |
| 61 | + |
| 62 | + steps: |
| 63 | + - name: Checkout code |
| 64 | + uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - name: Install ShellCheck |
| 67 | + run: | |
| 68 | + sudo apt-get update |
| 69 | + sudo apt-get install -y shellcheck |
| 70 | +
|
| 71 | + - name: Run ShellCheck |
| 72 | + run: | |
| 73 | + find scripts/bash -name "*.sh" -type f | xargs shellcheck |
| 74 | +
|
| 75 | + test-python: |
| 76 | + name: Python Tests |
| 77 | + runs-on: ubuntu-latest |
| 78 | + needs: lint-python |
| 79 | + |
| 80 | + strategy: |
| 81 | + matrix: |
| 82 | + python-version: ['3.9', '3.10', '3.11'] |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Checkout code |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Set up Python ${{ matrix.python-version }} |
| 89 | + uses: actions/setup-python@v4 |
| 90 | + with: |
| 91 | + python-version: ${{ matrix.python-version }} |
| 92 | + |
| 93 | + - name: Cache pip dependencies |
| 94 | + uses: actions/cache@v3 |
| 95 | + with: |
| 96 | + path: ~/.cache/pip |
| 97 | + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt') }} |
| 98 | + restore-keys: | |
| 99 | + ${{ runner.os }}-pip-${{ matrix.python-version }}- |
| 100 | +
|
| 101 | + - name: Install dependencies |
| 102 | + run: | |
| 103 | + python -m pip install --upgrade pip |
| 104 | + pip install -r requirements.txt |
| 105 | + pip install -r requirements-dev.txt |
| 106 | +
|
| 107 | + - name: Create necessary directories |
| 108 | + run: | |
| 109 | + mkdir -p logs |
| 110 | + mkdir -p scripts/python/tests |
| 111 | +
|
| 112 | + - name: Run pytest |
| 113 | + run: | |
| 114 | + python -m pytest scripts/python/tests/ -v --cov=scripts/python --cov-report=xml --cov-report=term-missing |
| 115 | +
|
| 116 | + - name: Upload coverage to Codecov |
| 117 | + uses: codecov/codecov-action@v3 |
| 118 | + with: |
| 119 | + file: ./coverage.xml |
| 120 | + flags: unittests |
| 121 | + name: codecov-umbrella |
| 122 | + |
| 123 | + test-bash: |
| 124 | + name: Bash Tests |
| 125 | + runs-on: ubuntu-latest |
| 126 | + needs: lint-bash |
| 127 | + |
| 128 | + steps: |
| 129 | + - name: Checkout code |
| 130 | + uses: actions/checkout@v4 |
| 131 | + |
| 132 | + - name: Install BATS |
| 133 | + run: | |
| 134 | + git clone https://github.com/bats-core/bats-core.git |
| 135 | + cd bats-core |
| 136 | + sudo ./install.sh /usr/local |
| 137 | +
|
| 138 | + - name: Create test directory if it doesn't exist |
| 139 | + run: | |
| 140 | + mkdir -p scripts/bash/tests |
| 141 | +
|
| 142 | + - name: Run BATS tests (if any exist) |
| 143 | + run: | |
| 144 | + if find scripts/bash/tests -name "*.bats" -type f | grep -q .; then |
| 145 | + bats scripts/bash/tests/ |
| 146 | + else |
| 147 | + echo "No BATS tests found, skipping..." |
| 148 | + fi |
| 149 | +
|
| 150 | + integration-tests: |
| 151 | + name: Integration Tests |
| 152 | + runs-on: ubuntu-latest |
| 153 | + needs: [test-python, test-bash] |
| 154 | + |
| 155 | + steps: |
| 156 | + - name: Checkout code |
| 157 | + uses: actions/checkout@v4 |
| 158 | + |
| 159 | + - name: Set up Python |
| 160 | + uses: actions/setup-python@v4 |
| 161 | + with: |
| 162 | + python-version: ${{ env.PYTHON_VERSION }} |
| 163 | + |
| 164 | + - name: Install dependencies |
| 165 | + run: | |
| 166 | + python -m pip install --upgrade pip |
| 167 | + pip install -r requirements.txt |
| 168 | + pip install -r requirements-dev.txt |
| 169 | +
|
| 170 | + - name: Create necessary directories |
| 171 | + run: | |
| 172 | + mkdir -p logs |
| 173 | +
|
| 174 | + - name: Test command checker with safe command |
| 175 | + run: | |
| 176 | + python scripts/python/core/check_command.py "ls -la" | grep -q "PASS" |
| 177 | +
|
| 178 | + - name: Test command checker with dangerous command |
| 179 | + run: | |
| 180 | + python scripts/python/core/check_command.py "rm -rf /" | grep -q "ERROR" |
| 181 | +
|
| 182 | + - name: Test configuration loading |
| 183 | + run: | |
| 184 | + python -c " |
| 185 | + import sys |
| 186 | + sys.path.insert(0, '.') |
| 187 | + from scripts.python.core.config import get_config |
| 188 | + config = get_config() |
| 189 | + assert config.get_rules_file() is not None |
| 190 | + print('β
Configuration loading test passed') |
| 191 | + " |
| 192 | +
|
| 193 | + - name: Test security validation |
| 194 | + run: | |
| 195 | + python -c " |
| 196 | + import sys |
| 197 | + sys.path.insert(0, '.') |
| 198 | + from scripts.python.core.security import validate_command |
| 199 | + is_safe, error = validate_command('ls -la') |
| 200 | + assert is_safe == True |
| 201 | + is_safe, error = validate_command('rm -rf /') |
| 202 | + assert is_safe == False |
| 203 | + print('β
Security validation test passed') |
| 204 | + " |
| 205 | +
|
| 206 | + security-scan: |
| 207 | + name: Security Scan |
| 208 | + runs-on: ubuntu-latest |
| 209 | + |
| 210 | + steps: |
| 211 | + - name: Checkout code |
| 212 | + uses: actions/checkout@v4 |
| 213 | + |
| 214 | + - name: Set up Python |
| 215 | + uses: actions/setup-python@v4 |
| 216 | + with: |
| 217 | + python-version: ${{ env.PYTHON_VERSION }} |
| 218 | + |
| 219 | + - name: Install security tools |
| 220 | + run: | |
| 221 | + python -m pip install --upgrade pip |
| 222 | + pip install bandit safety |
| 223 | +
|
| 224 | + - name: Run Bandit (Security Linting) |
| 225 | + run: | |
| 226 | + bandit -r scripts/python/ -f json -o bandit-report.json || true |
| 227 | + bandit -r scripts/python/ --exit-zero |
| 228 | +
|
| 229 | + - name: Run Safety (Dependency Vulnerability Check) |
| 230 | + run: | |
| 231 | + safety check --json --output safety-report.json || true |
| 232 | + safety check |
| 233 | +
|
| 234 | + - name: Upload Security Report |
| 235 | + if: always() |
| 236 | + uses: actions/upload-artifact@v4 |
| 237 | + with: |
| 238 | + name: security-report |
| 239 | + path: security-report.txt |
| 240 | + retention-days: 30 |
| 241 | + |
| 242 | + build-success: |
| 243 | + name: Build Success |
| 244 | + runs-on: ubuntu-latest |
| 245 | + needs: [lint-python, lint-bash, test-python, test-bash, integration-tests, security-scan] |
| 246 | + if: success() |
| 247 | + |
| 248 | + steps: |
| 249 | + - name: Success notification |
| 250 | + run: | |
| 251 | + echo "π All CI checks passed successfully!" |
| 252 | + echo "β
Python linting passed" |
| 253 | + echo "β
Bash linting passed" |
| 254 | + echo "β
Python tests passed" |
| 255 | + echo "β
Bash tests passed" |
| 256 | + echo "β
Integration tests passed" |
| 257 | + echo "β
Security scan completed" |
0 commit comments