From 3a31f35d9d7ada065756dfaf30ad5fbc0f120646 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 4 Jan 2024 17:48:59 +0000 Subject: [PATCH] Enable coverage reporting --- .github/workflows/tox.yml | 44 ++++++++++++++++++++++++++++++++------- .pre-commit-config.yaml | 4 ++-- .vscode/settings.json | 2 +- codecov.yml | 6 ++++++ tox.ini | 9 +++++--- 5 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 codecov.yml diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 52d7d9e..a14e85c 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -1,15 +1,21 @@ +--- name: tox -# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency +on: + push: # only publishes pushes to the main branch to TestPyPI + branches: # any integration branch but not tag + - "main" + pull_request: + branches: + - "main" + concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} cancel-in-progress: true -on: - create: # is used for publishing to PyPI and TestPyPI - tags: # any tag regardless of its name, no branches - - "**" - pull_request: +env: + FORCE_COLOR: 1 # tox, pytest, ansible-lint + PY_COLORS: 1 jobs: prepare: @@ -80,6 +86,30 @@ jobs: - name: tox -e ${{ matrix.passed_name }} run: python3 -m tox -e ${{ matrix.passed_name }} + - name: Upload coverage data + if: ${{ startsWith(matrix.passed_name, 'py') }} + uses: codecov/codecov-action@v3 + with: + name: ${{ matrix.passed_name }} + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true + verbose: true # optional (default = false) + + - name: Archive logs + uses: actions/upload-artifact@v3 + with: + name: logs.zip + path: .tox/**/log/ + + - name: Report failure if git reports dirty status + run: | + if [[ -n $(git status -s) ]]; then + # shellcheck disable=SC2016 + echo -n '::error file=git-status::' + printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY" + exit 99 + fi + # https://github.com/actions/toolkit/issues/193 check: # This job does nothing and is only used for the branch protection if: always() permissions: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 462150c..95f31a0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,14 +50,14 @@ repos: - id: tox-ini-fmt - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.1.9" + rev: "v0.1.11" hooks: - id: ruff args: - "--exit-non-zero-on-fix" - repo: https://github.com/streetsidesoftware/cspell-cli - rev: v8.2.1 + rev: v8.3.0 hooks: - id: cspell name: Spell check with cspell diff --git a/.vscode/settings.json b/.vscode/settings.json index ac23230..378860b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,7 @@ "[python]": { "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" }, "editor.defaultFormatter": "ms-python.black-formatter" }, diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..0ba9516 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,6 @@ +codecov: + require_ci_to_pass: true +comment: false +coverage: + status: + patch: true # we want github annotations diff --git a/tox.ini b/tox.ini index 4591f18..aacae41 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ skip_missing_interpreters = true work_dir = {env:TOX_WORK_DIR:.tox} [testenv] -description = Run pytest under {basepython} ({envpython}) +description = Run pytest under {basepython} package = editable extras = test @@ -31,15 +31,18 @@ set_env = PIP_CONSTRAINT = {toxinidir}/.config/requirements.txt PRE_COMMIT_COLOR = always TERM = xterm-256color +commands_pre = + sh -c "rm -f .tox/.coverage* 2>/dev/null || true" commands = coverage run -m pytest {posargs} - sh -c "coverage combine -q .tox/.coverage.* && coverage xml || true && coverage report" +commands_post = + py: sh -c "coverage combine -q .tox/.coverage.* && coverage xml && coverage report" allowlist_externals = rm sh [testenv:lint] -description = Enforce quality standards under {basepython} ({envpython}) +description = Enforce quality standards under {basepython} skip_install = true deps = pre-commit