py-cov-action / python-coverage-comment-action

Publish coverage report as PR comment, and create a coverage badge & dashboard to display on the Readme for Python projects, all inside GitHub without third party servers
https://github.com/marketplace/actions/python-coverage-comment
MIT License
81 stars 30 forks source link

Supporting coverage plugins #419

Open phrfpeixoto opened 4 months ago

phrfpeixoto commented 4 months ago

Is there any way to support coverage plugins?

My .coveragerc file uses the django_coverage_plugin plugin

[run]
relative_files = True
branch = True
plugins = django_coverage_plugin

And I get this error when running the workflow:

Traceback (most recent call last):
  File "/workdir/coverage_comment/subprocess.py", line 22, in run
    return subprocess.run(
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('coverage', 'json', '-o', '-')' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/workdir/coverage_comment/main.py", line 44, in main
    exit_code = action(
                ^^^^^^^
  File "/workdir/coverage_comment/main.py", line 96, in action
    return process_pr(
           ^^^^^^^^^^^
  File "/workdir/coverage_comment/main.py", line 127, in process_pr
    _, coverage = coverage_module.get_coverage_info(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workdir/coverage_comment/coverage.py", line 99, in get_coverage_info
    subprocess.run("coverage", "json", "-o", "-", path=coverage_path)
  File "/workdir/coverage_comment/subprocess.py", line 36, in run
    raise SubProcessError("\n".join([exc.stderr, exc.stdout])) from exc
coverage_comment.subprocess.SubProcessError: Traceback (most recent call last):
  File "/usr/local/bin/coverage", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/coverage/cmdline.py", line 970, in main
    status = CoverageScript().command_line(argv)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/coverage/cmdline.py", line 704, in command_line
    self.coverage.load()
  File "/usr/local/lib/python3.12/site-packages/coverage/control.py", line 501, in load
    self._init()
  File "/usr/local/lib/python3.12/site-packages/coverage/control.py", line [34](https://github.com/myollie/olliemain/actions/runs/9292185517/job/25572489665?pr=10274#step:13:35)3, in _init
    self._plugins = Plugins.load_plugins(self.config.plugins, self.config, self._debug)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/coverage/plugin_support.py", line 55, in load_plugins
    __import__(module)
ModuleNotFoundError: No module named 'django_coverage_plugin'
ewjoachim commented 4 months ago

it makes sense, as coverage doesn't run in your env but in the action's own dockerized env.

This caused #370 in the past, and the only way forward I'd see would be doing #347 (which is likely quite some work).

Do you have a better idea?

phrfpeixoto commented 4 months ago

The best option would be to allow custom package installation, through one of the options set on the action. The entrypoint script would check for that, and install them on demand.

ewjoachim commented 3 months ago

This would probably lead to a slower action start for users of this feature. It's not a problem per se, but let's keep that in mind.

Also, I imagine we'd soon have people requesting the ability to install custom apt packages because they need them for the python packages etc.

I wonder if there could be a way to select a custom base image instead...

phrfpeixoto commented 3 months ago

That's actually a good call. Why don't we update the base image to include the top 10 most used coverage.py plugins?

ewjoachim commented 3 months ago

Do you want to compare the current base image with, say, what it would be if we installed the plugins advertised in the coverage lib? I'm ok going this way this if this doesn't add more than 30% to the size of the image (gotta put the threshold somewhere).

(haha we're featured on that page, I didn't know that 😅)

phrfpeixoto commented 3 months ago

I'll try to have a look on that this weekend.