diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..1ff153e4 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,10 @@ +[run] +branch = True +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..3f4c930e 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 @@ -133,8 +133,15 @@ 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.${{ matrix.usage_example}} \ + --rcfile=../repository/.coveragerc \ + $(which cijoe) --monitor -l + + - name: Coverage report + run: | + coverage report --data-file=.coverage.${{ matrix.usage_example}} - name: Upload report if: always() @@ -144,6 +151,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: .coverage.${{ matrix.usage_example}} + if-no-files-found: error + + publish: if: startsWith(github.ref, 'refs/tags/v') needs: @@ -172,3 +188,51 @@ 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: | + find all_artifacts -name '.coverage*' -exec coverage debug data {} \; + coverage combine \ + --rcfile=repository/.coveragerc \ + all_artifacts/report-coverage**/.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 1baa6e9d..ab0e0256 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]" @@ -123,7 +121,8 @@ 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 + @${PIPX} inject cijoe pytest-cov --force @echo "## ${PROJECT_NAME}: make install [DONE]" define uninstall-help @@ -143,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 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: