Skip to content

Commit

Permalink
Add receptorctl coverage reporting (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
thom-at-redhat authored May 7, 2024
1 parent 772774f commit 1a17043
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverage_reporting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 71 additions & 16 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -85,39 +91,41 @@ 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 }}
session: tests-${{ matrix.python-version }}
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
Expand All @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion receptorctl/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[run]
omit = "tests/"
omit = tests/*
33 changes: 18 additions & 15 deletions receptorctl/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...] = (
Expand All @@ -16,18 +17,15 @@

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):
if PINNED:
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):
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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"))
Expand Down
2 changes: 2 additions & 0 deletions receptorctl/requirements/tests.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This requirements file is used for receptorctl tests

pytest==8.2.0 # <-- used to run receptorctl tests
pytest-cov
coverage

0 comments on commit 1a17043

Please sign in to comment.