|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + release: |
| 9 | + types: [ published ] |
| 10 | + |
| 11 | +env: |
| 12 | + PYTHON_VERSION: "3.10" |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + name: Test Suite |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + os: [ubuntu-latest] |
| 22 | + python-version: ["3.9", "3.10", "3.11", "3.12"] |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up Python ${{ matrix.python-version }} |
| 29 | + uses: actions/setup-python@v4 |
| 30 | + with: |
| 31 | + python-version: ${{ matrix.python-version }} |
| 32 | + |
| 33 | + - name: Install Poetry |
| 34 | + uses: snok/install-poetry@v1 |
| 35 | + with: |
| 36 | + version: latest |
| 37 | + virtualenvs-create: true |
| 38 | + virtualenvs-in-project: true |
| 39 | + |
| 40 | + - name: Cache dependencies |
| 41 | + uses: actions/cache@v3 |
| 42 | + with: |
| 43 | + path: .venv |
| 44 | + key: ${{ runner.os }}-python-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-python-${{ matrix.python-version }}-poetry- |
| 47 | +
|
| 48 | + - name: Install dependencies |
| 49 | + run: poetry install --with dev |
| 50 | + |
| 51 | + - name: Run linting |
| 52 | + run: | |
| 53 | + make check |
| 54 | +
|
| 55 | + - name: Run tests |
| 56 | + run: poetry run pytest --cov=mvc_flask --cov-report=xml --cov-report=term-missing |
| 57 | + |
| 58 | + - name: Upload coverage to Codecov |
| 59 | + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' |
| 60 | + uses: codecov/codecov-action@v3 |
| 61 | + with: |
| 62 | + file: ./coverage.xml |
| 63 | + flags: unittests |
| 64 | + name: codecov-umbrella |
| 65 | + |
| 66 | + security: |
| 67 | + name: Security Scan |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Checkout code |
| 71 | + uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Set up Python |
| 74 | + uses: actions/setup-python@v4 |
| 75 | + with: |
| 76 | + python-version: ${{ env.PYTHON_VERSION }} |
| 77 | + |
| 78 | + - name: Install Poetry |
| 79 | + uses: snok/install-poetry@v1 |
| 80 | + |
| 81 | + - name: Install dependencies |
| 82 | + run: poetry install --with dev |
| 83 | + |
| 84 | + - name: Run security checks |
| 85 | + run: | |
| 86 | + poetry run bandit -r mvc_flask |
| 87 | +
|
| 88 | + build: |
| 89 | + name: Build Package |
| 90 | + runs-on: ubuntu-latest |
| 91 | + needs: [test, security] |
| 92 | + steps: |
| 93 | + - name: Checkout code |
| 94 | + uses: actions/checkout@v4 |
| 95 | + |
| 96 | + - name: Set up Python |
| 97 | + uses: actions/setup-python@v4 |
| 98 | + with: |
| 99 | + python-version: ${{ env.PYTHON_VERSION }} |
| 100 | + |
| 101 | + - name: Install Poetry |
| 102 | + uses: snok/install-poetry@v1 |
| 103 | + |
| 104 | + - name: Build package |
| 105 | + run: poetry build |
| 106 | + |
| 107 | + - name: Upload build artifacts |
| 108 | + uses: actions/upload-artifact@v4 |
| 109 | + with: |
| 110 | + name: dist |
| 111 | + path: dist/ |
| 112 | + |
| 113 | + publish: |
| 114 | + name: Publish to PyPI |
| 115 | + runs-on: ubuntu-latest |
| 116 | + needs: [test, security, build] |
| 117 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 118 | + environment: release |
| 119 | + |
| 120 | + steps: |
| 121 | + - name: Checkout code |
| 122 | + uses: actions/checkout@v4 |
| 123 | + |
| 124 | + - name: Set up Python |
| 125 | + uses: actions/setup-python@v4 |
| 126 | + with: |
| 127 | + python-version: ${{ env.PYTHON_VERSION }} |
| 128 | + |
| 129 | + - name: Install Poetry |
| 130 | + uses: snok/install-poetry@v1 |
| 131 | + |
| 132 | + - name: Build package |
| 133 | + run: poetry build |
| 134 | + |
| 135 | + - name: Publish to PyPI |
| 136 | + env: |
| 137 | + POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }} |
| 138 | + run: poetry publish |
| 139 | + |
| 140 | + docs: |
| 141 | + name: Build Documentation |
| 142 | + runs-on: ubuntu-latest |
| 143 | + steps: |
| 144 | + - name: Checkout code |
| 145 | + uses: actions/checkout@v4 |
| 146 | + |
| 147 | + - name: Set up Python |
| 148 | + uses: actions/setup-python@v4 |
| 149 | + with: |
| 150 | + python-version: ${{ env.PYTHON_VERSION }} |
| 151 | + |
| 152 | + - name: Install Poetry |
| 153 | + uses: snok/install-poetry@v1 |
| 154 | + |
| 155 | + - name: Install dependencies |
| 156 | + run: poetry install --with docs |
| 157 | + |
| 158 | + - name: Build documentation |
| 159 | + run: poetry run mkdocs build |
| 160 | + |
| 161 | + - name: Deploy to GitHub Pages |
| 162 | + if: github.ref == 'refs/heads/main' |
| 163 | + uses: peaceiris/actions-gh-pages@v3 |
| 164 | + with: |
| 165 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 166 | + publish_dir: ./site |
0 commit comments