|
| 1 | +name: Continuous Integration |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + pull_request: |
| 7 | + |
| 8 | +jobs: |
| 9 | + lints: |
| 10 | + name: Run linters |
| 11 | + runs-on: ubuntu-latest |
| 12 | + timeout-minutes: 15 |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + checks: write |
| 16 | + pull-requests: write |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - uses: actions/setup-python@v4 |
| 20 | + with: |
| 21 | + python-version: "3.11" |
| 22 | + |
| 23 | + - name: Cache pre-commit |
| 24 | + uses: actions/cache@v3 |
| 25 | + with: |
| 26 | + path: ~/.cache/pre-commit |
| 27 | + key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} |
| 28 | + |
| 29 | + - name: Install pre-commit |
| 30 | + run: pip3 install pre-commit |
| 31 | + |
| 32 | + - name: Run pre-commit checks |
| 33 | + run: pre-commit run --all-files --show-diff-on-failure --color always |
| 34 | + |
| 35 | + - name: Run Trivy vulnerability scanner |
| 36 | + uses: aquasecurity/trivy-action@master |
| 37 | + with: |
| 38 | + scan-type: "fs" |
| 39 | + ignore-unfixed: true |
| 40 | + exit-code: 0 # change if you want to fail build on vulnerabilities |
| 41 | + severity: "CRITICAL,HIGH,MEDIUM" |
| 42 | + format: "table" |
| 43 | + output: "trivy-scanning-results.txt" |
| 44 | + |
| 45 | + - name: Format trivy message |
| 46 | + run: | |
| 47 | + echo "Trivy scanning results." >> trivy.txt |
| 48 | + cat trivy-scanning-results.txt >> trivy.txt |
| 49 | +
|
| 50 | + - name: Add trivy report to PR |
| 51 | + uses: thollander/actions-comment-pull-request@v2 |
| 52 | + continue-on-error: true |
| 53 | + if: ${{ github.event_name == 'pull_request' }} |
| 54 | + with: |
| 55 | + filePath: trivy.txt |
| 56 | + reactions: "" |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + comment_tag: trivy |
| 59 | + |
| 60 | + - name: Create venv |
| 61 | + run: . ./setup_dev_env.sh |
| 62 | + |
| 63 | + - name: Check licenses |
| 64 | + run: ./check_licenses.sh |
| 65 | + |
| 66 | + - name: Generate pip freeze |
| 67 | + run: | |
| 68 | + source venv/bin/activate |
| 69 | + pip freeze > requirements-freeze.txt |
| 70 | +
|
| 71 | + - name: Publish Artefacts |
| 72 | + uses: actions/upload-artifact@v3 |
| 73 | + if: always() |
| 74 | + continue-on-error: true |
| 75 | + with: |
| 76 | + name: results |
| 77 | + path: | |
| 78 | + requirements-freeze.txt |
| 79 | + licenses.txt |
| 80 | + trivy-scanning-results.txt |
| 81 | + retention-days: 30 |
| 82 | + |
| 83 | + - name: Publish Test Report |
| 84 | + uses: actions/upload-artifact@v3 |
| 85 | + if: always() |
| 86 | + continue-on-error: true |
| 87 | + with: |
| 88 | + name: test-report |
| 89 | + path: report.xml |
| 90 | + retention-days: 10 |
| 91 | + |
| 92 | + - name: Validate package build |
| 93 | + run: | |
| 94 | + source venv/bin/activate |
| 95 | + python -m pip install -U build |
| 96 | + python -m build |
| 97 | +
|
| 98 | + - name: Publish Package |
| 99 | + uses: actions/upload-artifact@v3 |
| 100 | + continue-on-error: true |
| 101 | + if: success() |
| 102 | + with: |
| 103 | + name: packages |
| 104 | + path: dist/** |
| 105 | + retention-days: 3 |
| 106 | + |
| 107 | + tests: |
| 108 | + name: Run tests |
| 109 | + runs-on: ubuntu-latest |
| 110 | + timeout-minutes: 15 |
| 111 | + permissions: |
| 112 | + checks: write |
| 113 | + pull-requests: write |
| 114 | + contents: write # required for advanced coverage reporting (to keep branch) |
| 115 | + strategy: |
| 116 | + fail-fast: false # do not stop all jobs if one fails |
| 117 | + matrix: |
| 118 | + include: |
| 119 | + - python-version: "3.11" |
| 120 | + steps: |
| 121 | + - uses: actions/checkout@v4 |
| 122 | + - name: Set up Python ${{ matrix.python-version }} |
| 123 | + uses: actions/setup-python@v4 |
| 124 | + with: |
| 125 | + python-version: ${{ matrix.python-version }} |
| 126 | + |
| 127 | + - name: Cache Dependencies |
| 128 | + uses: actions/cache@v3 |
| 129 | + with: |
| 130 | + path: ~/.cache/pip |
| 131 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/pyproject.toml') }} |
| 132 | + restore-keys: | |
| 133 | + ${{ runner.os }}-pip- |
| 134 | +
|
| 135 | + - name: Install Dependencies |
| 136 | + run: pip install -r requirements-dev.txt |
| 137 | + |
| 138 | + - name: Run Tests With Coverage |
| 139 | + run: | |
| 140 | + # run with coverage to not execute tests twice |
| 141 | + coverage run -m pytest -v -p no:warnings --junitxml=report.xml tests/ |
| 142 | + coverage report |
| 143 | + coverage xml |
| 144 | +
|
| 145 | + - name: Test Report |
| 146 | + uses: mikepenz/action-junit-report@v4 |
| 147 | + continue-on-error: true |
| 148 | + if: always() |
| 149 | + with: |
| 150 | + report_paths: 'report.xml' |
| 151 | + |
| 152 | + - name: Publish Test Report |
| 153 | + uses: actions/upload-artifact@v3 |
| 154 | + continue-on-error: true |
| 155 | + if: always() |
| 156 | + with: |
| 157 | + name: test-report |
| 158 | + path: report.xml |
| 159 | + retention-days: 10 |
| 160 | + |
| 161 | + # simpler version for code coverage reporting |
| 162 | + # - name: Produce Coverage report |
| 163 | + # uses: 5monkeys/cobertura-action@v13 |
| 164 | + # continue-on-error: true |
| 165 | + # with: |
| 166 | + # path: coverage.xml |
| 167 | + # minimum_coverage: 70 |
| 168 | + # fail_below_threshold: false |
| 169 | + |
| 170 | + # more complex version for better coverage reporting |
| 171 | + - name: Produce the coverage report |
| 172 | + uses: insightsengineering/coverage-action@v2 |
| 173 | + continue-on-error: true |
| 174 | + with: |
| 175 | + # Path to the Cobertura XML report. |
| 176 | + path: coverage.xml |
| 177 | + # Minimum total coverage, if you want to the |
| 178 | + # workflow to enforce it as a standard. |
| 179 | + # This has no effect if the `fail` arg is set to `false`. |
| 180 | + threshold: 60 |
| 181 | + # Fail the workflow if the minimum code coverage |
| 182 | + # reuqirements are not satisfied. |
| 183 | + fail: false |
| 184 | + # Publish the rendered output as a PR comment |
| 185 | + publish: true |
| 186 | + # Create a coverage diff report. |
| 187 | + diff: true |
| 188 | + # Branch to diff against. |
| 189 | + # Compare the current coverage to the coverage |
| 190 | + # determined on this branch. |
| 191 | + diff-branch: ${{ github.event.repository.default_branch }} |
| 192 | + # make report togglable |
| 193 | + togglable-report: true |
| 194 | + # This is where the coverage reports for the |
| 195 | + # `diff-branch` are stored. |
| 196 | + # Branch is created if it doesn't already exist'. |
| 197 | + diff-storage: _xml_coverage_reports |
| 198 | + # A custom title that can be added to the code |
| 199 | + # coverage summary in the PR comment. |
| 200 | + coverage-summary-title: "Code Coverage Summary" |
0 commit comments