From 1a1704311034b59ec8edb5d7b563dc361f22a494 Mon Sep 17 00:00:00 2001 From: Thom Carlin Date: Tue, 7 May 2024 16:49:34 -0400 Subject: [PATCH] Add receptorctl coverage reporting (#1025) --- .github/workflows/coverage_reporting.yml | 4 +- .github/workflows/pull_request.yml | 87 +++++++++++++++++++----- receptorctl/.coveragerc | 2 +- receptorctl/noxfile.py | 33 +++++---- receptorctl/requirements/tests.in | 2 + 5 files changed, 94 insertions(+), 34 deletions(-) diff --git a/.github/workflows/coverage_reporting.yml b/.github/workflows/coverage_reporting.yml index a56cb6680..3dd9c7676 100644 --- a/.github/workflows/coverage_reporting.yml +++ b/.github/workflows/coverage_reporting.yml @@ -7,8 +7,8 @@ on: # yamllint disable-line rule:truthy branches: [devel] jobs: - testing: - name: coverage + go_test_coverage: + name: go test coverage runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b8a0610ea..7c514cf1e 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -4,6 +4,11 @@ name: CI on: # yamllint disable-line rule:truthy pull_request: # yamllint disable-line rule:empty-values +env: + DESIRED_GO_VERSION: '1.20' + DESIRED_GOLANGCI_LINT_VERSION: 'v1.56' + DESIRED_PYTHON_VERSION: '3.11' + jobs: lint-receptor: name: lint-receptor @@ -16,11 +21,12 @@ jobs: - uses: actions/setup-go@v5 with: cache: false - go-version: '1.20' + go-version: ${{ env.DESIRED_GO_VERSION }} - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.56 + version: ${{ env.DESIRED_GOLANGCI_LINT_VERSION }} + receptor: name: receptor (Go ${{ matrix.go-version }}) runs-on: ubuntu-latest @@ -85,21 +91,22 @@ jobs: with: name: receptor path: /usr/local/bin/receptor + receptorctl: - name: Run receptorctl tests${{ '' }} # Nest jobs under the same sidebar category + name: Run receptorctl tests${{ '' }} # Nest jobs under the same sidebar category needs: receptor strategy: fail-fast: false matrix: python-version: - # NOTE: The highest and the lowest versions come - # NOTE: first as their statuses are most likely to - # NOTE: signal problems early: - - 3.11 - - 3.8 - - >- - 3.10 - - 3.9 + # NOTE: The highest and the lowest versions come + # NOTE: first as their statuses are most likely to + # NOTE: signal problems early: + - 3.11 + - 3.8 + - >- + 3.10 + - 3.9 uses: ./.github/workflows/reusable-nox.yml with: python-version: ${{ matrix.python-version }} @@ -107,17 +114,18 @@ jobs: download-receptor: true lint-receptorctl: - name: Lint receptorctl${{ '' }} # Nest jobs under the same sidebar category + name: Lint receptorctl${{ '' }} # Nest jobs under the same sidebar category strategy: fail-fast: false matrix: session: - - check_style - - check_format + - check_style + - check_format uses: ./.github/workflows/reusable-nox.yml with: - python-version: 3.11 + python-version: '3.11' session: ${{ matrix.session }} + container: name: container runs-on: ubuntu-latest @@ -130,7 +138,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: ${{ env.DESIRED_PYTHON_VERSION }} - name: Install python dependencies run: pip install build @@ -167,3 +175,50 @@ jobs: echo "Output did not contain expected value" exit 1 fi + + receptorctl-test-coverage: + name: Receptorctl test coverage + needs: receptor + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + session: + - coverage + steps: + - name: Download the `receptor` binary + uses: actions/download-artifact@v4 + with: + name: receptor + path: /usr/local/bin/ + + - name: Set executable bit on the `receptor` binary + run: sudo chmod a+x /usr/local/bin/receptor + + - name: Set up nox + uses: wntrblm/nox@2024.04.15 + with: + python-versions: ${{ env.DESIRED_PYTHON_VERSION }} + + - name: Check out the source code from Git + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed for the automation in Nox to find the last tag + + - name: Provision nox environment for ${{ matrix.session }} + run: nox --install-only --session ${{ matrix.session }} + working-directory: ./receptorctl + + - name: Run `receptorctl` nox ${{ matrix.session }} session + run: nox --no-install --session ${{ matrix.session }} + working-directory: ./receptorctl + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + directory: receptorctl + files: receptorctl_coverage.xml + fail_ci_if_error: true + flags: receptorctl + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true diff --git a/receptorctl/.coveragerc b/receptorctl/.coveragerc index 7bb31edc8..c712d2595 100644 --- a/receptorctl/.coveragerc +++ b/receptorctl/.coveragerc @@ -1,2 +1,2 @@ [run] -omit = "tests/" +omit = tests/* diff --git a/receptorctl/noxfile.py b/receptorctl/noxfile.py index 7dd734d13..d4e2e0d04 100644 --- a/receptorctl/noxfile.py +++ b/receptorctl/noxfile.py @@ -3,9 +3,10 @@ from glob import iglob from pathlib import Path -import nox import nox.command +LATEST_PYTHON_VERSION = ["3.11"] + python_versions = ["3.8", "3.9", "3.10", "3.11"] LINT_FILES: tuple[str, ...] = ( @@ -16,10 +17,7 @@ requirements_directory = Path("requirements").resolve() -requirements_files = [ - requirements_input_file_path.stem - for requirements_input_file_path in requirements_directory.glob("*.in") -] +requirements_files = [requirements_input_file_path.stem for requirements_input_file_path in requirements_directory.glob("*.in")] def install(session: nox.Session, *args, req: str, **kwargs): @@ -27,7 +25,7 @@ def install(session: nox.Session, *args, req: str, **kwargs): pip_constraint = requirements_directory / f"{req}.txt" kwargs.setdefault("env", {})["PIP_CONSTRAINT"] = pip_constraint session.log(f"export PIP_CONSTRAINT={pip_constraint!r}") - session.install("-r", requirements_directory / f"{req}.in", *args, **kwargs) + session.install("-r", f"{requirements_directory}/{req}.in", *args, **kwargs) def version(session: nox.Session): @@ -50,17 +48,24 @@ def version(session: nox.Session): if official_version: version = official_version.strip() else: - tag = session.run_install( - "git", "describe", "--tags", "--always", silent=True, external=True - ) - rev = session.run_install( - "git", "rev-parse", "--short", "HEAD", silent=True, external=True - ) + tag = session.run_install("git", "describe", "--tags", "--always", silent=True, external=True) + rev = session.run_install("git", "rev-parse", "--short", "HEAD", silent=True, external=True) version = tag.split("-")[0] + "+" + rev Path(".VERSION").write_text(version) +@nox.session(python=LATEST_PYTHON_VERSION) +def coverage(session: nox.Session): + """ + Run receptorctl tests with code coverage + """ + install(session, req="tests") + version(session) + session.install("-e", ".") + session.run("pytest", "--cov", "--cov-report", "xml:receptorctl_coverage.xml" "-v", "tests", *session.posargs) + + @nox.session(python=python_versions) def tests(session: nox.Session): """ @@ -121,9 +126,7 @@ def pip_compile(session: nox.Session, req: str): # Use --upgrade by default unless a user passes -P. upgrade_related_cli_flags = ("-P", "--upgrade-package", "--no-upgrade") - has_upgrade_related_cli_flags = any( - arg.startswith(upgrade_related_cli_flags) for arg in session.posargs - ) + has_upgrade_related_cli_flags = any(arg.startswith(upgrade_related_cli_flags) for arg in session.posargs) injected_extra_cli_args = () if has_upgrade_related_cli_flags else ("--upgrade",) output_file = os.path.relpath(Path(requirements_directory / f"{req}.txt")) diff --git a/receptorctl/requirements/tests.in b/receptorctl/requirements/tests.in index 2ab438b6e..2983fad1e 100644 --- a/receptorctl/requirements/tests.in +++ b/receptorctl/requirements/tests.in @@ -1,3 +1,5 @@ # This requirements file is used for receptorctl tests pytest==8.2.0 # <-- used to run receptorctl tests +pytest-cov +coverage