GitHub actions: save coverage data as artifacts #173
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: core-tests | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.10"] | |
env: | |
TOTAL_COVERAGE: "-" | |
COVERAGE_FILE_TEST: .coverage.${{ matrix.python-version }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Pipx cache for poetry | |
uses: actions/cache@v3 | |
with: | |
path: | | |
/opt/pipx/venvs/poetry | |
/opt/pipx_bin/poetry | |
key: pipx-venvs | |
- name: Install poetry | |
run: | | |
pipx install poetry | |
pipx list --verbose | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: 'poetry' | |
- run: | | |
poetry install | |
- name: Unit tests with pytest | |
run: | | |
poetry run pytest | |
env: | |
COVERAGE_FILE: .coverage.${{ matrix.python-version }} | |
- name: Display coverage data | |
run: ls -al .coverage* | |
- name: Upload coverage data | |
if: success() || failure() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-data-${{ matrix.python-version }} | |
if-no-files-found: warn | |
path: ./.coverage* | |
compression-level: 0 # no compression | |
retention-days: 1 | |
- name: prepare coverage data | |
continue-on-error: true | |
run: | | |
poetry run coverage json | |
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])") | |
echo "TOTAL_COVERAGE=$TOTAL" >> $GITHUB_ENV | |
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY | |
- name: create coverage badge | |
if : ${{ matrix.python-version == '3.11' }} | |
uses: schneegans/dynamic-badges-action@v1.7.0 | |
with: | |
auth: ${{ secrets.GIST_TOKEN }} | |
gistID: 1a66c9e88a9e4267f7e0b1d185be98f4 | |
filename: covbadge.json | |
label: coverage | |
message: ${{ env.TOTAL_COVERAGE }}% | |
minColorRange: 50 | |
maxColorRange: 90 | |
valColorRange: ${{ env.TOTAL_COVERAGE }} | |
isError: ${{ env.TOTAL_COVERAGE == '-' }} | |
- name: Static typechecking with mypy | |
if: ${{ !startsWith(matrix.python-version, 'pypy') }} | |
run: | | |
poetry run mypy ./zammadoo | |
- name: Static code analysis with pylint | |
if: ${{ matrix.python-version != '3.8' }} | |
run: | | |
poetry run pylint ./zammadoo | |
process-test-data: | |
runs-on: ubuntu-latest | |
needs: test | |
if: success() || failure() | |
steps: | |
- name: Download coverage data | |
uses: actions/download-artifact@v4 | |
with: | |
path: .coverage* | |
- name: Display structure of downloaded files | |
run: ls -alR |