From 1f6170d4a1c1e6fb5f48c67e60a38359ce93a9b3 Mon Sep 17 00:00:00 2001 From: "Simon A. F. Lund" Date: Fri, 27 Dec 2024 00:52:25 +0100 Subject: [PATCH 1/8] fix(mk): remove unused 'PYTHON_VENV' Signed-off-by: Simon A. F. Lund --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 1baa6e9d..1bbbabd4 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,6 @@ BUILD=pyproject-build PIPX=pipx PYTEST="$(shell pipx environment -V PIPX_LOCAL_VENVS)/${PROJECT_NAME}/bin/pytest" PYTHON_SYS=python3 -PYTHON_VENV="$(shell pipx environment -V PIPX_LOCAL_VENVS)/${PROJECT_NAME}/bin/python3" TWINE=twine CIJOE_VERSION=$(shell cd src; python3 -c "from cijoe import core;print(core.__version__)") @@ -42,7 +41,6 @@ info: ${PIPX} --version || true ${PYTEST} --version || true ${PYTHON_SYS} --version || true - ${PYTHON_VENV} --version || true ${TWINE} --version || true @echo "## ${PROJECT_NAME}: make info [DONE]" From 012fc6d4a90c2a4fcb33eddb7eb69f112e3b3086 Mon Sep 17 00:00:00 2001 From: "Simon A. F. Lund" Date: Fri, 27 Dec 2024 00:51:22 +0100 Subject: [PATCH 2/8] fix(mk/install): when injecting coverage also add its deps. Signed-off-by: Simon A. F. Lund --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1bbbabd4..d2b8387c 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ endef install: @echo "## ${PROJECT_NAME}: make install" @${PIPX} install dist/*.tar.gz --include-deps --force --python python3 - @${PIPX} inject cijoe coverage --include-apps --force + @${PIPX} inject cijoe coverage --include-apps --include-deps --force @echo "## ${PROJECT_NAME}: make install [DONE]" define uninstall-help From ebcbda8229168176d1641c4396d3b40a7a3e365a Mon Sep 17 00:00:00 2001 From: "Morten B. Rasmussen" Date: Fri, 27 Dec 2024 00:53:37 +0100 Subject: [PATCH 3/8] feat: add collection and publication of coverage-data This update modifies the GitHub Actions workflow to integrate code coverage reporting with Coveralls. It includes steps to collect, combine, and publish coverage data. The following supporting changes were also added: * feat: add config-file for the 'coverage' cli-tool * feat(git-ignore): add '.coverage' directory to .gitignore - The '.coverage' directory is generated by 'coverage'/'coverage.py' during unittest runs. Ignoring it prevents accidental inclusion in the repository. * feat(mk/install): add injection of pytest-cov * feat(mk/test): add use of 'coverage' when running pytest Signed-off-by: Morten B. Rasmussen --- .coveragerc | 9 ++++ .github/workflows/verify_and_publish.yml | 64 +++++++++++++++++++++++- .gitignore | 1 + Makefile | 3 +- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..84ba417b --- /dev/null +++ b/.coveragerc @@ -0,0 +1,9 @@ +[run] +source = + cijoe.core + cijoe.cli + cijoe.fio + cijoe.gha + cijoe.linux + cijoe.qemu + cijoe.system_imaging diff --git a/.github/workflows/verify_and_publish.yml b/.github/workflows/verify_and_publish.yml index 3a47f631..32aef9ac 100644 --- a/.github/workflows/verify_and_publish.yml +++ b/.github/workflows/verify_and_publish.yml @@ -133,8 +133,12 @@ jobs: - name: Run it! run: | - cd cijoe-example-${{ matrix.usage_example }} - cijoe --monitor -l + cd cijoe-example-${{ matrix.usage_example}} + coverage run \ + --data-file=.coverage \ + --rcfile=../repository/.coveragerc \ + $(which cijoe) --monitor -l + coverage report - name: Upload report if: always() @@ -144,6 +148,15 @@ jobs: path: cijoe-example-${{ matrix.usage_example }}/cijoe-output/* if-no-files-found: error + - name: Upload coverage files + if: always() + uses: actions/upload-artifact@v4.3.0 + with: + name: report-coverage-${{ matrix.usage_example }} + path: cijoe-example-${{ matrix.usage_example}}/.coverage + if-no-files-found: error + + publish: if: startsWith(github.ref, 'refs/tags/v') needs: @@ -172,3 +185,50 @@ jobs: run: | make release + publish-coverage: + runs-on: ${{ matrix.os }} + needs: [examples, unittest] + container: + image: ghcr.io/refenv/cijoe-docker:latest + options: --privileged + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python-version: ['3.12'] + + steps: + - name: Grab source + uses: actions/checkout@v4.2.2 + with: + path: repository + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5.2.0 + with: + python-version: ${{ matrix.python-version }} + + - name: Build and install cijoe from source + run: | + pipx uninstall cijoe + cd repository + make deps info build install + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Download all artifacts + uses: actions/download-artifact@v4.1.8 + with: + # If you omit 'name', all artifacts from previous jobs are downloaded. + path: ./all_artifacts + + - name: Show downloaded artifacts + run: | + coverage combine \ + --rcfile=repository/.coveragerc \ + all_artifacts/**/.coverage + coverage report \ + --debug=trace,config \ + --rcfile=repository/.coveragerc + - name: Coveralls upload + uses: coverallsapp/github-action@v2 diff --git a/.gitignore b/.gitignore index 3a85dfd8..95a6ec47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.coverage cijoe-output* tags selftest_results diff --git a/Makefile b/Makefile index d2b8387c..ab0e0256 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,7 @@ install: @echo "## ${PROJECT_NAME}: make install" @${PIPX} install dist/*.tar.gz --include-deps --force --python python3 @${PIPX} inject cijoe coverage --include-apps --include-deps --force + @${PIPX} inject cijoe pytest-cov --force @echo "## ${PROJECT_NAME}: make install [DONE]" define uninstall-help @@ -141,7 +142,7 @@ endef .PHONY: test test: @echo "## ${PROJECT_NAME}: make test" - ${PYTEST} --pyargs cijoe.core.selftest --config src/cijoe/core/configs/example_config_default.toml -v -s + ${PYTEST} --cov --pyargs cijoe.core.selftest --config src/cijoe/core/configs/example_config_default.toml -v -s @echo "## ${PROJECT_NAME}: make test [DONE]" define examples-help From 2e6d600c515d6dde964a3cf45c36b9248c3b6fd3 Mon Sep 17 00:00:00 2001 From: "Simon A. F. Lund" Date: Fri, 27 Dec 2024 22:30:18 +0100 Subject: [PATCH 4/8] refactor(gha): move 'env' into job where it is used Signed-off-by: Simon A. F. Lund --- .github/workflows/verify_and_publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/verify_and_publish.yml b/.github/workflows/verify_and_publish.yml index 32aef9ac..14d181e5 100644 --- a/.github/workflows/verify_and_publish.yml +++ b/.github/workflows/verify_and_publish.yml @@ -14,10 +14,6 @@ defaults: run: shell: bash -# This is needed for 'guestmount' / 'libguestfs' -env: - LIBGUESTFS_BACKEND: direct - jobs: format: runs-on: ${{ matrix.os }} @@ -86,6 +82,10 @@ jobs: needs: format runs-on: ubuntu-latest + # This is needed for 'guestmount' / 'libguestfs' + env: + LIBGUESTFS_BACKEND: direct + container: image: ghcr.io/refenv/cijoe-docker:latest options: --privileged From fd5b13bbeaa60d93857516843e256ce35e4b139b Mon Sep 17 00:00:00 2001 From: "Simon A. F. Lund" Date: Fri, 27 Dec 2024 22:47:36 +0100 Subject: [PATCH 5/8] refactor(gha): add seperate step for coverage-report Signed-off-by: Simon A. F. Lund --- .github/workflows/verify_and_publish.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/verify_and_publish.yml b/.github/workflows/verify_and_publish.yml index 14d181e5..c59e12a9 100644 --- a/.github/workflows/verify_and_publish.yml +++ b/.github/workflows/verify_and_publish.yml @@ -138,6 +138,9 @@ jobs: --data-file=.coverage \ --rcfile=../repository/.coveragerc \ $(which cijoe) --monitor -l + + - name: Coverage report + run: | coverage report - name: Upload report From 711ddc9c75bf1c5947b4d80075a6e0c0dd1c91f1 Mon Sep 17 00:00:00 2001 From: "Simon A. F. Lund" Date: Fri, 27 Dec 2024 22:48:17 +0100 Subject: [PATCH 6/8] refactor(gha): rename .coverage-files Signed-off-by: Simon A. F. Lund --- .github/workflows/verify_and_publish.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/verify_and_publish.yml b/.github/workflows/verify_and_publish.yml index c59e12a9..3f4c930e 100644 --- a/.github/workflows/verify_and_publish.yml +++ b/.github/workflows/verify_and_publish.yml @@ -135,13 +135,13 @@ jobs: run: | cd cijoe-example-${{ matrix.usage_example}} coverage run \ - --data-file=.coverage \ + --data-file=../.coverage.${{ matrix.usage_example}} \ --rcfile=../repository/.coveragerc \ $(which cijoe) --monitor -l - name: Coverage report run: | - coverage report + coverage report --data-file=.coverage.${{ matrix.usage_example}} - name: Upload report if: always() @@ -156,7 +156,7 @@ jobs: uses: actions/upload-artifact@v4.3.0 with: name: report-coverage-${{ matrix.usage_example }} - path: cijoe-example-${{ matrix.usage_example}}/.coverage + path: .coverage.${{ matrix.usage_example}} if-no-files-found: error @@ -227,9 +227,10 @@ jobs: - name: Show downloaded artifacts run: | + find all_artifacts -name '.coverage*' -exec coverage debug data {} \; coverage combine \ --rcfile=repository/.coveragerc \ - all_artifacts/**/.coverage + all_artifacts/report-coverage**/.coverage** coverage report \ --debug=trace,config \ --rcfile=repository/.coveragerc From 74a1c7373e09498d561360a300da20d1cc8ef26b Mon Sep 17 00:00:00 2001 From: "Simon A. F. Lund" Date: Sun, 29 Dec 2024 23:40:03 +0100 Subject: [PATCH 7/8] feat(gha/ci): add branch-tracking in coverity-config Signed-off-by: Simon A. F. Lund --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index 84ba417b..1ff153e4 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,5 @@ [run] +branch = True source = cijoe.core cijoe.cli From 34925880356154c7c37b1739b3b491b1f578b0e9 Mon Sep 17 00:00:00 2001 From: "Simon A. F. Lund" Date: Sun, 29 Dec 2024 23:41:21 +0100 Subject: [PATCH 8/8] fix(core/resources): use full package name when defining 'spec' The coverage.py tool was not tracking cijoe scripts executed via workflows, leaving a substantial amount of tested code untracked for coverage. This issue is similar to one reported previously: nedbat/coveragepy#1002 This commit addresses the problem by ensuring dynamically loaded Python modules are defined using their full package name. For example, instead of: example_script_default The full package name is now used: cijoe.core.scripts.example_script_default This change enables proper coverage tracking for these scripts. Signed-off-by: Simon A. F. Lund --- src/cijoe/core/resources.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cijoe/core/resources.py b/src/cijoe/core/resources.py index 06614ccb..02e2dddd 100644 --- a/src/cijoe/core/resources.py +++ b/src/cijoe/core/resources.py @@ -246,8 +246,17 @@ def load(self): if not self.content_has_script_func(): return ["Missing script_entry() function in ast"] - mod_name = str(Path(self.path).resolve().stem) - mod_path = str(Path(self.path).resolve()) + path = Path(self.path).resolve() + + mod_path = str(path) + mod_name = ".".join( + [ + path.parent.parent.parent.stem, # This should be cijoe + path.parent.parent.stem, # This should be the "package" name + path.parent.stem, # This should be "scripts" + path.stem, # This is the name of the module + ] + ) parent_path = str(Path(self.path).resolve().parent) if parent_path not in sys.path: