|
| 1 | +name: CI Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + python-version: [3.8, 3.9, '3.10', '3.11'] |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v3 |
| 19 | + |
| 20 | + - name: Set up Python ${{ matrix.python-version }} |
| 21 | + uses: actions/setup-python@v4 |
| 22 | + with: |
| 23 | + python-version: ${{ matrix.python-version }} |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: | |
| 27 | + python -m pip install --upgrade pip |
| 28 | + pip install -r requirements.txt |
| 29 | +
|
| 30 | + - name: Lint with flake8 |
| 31 | + run: | |
| 32 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 33 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 34 | +
|
| 35 | + - name: Type check with mypy |
| 36 | + run: | |
| 37 | + mypy app/ --ignore-missing-imports |
| 38 | + continue-on-error: true |
| 39 | + |
| 40 | + - name: Run tests |
| 41 | + run: | |
| 42 | + pytest tests/ -v --cov=app --cov-report=xml |
| 43 | +
|
| 44 | + - name: Upload coverage |
| 45 | + uses: codecov/codecov-action@v3 |
| 46 | + with: |
| 47 | + file: ./coverage.xml |
| 48 | + |
| 49 | + security-scan: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v3 |
| 54 | + |
| 55 | + - name: Run Bandit security scanner |
| 56 | + run: | |
| 57 | + pip install bandit |
| 58 | + bandit -r app/ -f json -o bandit-report.json |
| 59 | + continue-on-error: true |
| 60 | + |
| 61 | + - name: Upload security report |
| 62 | + uses: actions/upload-artifact@v3 |
| 63 | + with: |
| 64 | + name: security-report |
| 65 | + path: bandit-report.json |
| 66 | + |
| 67 | + build: |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: [test] |
| 70 | + |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v3 |
| 73 | + |
| 74 | + - name: Build Docker image |
| 75 | + run: | |
| 76 | + docker build -t bloghub:${{ github.sha }} . |
| 77 | +
|
| 78 | + - name: Test Docker image |
| 79 | + run: | |
| 80 | + docker run -d -p 5000:5000 bloghub:${{ github.sha }} |
| 81 | + sleep 5 |
| 82 | + curl -f http://localhost:5000/api/health || exit 1 |
0 commit comments