GithubHelp home page GithubHelp logo

py-cov-action / python-coverage-comment-action Goto Github PK

View Code? Open in Web Editor NEW
70.0 70.0 26.0 3.95 MB

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

Home Page: https://github.com/marketplace/actions/python-coverage-comment

License: MIT License

Dockerfile 0.09% Python 94.38% Jinja 5.53%
actions coverage github-actions python

python-coverage-comment-action's People

Contributors

arthurnrl avatar astrochun avatar dato avatar doggie52 avatar ewjoachim avatar keunhyung-chung avatar kieferro avatar martinbernstorff avatar matias-a avatar me-on1 avatar nedbat avatar neilmunday avatar pre-commit-ci[bot] avatar renovate[bot] avatar tcompa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-coverage-comment-action's Issues

Check for open PRs on `push` GHA trigger

Hello ๐Ÿ‘‹

I've been successfully using this action for a couple weeks now (it is great ๐Ÿ‘ ) - I am opening this issue to suggest an improvement:

When the action is run as part of a push it would be great if the action could lookup the open PR that the commit belongs to and post the PR comment there.

I think this could simplify the usage of this action by obviating the need for:

  • pull_request trigger
  • actions/upload-artifact@v3
  • workflow_run trigger

(I am not suggesting that the above functionality is removed, only suggesting that we improve the push event handling for now, which could make this action easier to use imo)

What do you think? If this sounds like an acceptable improvement I would also be willing to work on it ๐Ÿ™‚

Can't succesfully configure action

I seem to be having issues with the action in generating a coverage report and am wondering if there are any suggestion to get it to work.

The action does successfully make a comment, but seems to fail in uploading an artifact to be used later. The "Store Pull Request comment to be posted" step does not seem to get executed.
Under Actions settings, GITHUB_TOKEN does have read/write permissions. The repo is set to private.

The error:

Run py-cov-action/python-coverage-comment-action@v3
/usr/bin/docker run --name bedb48eb8588bfd474f5aab19b4cd5187c8db_d2e0e6 --label 5bedb4 --workdir /github/workspace --rm -e "INPUT_GITHUB_TOKEN" -e "INPUT_GITHUB_PR_RUN_ID" -e "INPUT_COMMENT_TEMPLATE" -e "INPUT_COVERAGE_DATA_BRANCH" -e "INPUT_COVERAGE_PATH" -e "INPUT_COMMENT_ARTIFACT_NAME" -e "INPUT_COMMENT_FILENAME" -e "INPUT_MINIMUM_GREEN" -e "INPUT_MINIMUM_ORANGE" -e "INPUT_MERGE_COVERAGE_FILES" -e "INPUT_ANNOTATE_MISSING_LINES" -e "INPUT_ANNOTATION_TYPE" -e "INPUT_VERBOSE" -e "GITHUB_TOKEN" -e "GITHUB_PR_RUN_ID" -e "COMMENT_TEMPLATE" -e "COVERAGE_DATA_BRANCH" -e "COVERAGE_PATH" -e "COMMENT_ARTIFACT_NAME" -e "COMMENT_FILENAME" -e "MINIMUM_GREEN" -e "MINIMUM_ORANGE" -e "MERGE_COVERAGE_FILES" -e "ANNOTATE_MISSING_LINES" -e "ANNOTATION_TYPE" -e "VERBOSE" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/repo_name/repo_name":"/github/workspace" *****
Notice: Starting action
Notice: Generating comment for PR
Notice: HTTP Request: GET https://api.github.com/repos/user_name/repo_name/contents/data.json?ref=python-coverage-comment-action-data "HTTP/1.1 404 Not Found"
Notice: HTTP Request: GET https://api.github.com/user "HTTP/1.1 403 Forbidden"
Notice: HTTP Request: GET https://api.github.com/repos/user_name/repo_name/issues/68/comments "HTTP/1.1 200 OK"
Notice: Adding new comment
Notice: HTTP Request: POST https://api.github.com/repos/user_name/repo_name/issues/68/comments "HTTP/1.1 201 Created"
Notice: Ending action

My workflow:

      - name: Coverage comment
        id: coverage_comment
        uses: py-cov-action/python-coverage-comment-action@v3
        with:
          GITHUB_TOKEN: ${{ github.token }}

      - name: Store Pull Request comment to be posted
        uses: actions/upload-artifact@v3
        if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
        with:
          # If you use a different name, update COMMENT_ARTIFACT_NAME accordingly
          name: python-coverage-comment-action
          # If you use a different name, update COMMENT_FILENAME accordingly
          path: python-coverage-comment-action.txt

.coveragerc:

[run]
relative_files = True

TOML dependencies required for coverage

Hi, I'm glad that you built this GitHub Actions. I tried using it recently on a python 3.10 app and came across the following issue.

/usr/bin/docker run --name ewjoachimpythoncoveragecommentactionlatest_884cb6 --label 08450d --workdir /github/workspace --rm -e pythonLocation -e LD_LIBRARY_PATH -e INPUT_GITHUB_TOKEN -e INPUT_GITHUB_PR_RUN_ID -e INPUT_COMMENT_TEMPLATE -e INPUT_BADGE_FILENAME -e INPUT_COMMENT_ARTIFACT_NAME -e INPUT_COMMENT_FILENAME -e INPUT_MINIMUM_GREEN -e INPUT_MINIMUM_ORANGE -e INPUT_MERGE_COVERAGE_FILES -e INPUT_VERBOSE -e GITHUB_TOKEN -e GITHUB_PR_RUN_ID -e BADGE_FILENAME -e COMMENT_ARTIFACT_NAME -e COMMENT_FILENAME -e MINIMUM_GREEN -e MINIMUM_ORANGE -e MERGE_COVERAGE_FILES -e VERBOSE -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/fastapi-oauth-dev/fastapi-oauth-dev":"/github/workspace" ewjoachim/python-coverage-comment-action:latest
INFO:coverage_comment:Starting action
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line [16](https://github.com/astrochun/fastapi-oauth-dev/runs/6396946762?check_suite_focus=true#step:8:16), in run
    return subprocess.run(
  File "/usr/local/lib/python3.10/subprocess.py", line 524, 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 "/usr/local/bin/coverage_comment", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 37, in main
    exit_code = action(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 67, in action
    coverage = coverage_module.get_coverage_info(merge=config.MERGE_COVERAGE_FILES)
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/coverage.py", line 68, in get_coverage_info
    json_coverage = subprocess.run("coverage", "json", "-o", "-")
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line [24](https://github.com/astrochun/fastapi-oauth-dev/runs/6396946762?check_suite_focus=true#step:8:24), in run
    raise SubProcessError("/n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError: Can't read 'pyproject.toml' without TOML support. Install with [toml] extra
/n

This may be as simple as updating the dependencies but a bit surprised since your code also includes a pyproject.toml

Miscalculating branch coverage

In this issue, "branch coverage" means the thing that lets you check if all paths through an if
statement are covered. Completely unrelated to git branches.

I think in some case we're miscalculating branch coverage:

  • Without branches, coverage is computed as number of executed statements / total number of statements
  • With branches, I think it's currently sometimes computed as (executed statements + fully executed branches)/(total statements + total branches) though I think it's not always consistent and sometimes, it's computed as if branches weren't here
  • And I'm not sure how it should be computed, or dependening on the how, if it's even possible to do it from the json report.

In #211 , I'm removing branch coverage completely from the equation. But it might be worth investigating if we want to re-add it, though I believe it might be too complex to express in simple terms all the notions, especially given that "branch" is used both for if and git branch.

For now I'll just open this issue.

Fails on default branch

Hello,

I'm getting an error running the action on my default branch main. It works fine when running on PRs, but when running on the default branch it fails. I've been trying to debug and haven't been able to figure it out. Any help would be appreciated!

I've added running to my ci lint action as follows:

    permissions:
      pull-requests: write
      contents: write
...
      - name: Coverage comment
        uses: py-cov-action/python-coverage-comment-action@v3
        with:
          GITHUB_TOKEN: ${{ github.token }}
          COVERAGE_PATH: ./api/

git.branch("--show-current").strip()
here https://github.com/py-cov-action/python-coverage-comment-action/blob/main/coverage_comment/storage.py#L30 is returning empty.

Fails as follows:

Notice: Starting action
##[debug]load_ssl_context verify=True cert=None trust_env=True http2=False
##[debug]load_verify_locations cafile='/usr/local/lib/python3.11/site-packages/certifi/cacert.pem'
##[debug]load_ssl_context verify=True cert=None trust_env=True http2=False
##[debug]load_verify_locations cafile='/usr/local/lib/python3.11/site-packages/certifi/cacert.pem'
##[debug]Operating on refs/heads/main
##[debug]connect_tcp.started host='api.github.com' port=443 local_address=None timeout=60 socket_options=None
##[debug]connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7fb1c4c24c10>
##[debug]start_tls.started ssl_context=<ssl.SSLContext object at 0x7fb1c45dacc0> server_hostname='api.github.com' timeout=60
##[debug]start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7fb1c447d490>
##[debug]send_request_headers.started request=<Request [b'GET']>
##[debug]send_request_headers.complete
##[debug]send_request_body.started request=<Request [b'GET']>
##[debug]send_request_body.complete
##[debug]receive_response_headers.started request=<Request [b'GET']>
##[debug]receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Server', b'GitHub.com'), (b'Date', b'Tue, 05 Dec 2023 19:34:17 GMT'), (b'Content-Type', b'application/json; charset=utf-8'), (b'Transfer-Encoding', b'chunked'), (b'Cache-Control', b'private, max-age=60, s-maxage=60'), (b'Vary', b'Accept, Authorization, Cookie, X-GitHub-OTP'), (b'ETag', b'W/"86e1c69a5fe697eb1321ec2e2b7f3981c111333ff9a80eed4c78963728bf3517"'), (b'Last-Modified', b'Thu, 14 Sep 2023 14:15:37 GMT'), (b'X-GitHub-Media-Type', b'github.v3; format=json'), (b'x-accepted-github-permissions', b'metadata=read'), (b'x-github-api-version-selected', b'2022-11-28'), (b'X-RateLimit-Limit', b'1000'), (b'X-RateLimit-Remaining', b'992'), (b'X-RateLimit-Reset', b'1701807966'), (b'X-RateLimit-Used', b'8'), (b'X-RateLimit-Resource', b'core'), (b'Access-Control-Expose-Headers', b'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset'), (b'Access-Control-Allow-Origin', b'*'), (b'Strict-Transport-Security', b'max-age=31536000; includeSubdomains; preload'), (b'X-Frame-Options', b'deny'), (b'X-Content-Type-Options', b'nosniff'), (b'X-XSS-Protection', b'0'), (b'Referrer-Policy', b'origin-when-cross-origin, strict-origin-when-cross-origin'), (b'Content-Security-Policy', b"default-src 'none'"), (b'Vary', b'Accept-Encoding, Accept, X-Requested-With'), (b'Content-Encoding', b'gzip'), (b'X-GitHub-Request-Id', b'D981:3DE0:FCA340:20673B1:656F7B39')])

##[debug]receive_response_body.started request=<Request [b'GET']>
##[debug]receive_response_body.complete
##[debug]response_closed.started
##[debug]response_closed.complete
Notice: Computing coverage files & badge
##[debug]connect_tcp.started host='img.shields.io' port=443 local_address=None timeout=5.0 socket_options=None
##[debug]connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7fb1c416bfd0>
##[debug]start_tls.started ssl_context=<ssl.SSLContext object at 0x7fb1c45dade0> server_hostname='img.shields.io' timeout=5.0
##[debug]start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7fb1c416bf50>
##[debug]send_request_headers.started request=<Request [b'GET']>
##[debug]send_request_headers.complete
##[debug]send_request_body.started request=<Request [b'GET']>
##[debug]send_request_body.complete
##[debug]receive_response_headers.started request=<Request [b'GET']>
##[debug]receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Tue, 05 Dec 2023 19:34:19 GMT'), (b'Content-Type', b'image/svg+xml;charset=utf-8'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'access-control-allow-origin', b'*'), (b'Cache-Control', b'max-age=86400, s-maxage=86400'), (b'last-modified', b'Mon, 04 Dec 2023 14:25:54 GMT'), (b'Content-Encoding', b'gzip'), (b'via', b'2 fly.io'), (b'fly-request-id', b'01HGXQJR8RGKHPG45SGCG0E8QQ-lga'), (b'CF-Cache-Status', b'EXPIRED'), (b'Report-To', b'{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=ELR%2Fjs%2BwPpjQG%2FuHkCQdSGUuv%2BvrL9REtw8gnjAI2r5rGE5eehs4D0Q0BchlDO1mMr8EVWnC4iz7j0NLu4Au5ETkGLCfNGmS5c5PrV0Dy3x5f0atelue4QwQQzoVwVlyxg%3D%3D"}],"group":"cf-nel","max_age":604800}'), (b'NEL', b'{"success_fraction":0,"report_to":"cf-nel","max_age":604800}'), (b'Vary', b'Accept-Encoding'), (b'Server', b'cloudflare'), (b'CF-RAY', b'830eb9d4ee288c63-EWR'), (b'alt-svc', b'h3=":443"; ma=86400')])
Notice: HTTP Request: GET https://img.shields.io/static/v1?label=Coverage&message=80%25&color=orange "HTTP/1.1 200 OK"
##[debug]receive_response_body.started request=<Request [b'GET']>
##[debug]receive_response_body.complete
##[debug]response_closed.started
##[debug]response_closed.complete
##[debug]Current checkout is 
##[debug]Resetting all changes
##[debug]Branch python-coverage-comment-action-data exist.
##[debug]Writing file endpoint.json ({"schemaVersion": 1, "label": "Coverage", "message...)
##[debug]Writing file data.json ({"coverage": 80.72535647861129, "raw_data": {"meta...)
##[debug]Writing file badge.svg (<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlin...)
##[debug]Writing file README.md (# Repository Coverage
##[debug]
##[debug]
##[debug]
##[debug]| Name                   ...)
##[debug]Command failed: args=('git', 'diff', '--staged', '--exit-code') path=PosixPath('.') kwargs={'env': {'PATH': '/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOSTNAME': '67aa3d68edc9', 'GITHUB_REPOSITORY_ID': '***', 'GITHUB_SERVER_URL': 'https://github.com', 'GITHUB_WORKSPACE': '/github/workspace', 'ACTIONS_CACHE_URL': 'https://acghubeus2.actions.githubusercontent.com/mkHcM49NEyVC5s2ZEObfQ76SSXBf45H3iyuBtrWJcUpLgG8gLy/', 'Python3_ROOT_DIR': '/opt/hostedtoolcache/Python/3.10.13/x64', 'INPUT_COVERAGE_DATA_BRANCH': 'python-coverage-comment-action-data', 'HOME': '/github/home', 'GITHUB_REF_NAME': 'main', 'RUNNER_ARCH': 'X64', 'RUNNER_TOOL_CACHE': '/opt/hostedtoolcache', 'RUNNER_WORKSPACE': '/home/runner/work/***', 'ACTIONS_RESULTS_URL': 'https://results-receiver.actions.githubusercontent.com/', 'REDIS_HOST': 'localhost', 'Python_ROOT_DIR': '/opt/hostedtoolcache/Python/3.10.13/x64', 'GITHUB_TRIGGERING_ACTOR': 'tamerc', 'GITHUB_STATE': '/github/file_commands/save_state_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'RUNNER_NAME': 'GitHub Actions 9', 'MERGE_COVERAGE_FILES': 'false', 'ANNOTATION_TYPE': 'warning', 'GITHUB_EVENT_PATH': '/github/workflow/event.json', 'GITHUB_ACTOR': 'gabehenriques', 'GITHUB_HEAD_REF': '', 'GITHUB_PR_RUN_ID': '', 'GITHUB_REPOSITORY': '***', 'GITHUB_RUN_NUMBER': '3120', 'GITHUB_ACTION_REF': 'v3', 'GITHUB_TOKEN': '***', 'GITHUB_GRAPHQL_URL': 'https://api.github.com/graphql', 'GITHUB_ACTION_REPOSITORY': 'py-cov-action/python-coverage-comment-action', 'COMMENT_ARTIFACT_NAME': 'python-coverage-comment-action', 'GITHUB_WORKFLOW_SHA': '989f3ec8cfdd9b09de5501d849f0af82c10e3aff', 'PRIVATE_REPO_TOKEN': '***', 'LD_LIBRARY_PATH': '/opt/hostedtoolcache/Python/3.10.13/x64/lib', 'INPUT_MINIMUM_GREEN': '100', 'SUBPROJECT_ID': '', 'GITHUB_REPOSITORY_OWNER': '***', 'GITHUB_RETENTION_DAYS': '90', 'RUNNER_OS': 'Linux', 'Python2_ROOT_DIR': '/opt/hostedtoolcache/Python/3.10.13/x64', 'INPUT_MINIMUM_ORANGE': '70', 'COMMENT_FILENAME': 'python-coverage-comment-action.txt', 'GITHUB_ACTIONS': 'true', 'INPUT_COMMENT_ARTIFACT_NAME': 'python-coverage-comment-action', 'GITHUB_REF': 'refs/heads/main', 'GITHUB_ENV': '/github/file_commands/set_env_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'COVERAGE_PATH': './api/', 'GITHUB_SHA': '989f3ec8cfdd9b09de5501d849f0af82c10e3aff', 'GITHUB_ACTION': '__py-cov-action_python-coverage-comment-action', 'GITHUB_PATH': '/github/file_commands/add_path_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'RUNNER_DEBUG': '1', 'pythonLocation': '/opt/hostedtoolcache/Python/3.10.13/x64', 'INPUT_COVERAGE_PATH': './api/', 'INPUT_MERGE_COVERAGE_FILES': 'false', 'GITHUB_WORKFLOW_REF': '***/.github/workflows/api-lint-and-test.yml@refs/heads/main', 'PKG_CONFIG_PATH': '/opt/hostedtoolcache/Python/3.10.13/x64/lib/pkgconfig', 'INPUT_COMMENT_FILENAME': 'python-coverage-comment-action.txt', 'GITHUB_RUN_ATTEMPT': '2', 'ANNOTATE_MISSING_LINES': 'false', 'GITHUB_RUN_ID': '7105[154](https://github.com/***/actions/runs/7105154712/job/19343116405#step:12:155)712', 'GITHUB_REF_PROTECTED': 'true', 'RUNNER_ENVIRONMENT': 'github-hosted', 'ACTIONS_RUNTIME_TOKEN': '***', 'PYTHON_DEFAULT_VERSION': '3.10', 'INPUT_GITHUB_TOKEN': '***', 'INPUT_COMMENT_TEMPLATE': '', 'GITHUB_ACTOR_ID': '30266803', 'GITHUB_BASE_REF': '', 'ACTIONS_RUNTIME_URL': 'https://pipelinesghubeus10.actions.githubusercontent.com/mkHcM49NEyVC5s2ZEObfQ76SSXBf45H3iyuBtrWJcUpLgG8gLy/', 'INPUT_ANNOTATE_MISSING_LINES': 'false', 'MINIMUM_ORANGE': '70', 'GITHUB_JOB': 'api-test', 'INPUT_ANNOTATION_TYPE': 'warning', 'INPUT_VERBOSE': 'false', 'COVERAGE_DATA_BRANCH': 'python-coverage-comment-action-data', 'GITHUB_EVENT_NAME': 'push', 'GITHUB_REF_TYPE': 'branch', 'GITHUB_OUTPUT': '/github/file_commands/set_output_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'INPUT_SUBPROJECT_ID': '', 'COMMENT_TEMPLATE': '', 'VERBOSE': 'false', 'GITHUB_STEP_SUMMARY': '/github/file_commands/step_summary_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'RUNNER_TEMP': '/home/runner/work/_temp', 'CI': 'true', 'INPUT_GITHUB_PR_RUN_ID': '', 'GITHUB_WORKFLOW': 'API - Lint and test', 'GITHUB_API_URL': 'https://api.github.com', 'MINIMUM_GREEN': '100', 'GITHUB_REPOSITORY_OWNER_ID': '26981421', 'LANG': 'C.UTF-8', 'GPG_KEY': 'A035C8C19219BA821ECEA86B64E628F8D684696D', 'PYTHON_VERSION': '3.11.6', 'PYTHON_PIP_VERSION': '23.2.1', 'PYTHON_SETUPTOOLS_VERSION': '65.5.1', 'PYTHON_GET_PIP_URL': 'https://github.com/pypa/get-pip/raw/4cfa4081d27285bda1220a62a5ebf5b4bd749cdb/public/get-pip.py', 'PYTHON_GET_PIP_SHA256': '9cc0[166](https://github.com/***/actions/runs/7105154712/job/19343116405#step:12:167)5956d22b3bf057ae8287b035827bfd895da235bcea200ab3b811790b6', 'PIP_DISABLE_PIP_VERSION_CHECK': '1', 'PIP_ROOT_USER_ACTION': 'ignore', 'PIP_NO_CACHE_DIR': 'off'}} exc.stderr=''
Notice: Saving coverage files
Notice: Files saved
##[debug]Back to checkout of 
##[debug]Command failed: args=('git', 'switch', '') path=PosixPath('.') kwargs={'env': {'PATH': '/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOSTNAME': '67aa3d68edc9', 'GITHUB_REPOSITORY_ID': '***', 'GITHUB_SERVER_URL': 'https://github.com', 'GITHUB_WORKSPACE': '/github/workspace', 'ACTIONS_CACHE_URL': 'https://acghubeus2.actions.githubusercontent.com/mkHcM49NEyVC5s2ZEObfQ76SSXBf45H3iyuBtrWJcUpLgG8gLy/', 'Python3_ROOT_DIR': '/opt/hostedtoolcache/Python/3.10.13/x64', 'INPUT_COVERAGE_DATA_BRANCH': 'python-coverage-comment-action-data', 'HOME': '/github/home', 'GITHUB_REF_NAME': 'main', 'RUNNER_ARCH': 'X64', 'RUNNER_TOOL_CACHE': '/opt/hostedtoolcache', 'RUNNER_WORKSPACE': '/home/runner/work/***', 'ACTIONS_RESULTS_URL': 'https://results-receiver.actions.githubusercontent.com/', 'REDIS_HOST': 'localhost', 'Python_ROOT_DIR': '/opt/hostedtoolcache/Python/3.10.13/x64', 'GITHUB_TRIGGERING_ACTOR': 'tamerc', 'GITHUB_STATE': '/github/file_commands/save_state_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'RUNNER_NAME': 'GitHub Actions 9', 'MERGE_COVERAGE_FILES': 'false', 'ANNOTATION_TYPE': 'warning', 'GITHUB_EVENT_PATH': '/github/workflow/event.json', 'GITHUB_ACTOR': 'gabehenriques', 'GITHUB_HEAD_REF': '', 'GITHUB_PR_RUN_ID': '', 'GITHUB_REPOSITORY': '***', 'GITHUB_RUN_NUMBER': '3120', 'GITHUB_ACTION_REF': 'v3', 'GITHUB_TOKEN': '***', 'GITHUB_GRAPHQL_URL': 'https://api.github.com/graphql', 'GITHUB_ACTION_REPOSITORY': 'py-cov-action/python-coverage-comment-action', 'COMMENT_ARTIFACT_NAME': 'python-coverage-comment-action', 'GITHUB_WORKFLOW_SHA': '989f3ec8cfdd9b09de5501d849f0af82c10e3aff', 'PRIVATE_REPO_TOKEN': '***', 'LD_LIBRARY_PATH': '/opt/hostedtoolcache/Python/3.10.13/x64/lib', 'INPUT_MINIMUM_GREEN': '100', 'SUBPROJECT_ID': '', 'GITHUB_REPOSITORY_OWNER': '***', 'GITHUB_RETENTION_DAYS': '90', 'RUNNER_OS': 'Linux', 'Python2_ROOT_DIR': '/opt/hostedtoolcache/Python/3.10.13/x64', 'INPUT_MINIMUM_ORANGE': '70', 'COMMENT_FILENAME': 'python-coverage-comment-action.txt', 'GITHUB_ACTIONS': 'true', 'INPUT_COMMENT_ARTIFACT_NAME': 'python-coverage-comment-action', 'GITHUB_REF': 'refs/heads/main', 'GITHUB_ENV': '/github/file_commands/set_env_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'COVERAGE_PATH': './api/', 'GITHUB_SHA': '989f3ec8cfdd9b09de5501d849f0af82c10e3aff', 'GITHUB_ACTION': '__py-cov-action_python-coverage-comment-action', 'GITHUB_PATH': '/github/file_commands/add_path_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'RUNNER_DEBUG': '1', 'pythonLocation': '/opt/hostedtoolcache/Python/3.10.13/x64', 'INPUT_COVERAGE_PATH': './api/', 'INPUT_MERGE_COVERAGE_FILES': 'false', 'GITHUB_WORKFLOW_REF': '***/.github/workflows/api-lint-and-test.yml@refs/heads/main', 'PKG_CONFIG_PATH': '/opt/hostedtoolcache/Python/3.10.13/x64/lib/pkgconfig', 'INPUT_COMMENT_FILENAME': 'python-coverage-comment-action.txt', 'GITHUB_RUN_ATTEMPT': '2', 'ANNOTATE_MISSING_LINES': 'false', 'GITHUB_RUN_ID': '7105154712', 'GITHUB_REF_PROTECTED': 'true', 'RUNNER_ENVIRONMENT': 'github-hosted', 'ACTIONS_RUNTIME_TOKEN': '***', 'PYTHON_DEFAULT_VERSION': '3.10', 'INPUT_GITHUB_TOKEN': '***', 'INPUT_COMMENT_TEMPLATE': '', 'GITHUB_ACTOR_ID': '*', 'GITHUB_BASE_REF': '', 'ACTIONS_RUNTIME_URL': 'https://pipelinesghubeus10.actions.githubusercontent.com/mkHcM49NEyVC5s2ZEObfQ76SSXBf45H3iyuBtrWJcUpLgG8gLy/', 'INPUT_ANNOTATE_MISSING_LINES': 'false', 'MINIMUM_ORANGE': '70', 'GITHUB_JOB': 'api-test', 'INPUT_ANNOTATION_TYPE': 'warning', 'INPUT_VERBOSE': 'false', 'COVERAGE_DATA_BRANCH': 'python-coverage-comment-action-data', 'GITHUB_EVENT_NAME': 'push', 'GITHUB_REF_TYPE': 'branch', 'GITHUB_OUTPUT': '/github/file_commands/set_output_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'INPUT_SUBPROJECT_ID': '', 'COMMENT_TEMPLATE': '', 'VERBOSE': 'false', 'GITHUB_STEP_SUMMARY': '/github/file_commands/step_summary_c2378a73-a5b6-43b9-82bf-31b47818ac63', 'RUNNER_TEMP': '/home/runner/work/_temp', 'CI': 'true', 'INPUT_GITHUB_PR_RUN_ID': '', 'GITHUB_WORKFLOW': 'API - Lint and test', 'GITHUB_API_URL': 'https://api.github.com', 'MINIMUM_GREEN': '100', 'GITHUB_REPOSITORY_OWNER_ID': '26981421', 'LANG': 'C.UTF-8', 'GPG_KEY': 'A035C8C19219BA821ECEA86B64E628F8D684696D', 'PYTHON_VERSION': '3.11.6', 'PYTHON_PIP_VERSION': '23.2.1', 'PYTHON_SETUPTOOLS_VERSION': '65.5.1', 'PYTHON_GET_PIP_URL': 'https://github.com/pypa/get-pip/raw/4cfa4081d27285bda1220a62a5ebf5b4bd749cdb/public/get-pip.py', 'PYTHON_GET_PIP_SHA256': '9cc01665956d22b3bf057ae8287b035827bfd895da235bcea200ab3b81[179](https://github.com/***/actions/runs/7105154712/job/19343116405#step:12:180)0b6', 'PIP_DISABLE_PIP_VERSION_CHECK': '1', 'PIP_ROOT_USER_ACTION': 'ignore', 'PIP_NO_CACHE_DIR': 'off'}} exc.stderr='fatal: invalid reference: \n'
Error: Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com//py-cov-action/python-coverage-comment-action#basic-usage

LFS-enabled repo failing with permission and/or lfs issue

Hi,

I'm getting this with a (private) repo having lfs enabled:

Notice: Creating branch python-coverage-comment-action-data
Error: Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com/py-cov-action/python-coverage-comment-action#basic-usage
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 17, in run
    return subprocess.run(
  File "/usr/local/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('git', 'fetch', 'origin', 'python-coverage-comment-action-data')' returned non-zero exit status 128.

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 54, in _git
    return run(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 25, in run
    raise SubProcessError("\n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError: 
fatal: couldn't find remote ref python-coverage-comment-action-data

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/storage.py", line 41, in checked_out_branch
    git.fetch("origin", branch)
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 62, in _git
    raise GitError from exc
coverage_comment.subprocess.GitError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 17, in run
    return subprocess.run(
  File "/usr/local/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('git', 'switch', '--orphan', 'python-coverage-comment-action-data')' returned non-zero exit status 1.

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 54, in _git
    return run(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 25, in run
    raise SubProcessError("\n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError:

then at the end:

Switched to a new branch 'python-coverage-comment-action-data'

This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').

I'm not sure which error is the real one..

is lfs issue or permission issue ?

EDIT:

fwiw: have NOT lfs: true in my checkout step before but given the last message I'm not sure that would help..

EDIT2: well, should I only:

rm .git/hooks/post-checkout

before the step as proposed by the last error message ?

error: failed to push some refs to... Updates were rejected because the tip of your current branch is behind its remote counterpart

https://github.com/py-cov-action/python-coverage-comment-action/actions/runs/4100505236/jobs/7071400413#step:9:57

This is apparently because of #124 but I haven't understood yet why it happens.

EDIT: OK

  • we generate the htmlcov folder on the main branch, but we want to commit it on the coverage branch. I hadn't realized that, so I did nothing initially and it worked, because modified files are moved when we checkout
  • but as soon as we're working on a directory where we already have committed htmlcov files, it fails because we can't checkout anymore
  • we need to save the whole htmlcov dir somewhere, then checkout, then delete the previously committed htmlcov, copy the new one back, git add . and commit

What would be the best way of "saving" the htmlcov dir:

  • git stashing it ?
  • saving it to /tmp ?
  • saving each individual file in memory, in a list of objects ?
  • saving a single zip in memory and then expanding it back ?
    Meanwhile, I've reverted the HTML report so it doesn't fail everyone's CI

Issues with the action starting Jan 1st or 2nd ? (3.19)

I'm releasing 3.19 which contains the new format for PR comments (#211). I've spent quite some time working on it on the last week, and I hope you like it, but if you find yourself being here, I believe I forgot something and it broke someone's workflow. I've tried testing it here and there, and didn't find a problem.

I'm all ears :) Tell me what broke :) Also, I'll be actively accepting names of people to ping before I merge big PRs to try them on various codebases and avoid disruption.

BTW, if you preferred the old format, use the following setting:
COMMENT_TEMPLATE: |
  {% block title %}## Coverage report{% if subproject_id %} ({{ subproject_id  }}){% endif %}{% endblock title %}
  {% block coverage_evolution -%}
  {% if previous_coverage_rate -%}
  {% block coverage_evolution_wording -%}
  The coverage rate went from `{{ previous_coverage_rate | pct }}` to `{{ coverage.info.percent_covered | pct }}`{{" "}}
  {%- endblock coverage_evolution_wording %}
  {%- block emoji_coverage -%}
  {%- if previous_coverage_rate | float < coverage.info.percent_covered | float -%}
  {%- block emoji_coverage_up -%}:arrow_up:{%- endblock emoji_coverage_up -%}
  {%- elif previous_coverage_rate | float > coverage.info.percent_covered | float -%}
  {%- block emoji_coverage_down -%}:arrow_down:{%- endblock emoji_coverage_down -%}
  {%- else -%}
  {%- block emoji_coverage_constant -%}:arrow_right:{%- endblock emoji_coverage_constant -%}
  {%- endif %}
  {%- endblock emoji_coverage -%}
  {%- else -%}
  {% block no_comparison_info -%}
  {%- if pr_targets_default_branch -%}
  {% block no_comparison_info_data_not_found_message -%}
  > [!NOTE]
  > Coverage data for the default branch was not found.
  > This usually happens when the action has not run on the default
  > branch yet, for example right after deploying it into the workflows.
  {%- endblock no_comparison_info_data_not_found_message -%}
  {% else %}
  {% block no_comparison_info_non_default_target -%}
  > [!NOTE]
  > Coverage evolution disabled because this PR targets a different branch
  > than the default branch, for which coverage data is not available.
  {%- endblock no_comparison_info_non_default_target %}
  {%- endif %}
  {%- endblock no_comparison_info %}

  {% block coverage_value_wording -%}
  The coverage rate is `{{ coverage.info.percent_covered | pct }}`.
  {%- endblock coverage_value_wording %}
  {%- endif %}
  {%- endblock coverage_evolution %}
  {% block branch_coverage -%}
  {% if coverage.meta.branch_coverage and coverage.info.num_branches -%}
  {% block branch_coverage_wording -%}
  The branch rate is `{{ (coverage.info.covered_branches / coverage.info.num_branches) | pct }}`.
  {% endblock branch_coverage_wording -%}
  {%- endif %}
  {% endblock branch_coverage -%}

  {%- if diff_coverage.total_num_lines > 0 -%}
  {% block diff_coverage_wording -%}
  `{{ diff_coverage.total_percent_covered | pct }}` of new lines are covered.
  {%- endblock diff_coverage_wording %}
  {%- else -%}
  {% block diff_coverage_empty_wording -%}
  _None of the new lines are part of the tested code. Therefore, there is no coverage data about them._
  {%- endblock diff_coverage_empty_wording %}
  {%- endif %}

  {% block coverage_by_file -%}
  {%if diff_coverage.files -%}
  <details>
  <summary>{% block coverage_by_file_summary_wording -%}Diff Coverage details (click to unfold){% endblock coverage_by_file_summary_wording -%}</summary>
  {% for filename, diff_file_coverage in diff_coverage.files.items() -%}
  {% block coverage_single_file scoped %}
  {% block coverage_single_file_title scoped %}### {{ filename }}{% endblock coverage_single_file_title %}
  {% block diff_coverage_single_file_wording scoped -%}
  `{{ diff_file_coverage.percent_covered | pct }}` of new lines are covered (`{{ coverage.files[filename].info.percent_covered | pct }}` of the complete file).
  {%- endblock diff_coverage_single_file_wording %}
  {%- if diff_file_coverage.violation_lines -%}
  {% block single_file_missing_lines_wording scoped -%}
  {% set separator = joiner(", ") %}
  Missing lines: {% for line in diff_file_coverage.violation_lines %}{{ separator() }}`{{ line }}`{% endfor %}
  {%- endblock single_file_missing_lines_wording %}
  {%- endif %}
  {% endblock coverage_single_file -%}
  {%- endfor %}
  </details>
  {%- endif %}
  {%- endblock coverage_by_file %}
  {{ marker }}

Always getting "100% of new lines are covered"

Thanks for writing this interesting GH action script. I was experimenting with it in a sandbox repo. The line and branch coverage appears to be working as intended but the new line coverage is always showing 100%.

I probably did something wrong in the configuration that I wasn't able to immediately notice. I wonder if you can lend an eye on this?

This is a pull request where I deliberately introduced code that's not covered by tests. acwl-aiq/lambda_lock_poc#7

Additionally, is there a config I can use to make decreases in line/branch coverage to show red instead of blue? Thanks!

Don't publish the docker image if the CI fails

we need a way to avoid publishing the docker image if the ci fails. Probably using on: workflow_run and restricting on:

  • CI workflow being successful
  • CI workflow event to be a push on the v3 branch (and not a PR targetting the v3 branch and/or based on a head branch also named v3 but on a fork)

Support private repository wikis

Right now, if a repository's wiki is private, this action will not work, since private wikis cannot have their content accessed using raw.githubusercontent.com.

subprocess.CalledProcessError: Command '('coverage', 'json', '-o', '-')' returned non-zero exit status 2.

2023-12-04T14:04:41.0481051Z ##[notice]Starting action
2023-12-04T14:04:41.2909319Z ##[notice]HTTP Request: GET https://api.github.com/repos/descope/python-sdk "HTTP/1.1 200 OK"
2023-12-04T14:04:41.2916256Z ##[notice]Generating comment for PR
2023-12-04T14:04:41.6464808Z ##[error]Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com/py-cov-action/python-coverage-comment-action#basic-usage
Otherwise please look for open issues or open one in https://github.com/py-cov-action/python-coverage-comment-action/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/subprocess.py", line 18, in run
    return subprocess.run(
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('coverage', 'json', '-o', '-')' returned non-zero exit status 2.

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 40, in main
    exit_code = action(
                ^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 92, in action
    return process_pr(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 123, in process_pr
    _, coverage = coverage_module.get_coverage_info(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/coverage.py", line 84, in get_coverage_info
    subprocess.run("coverage", "json", "-o", "-", path=coverage_path)
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/subprocess.py", line 27, in run
    raise SubProcessError("\n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError: {"meta": {"version": "7.3.2", "timestamp": "2023-12-04T14:04:41.489052", "branch_coverage": false, "show_contexts": false}, "files": {"descope/__init__.py": {"executed_lines": [1, 10, 11, 18, 19], "summary": {"covered_lines": 5, "num_statements": 5, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "descope/_auth_base.py": {"executed_lines": [2, 5, 6, 8, 9], "summary": {"covered_lines": 4, "num_statements": 4, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "descope/auth.py": {"executed_lines": [1, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 19, 20, 21, 23, 35, 47, 48, 49, 54, 62, 63, 65, 74, 76, 77, 78, 86, 87, 88, 90, 91, 92, 94, 95, 96, 97, 99, 100, 102, 103, 104, 116, 123, 131, 132, 134, 137, 146, 147, 149, 152, 160, 161, 163, 164, 165, 171, 172, 173, 174, 177, 179, 180, 183, 184, 186, 187, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 208, 210, 212, 213, 214, 220, 221, 225, 227, 228, 229, 235, 236, 240, 242, 243, 244, 250, 251, 255, 257, 258, 259, 260, 266, 267, 268, 269, 273, 274, 275, 276, 282, 283, 287, 288, 292, 295, 296, 297, 298, 302, 303, 304, 306, 307, 308, 309, 315, 316, 317, 318, 319, 325, 326, 327, 333, 334, 335, 340, 342, 343, 344, 350, 352, 353, 355, 356, 358, 364, 366, 372, 374, 375, 376, 377, 378, 379, 384, 385, 386, 387, 388, 393, 395, 396, 399, 400, 403, 404, 407, 410, 414, 415, 416, 419, 424, 428, 433, 435, 438, 440, 442, 449, 450, 451, 452, 453, 454, 455, 458, 459, 463, 465, 466, 473, 475, 481, 485, 486, 487, 489, 490, 491, 492, 493, 494, 495, 498, 501, 507, 508, 509, 510, 516, 517, 518, 522, 523, 524, 528, 529, 530, 532, 533, 541, 543, 544, 551, 552, 559, 560, 566, 567, 569, 572, 573, 579, 580, 583, 585, 588, 595, 597, 598, 600, 601, 603, 609, 610, 616, 617, 618, 620, 626, 628, 647, 648, 649, 650, 651, 652], "summary": {"covered_lines": 269, "num_statements": 288, "percent_covered": 93.40277777777777, "percent_covered_display": "93", "missing_lines": 19, "excluded_lines": 0}, "missing_lines": [16, 17, 50, 51, 389, 391, 502, 534, 545, 589, 621, 629, 630, 636, 637, 641, 642, 645, 653], "excluded_lines": []}, "descope/authmethod/__init__.py": {"executed_lines

https://github.com/descope/python-sdk/actions/runs/7086877486/job/19288591568

I do not think this is a permission error, as permissions are there and it's been working well for a while

looks like the input is truncated by this might be github logs issue and not really

upload-artefact@v4 is incompatible with our advertised way of handling multiple python versions

https://github.com/actions/upload-artifact#breaking-changes

Due to how Artifacts are created in this new version, it is no longer possible to upload to the same named Artifact multiple times. You must either split the uploads into multiple Artifacts with different names, or only upload once. Otherwise you will encounter an error.

We used to upload all coverage files to the same artifact, and they were automatically merged. This is not possible anymore.

New subprocess error "detected dubious ownership in repository at '/github/workspace'"

subprocess.CalledProcessError: Command '('git', 'fetch', '--depth=1000')' returned non-zero exit status 128.

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

Traceback (most recent call last):
  File "/usr/local/bin/coverage_comment", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 39, in main
    exit_code = action(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 76, in action
    return generate_comment(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 108, in generate_comment
    diff_coverage = coverage_module.get_diff_coverage_info(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/coverage.py", line 187, in get_diff_coverage_info
    subprocess.run("git", "fetch", "--depth=1000")
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 25, in run
    raise SubProcessError("/n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError: /nfatal: detected dubious ownership in repository at '/github/workspace'
To add an exception for this directory, call:

Something seems to have changed the end of January.. git version upgrade perhaps?

Change behaviour when missing coverage data for the default branch

It might be helpful to write in the PR-comment that there is no comparative data in PR mode if no coverage data for the default branch was found, instead of crashing the action. This would not lead to so much confusion when the action is set up by a PR (#15, #48).
This is nothing urgent, but something I wanted to put here so that I don't forget it.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Lock file maintenance

Detected dependencies

dockerfile
Dockerfile
  • ewjoachim/python-coverage-comment-action-base v6
github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-python v5
  • actions/cache v4
  • actions/upload-artifact v4
.github/workflows/coverage-comment.yml
.github/workflows/e2e-delete-repo.yml
.github/workflows/e2e-external-phase-1.yml
  • actions/upload-artifact v4
.github/workflows/e2e-external-phase-2.yml
  • actions/checkout v4
  • actions/setup-python v5
  • actions/cache v4
.github/workflows/e2e-private-link-in-pr.yml
.github/workflows/e2e-public-link-in-pr.yml
.github/workflows/manual-release.yml
  • actions/checkout v4
.github/workflows/release.yml
  • docker/login-action v3
  • docker/build-push-action v5
  • actions/checkout v4
tests/end_to_end/repo/.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-python v5
  • actions/upload-artifact v4
tests/end_to_end/repo/.github/workflows/coverage-comment.yml
pep621
pyproject.toml
  • poetry-core >=1.0.0
tests/end_to_end/repo/pyproject.toml
poetry
pyproject.toml
  • python ^3.12
  • coverage *
  • httpx *
  • Jinja2 *
  • ruff *
  • mypy *
  • pytest *
  • pytest-cov *
  • pytest-mock *
  • tenacity *
pre-commit
.pre-commit-config.yaml
  • pre-commit/pre-commit-hooks v4.5.0
  • astral-sh/ruff-pre-commit v0.3.2
  • floatingpurr/sync_with_poetry 1.1.0

  • Check this box to trigger a request for Renovate to run again on this repository

v3: setoutput is deprecated

When using py-cov-action/python-coverage-comment-action@v3 in a workflow, the follow warning is reported by Github:

The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files.

In the v2 branch, commit 9c01da2 was added to correct the issue, this appears to be missing in the v3 branch.

File not found in the wiki, Skips "Store Pull Request comment to be posted"

I'm having trouble understanding what is happening here: https://github.com/aGuttman/e-mission-server/runs/6683601645?check_suite_focus=true

The action creates/edits a PR comment fine, but fails to store any artifacts to track evolution or display a badge. The problem seems to start in "Coverage comment" where I get the warnings:

WARNING:coverage_comment:File not found in the wiki's git repository.
WARNING:coverage_comment:Previous coverage results not found, cannot report on evolution.

and then "Store Pull Request comment to be posted" is skipped.

I don't know if I'm doing something wrong. I don't understand GitHub actions very well, but the yml files are basically just copy/pasted from the readme, I'm using all the default values, and I'm working with an already generated .coverage file for testing proposes.

If I try to comment out the conditional in "Store Pull Request comment to be posted" it gives the following warning when run:

Warning: No files were found with the provided path: python-coverage-comment-action.txt. No artifacts will be uploaded.

Comment doesn't get published

Hey it's me again ๐Ÿ˜ฆ

Now the action is creating the branch and updating it when in "default branch mode". But when run in a PR it doens't publish a comment at all.
Here's my jobs definition

# .github/workflows/build.yml
name: build/test
on: push

jobs:
  test:
    name: Test
    needs: install
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v3

      - name: Get virtualenv
        uses: ./.github/actions/get_venv

      - name: Test with pytest
        run: |
          ./venv/Scripts/activate.ps1
          pytest --cov alteryx_xml_tool --cov-report term-missing --cov-report html --durations 10

      - name: Store coverage file
        uses: actions/upload-artifact@v3
        with:
          name: coverage
          path: .coverage

  coverage:
    # must run with linux
    name: Coverage
    runs-on: ubuntu-latest
    needs: test
    permissions:
        contents: write
        pull-requests: write
    steps:
      - uses: actions/checkout@v3

      - uses: actions/download-artifact@v3
        id: download
        with:
          name: coverage
          path: .

      - name: Coverage comment
        id: coverage_comment
        uses: py-cov-action/python-coverage-comment-action@v3
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Store Pull Request comment to be posted
        uses: actions/upload-artifact@v3
        if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
        with:
          name: python-coverage-comment-action
          path: python-coverage-comment-action.txt
#.github/workflows/coverage.yml
name: Post coverage comment

on:
  workflow_run:
    workflows: ["build/test"]
    types:
      - completed

jobs:
  test:
    name: Run tests & display coverage
    runs-on: ubuntu-latest
    if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
    permissions:
      # Gives the action the necessary permissions for publishing new
      # comments in pull requests.
      pull-requests: write
      # Gives the action the necessary permissions for editing existing
      # comments (to avoid publishing multiple comments in the same PR)
      contents: write
      # Gives the action the necessary permissions for looking up the
      # workflow that launched this workflow, and download the related
      # artifact that contains the comment to be published
      actions: read
    steps:
      # DO NOT run actions/checkout here, for security reasons
      # For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
      - name: Post comment
        uses: py-cov-action/python-coverage-comment-action@v3
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
          # Update those if you changed the default values:
          # COMMENT_ARTIFACT_NAME: python-coverage-comment-action
          # COMMENT_FILENAME: python-coverage-comment-action.txt

The thing is the store comment step gets skipped in both pr/default branch mode
image
and so does the coverage.yml workflow
image

Changing the storage strategy

Continuation from the discussion in #29

So we're thinking about changing the storage strategy from "wiki" to "dedicated branch.

  • This will require a major version bump (v3)
  • Also, on the v2 branch, make sure we target the v2 docker image
  • I think the idea would be that we specify the branch in the actions settings. If not set, we would use a default name (python-coverage-comment-action-data ?) we would create an empty branch (as in: git checkout --orphan <branch>, git reset --hard)
  • Optionnal (but if we're rewriting this code anyway) We could always push 3 files : the svg itself (so that will make the private repo work as well) and a json containing details of the coverage run (a floating point coverage percentage with 2 decimal digits so we wouldn't loose too much precision when saying if the rate increase or decreased) and a json for the shields endpoint.
  • We would post all the URLs when the action runs:
    • the url to the image directly (and mention that it's the solution for private repos)
    • the url to the dynamic endpoint (and mention that it cannot have a dynamic color, it will always be the color you choose)
    • the url to the json endpoint (and mention that one can override parts of the style)
    • (and maybe the shields pages with the documentation)
  • When pushing the branch for the first time, it would be great to also push a README.md. Explain what this branch is, point to the action URL.
  • In the documentation, be clear that this action will push to a dedicated branch. This means users may have to tweak existing workflow if those workflow trigger on all branches pushes ?

Running coverage action in tag push events produce misleading error message

This change makes the coverage action produce a misleading error message about permissions, when the issue is that the event triggering the action does not relate to a pull request and/or branch:

2023-10-11T13:32:08.2937186Z ##[notice]Starting action
2023-10-11T13:32:08.6275828Z ##[notice]HTTP Request: GET https://api.github.com/repos/claranet/tfwrapper "HTTP/1.1 200 OK"
2023-10-11T13:32:08.6279564Z ##[notice]Generating comment for PR
2023-10-11T13:32:10.0641449Z ##[notice]HTTP Request: GET https://api.github.com/repos/claranet/tfwrapper/contents/data.json?ref=python-coverage-comment-action-data "HTTP/1.1 200 OK"
2023-10-11T13:32:10.0834693Z ##[error]Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com/py-cov-action/python-coverage-comment-action#basic-usage
Otherwise please look for open issues or open one in https://github.com/py-cov-action/python-coverage-comment-action/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 40, in main
    exit_code = action(
                ^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 92, in action
    return process_pr(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 180, in process_pr
    assert config.GITHUB_BRANCH_NAME
AssertionError

See this execution for example: https://github.com/claranet/tfwrapper/actions/runs/6483246492/job/17604440212#step:5:22

`parse_diff_output()` raises AssertionError in v3.12

Hello, and thanks for creating this GH Action! I have a workflow that fails on v3.12 but succeeds on v3.11...

Stack trace from failing workflow run when using v3.12...
Notice: Generating comment for PR
Error: Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com/py-cov-action/python-coverage-comment-action#basic-usage
Otherwise please look for open issues or open one in https://github.com/py-cov-action/python-coverage-comment-action/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 40, in main
    exit_code = action(
                ^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 92, in action
    return process_pr(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 121, in process_pr
    added_lines = coverage_module.get_added_lines(git=git, base_ref=base_ref)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/coverage.py", line 279, in get_added_lines
    return parse_diff_output(diff)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/coverage.py", line 291, in parse_diff_output
    assert current_file
AssertionError

It falls over on the line below, where it looks like current_file never gets updated:

Here's an example of an input diff for this function that fails on v3.12, but passes when I pin the action to v3.11:

Sample diff for `parse_diff_output()`...

Note
This diff was created by inserting the following step into the workflow directly before the python-coverage-comment-action step:

     - name: Debug CI on host
       run: |
         sudo apt-get install -y tree \
           && tree -a . \
           && git fetch origin dev --depth=1000 \
           && git diff --unified=1 FETCH_HEAD -- .

Let me know if you want to see the output of tree, but all the files are found as expected.

Sample diff:

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 7c0e612..e4ddca1 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -75,2 +75,17 @@ jobs:
         run: docker exec $CONTAINER_NAME yarn lint
+      
+      - name: Debug CI in container
+        run: |
+          docker exec $CONTAINER_NAME \
+            yum install -y tree \
+            && tree -a . \
+            && git fetch origin dev --depth=1000 \
+            && git diff --unified=1 FETCH_HEAD -- .
+
+      - name: Debug CI on host
+        run: |
+          sudo apt-get install -y tree \
+            && tree -a . \
+            && git fetch origin dev --depth=1000 \
+            && git diff --unified=1 FETCH_HEAD -- .

If it makes a difference this is from a PR where a feature branch is getting merged into dev. We use master as our default branch. Also, we haven't yet run this action on master so don't yet have the python-coverage-comment-action-data branch.

Unfortunately this is in a private work repo so I can't give links, but let me know if you need any more info.

Cheers,
Andrew.

Improve the link between action version and docker image version

Build Dockerfile seemlessly

It would be nice if we could read a local variable (DEBUG or BUILD_FROM_DOCKERFILE), (an action parameter that could be set set as repository variable or hardcoded in the workflow), that would switch from pulling the image to building it from the Dockerfile.

I'm sure we're not the first ones doing that, so maybe we can reuse something.

Use correct version

I believe that, as of today, using a release tag of the version still ends up using the latest docker version, so it's probably quite useless.

"missing line" annotations that span multiple lines?

The annotations get a bit noisy when an entire multi-line clause of code is missed. There's an annotation on every line. GitHub Action annotations have an endLine attribute, so we could create one annotation for an entire block of lines.

The difficulty is in knowing what block to mark. If lines 10 and 12 are missing, and 11 is blank, it should be one annotation on lines 10-12. But the coverage data will have "missing_lines": [10, 12]. Internally, coverage knows better. For example, coverage report -m would show 10-12, because coverage knows that line 11 wasn't a possibility.

Would you be interested in supporting something like this? We could figure out a good way for coverage to make the better information available.

Instructions for running built docker container.

Hey, thanks for the action!

I'm trying to figure out how to use the build docker container version to save build times, but it doesnt seem to be a drop in replacement:

- name: Coverage Report
      if: inputs.skip-coverage == 'false'
      id: coverage_comment
      uses: docker://docker.io/ewjoachim/python-coverage-comment-action:v2
      with:
          GITHUB_TOKEN: ${{ inputs.gh-token }}
          COVERAGE_PATH: ${{ inputs.project-root }}

Results in:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/settings.py", line 167, in from_environ
    config_obj = cls(**config)
                 ^^^^^^^^^^^^^
TypeError: Config.__init__() missing 2 required keyword-only arguments: 'GITHUB_TOKEN' and 'GITHUB_PR_RUN_ID'
During handling of the above exception, another exception occurred:

So maybe I need to provide different config parameters for the built docker image version..

COMMENT_FILE_WRITTEN always false

Hello guys,
could you please explain me this flag? When it is true? I followed your approach and we are able to generate comments with % coverage for our PRs, however I am not able to update the "python-coverage-comment-action-data" branch. The branch was generated, but now for my PRs, the flag is always false, and it wont store the comment. Thank you for your help!
Screenshot from 2023-10-23 15-18-28

No data collected by coverage package

Following the example here in my repo I get the following errors:
ERROR:coverage_comment:Cannot read .coverage files because files are absolute. You need to configure coverage to write relative paths by adding the following option to your coverage configuration file:
[run]
relative_files = true

My pytest.ini looks as:

[pytest]
testpaths =
    tests
norecursedirs=dist build .tox scripts
addopts =
    --cov-report term-missing --cov-branch  --cov-report xml --cov-report term --cov=src -vv --strict-markers -rfE
[run]
disable_warnings = no-data-collected

[coverage:run]
relative_files = true

Failed to generate comment for PR

While setting up the action as described in the docs, I came across this traceback.

I'm not sure, whether I missed something or whether there is an actual problem ๐Ÿค”

Run ewjoachim/python-coverage-comment-action@v2
  with:
    GITHUB_TOKEN: ***
    MERGE_COVERAGE_FILES: true
    VERBOSE: true
    BADGE_FILENAME: python-coverage-comment-action-badge.json
    COMMENT_ARTIFACT_NAME: python-coverage-comment-action
    COMMENT_FILENAME: python-coverage-comment-action.txt
    MINIMUM_GREEN: 100
    MINIMUM_ORANGE: 70
/usr/bin/docker run --name ewjoachimpythoncoveragecommentactionv2_52b40a --label 94859b --workdir /github/workspace --rm -e INPUT_GITHUB_TOKEN -e INPUT_MERGE_COVERAGE_FILES -e INPUT_VERBOSE -e INPUT_GITHUB_PR_RUN_ID -e INPUT_COMMENT_TEMPLATE -e INPUT_BADGE_FILENAME -e INPUT_COMMENT_ARTIFACT_NAME -e INPUT_COMMENT_FILENAME -e INPUT_MINIMUM_GREEN -e INPUT_MINIMUM_ORANGE -e GITHUB_TOKEN -e GITHUB_PR_RUN_ID -e COMMENT_TEMPLATE -e BADGE_FILENAME -e COMMENT_ARTIFACT_NAME -e COMMENT_FILENAME -e MINIMUM_GREEN -e MINIMUM_ORANGE -e MERGE_COVERAGE_FILES -e VERBOSE -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_TRIGGERING_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/osc-tiny/osc-tiny":"/github/workspace" ewjoachim/python-coverage-comment-action:v2
INFO:coverage_comment:Starting action
DEBUG:coverage_comment:Settings: Config(GITHUB_BASE_REF='master', GITHUB_REPOSITORY='crazyscientist/osc-tiny', GITHUB_REF='refs/pull/79/merge', GITHUB_EVENT_NAME='pull_request', GITHUB_PR_RUN_ID=None, COMMENT_TEMPLATE='', BADGE_FILENAME=PosixPath('python-coverage-comment-action-badge.json'), COMMENT_ARTIFACT_NAME='python-coverage-comment-action', COMMENT_FILENAME=PosixPath('python-coverage-comment-action.txt'), MINIMUM_GREEN=100.0, MINIMUM_ORANGE=70.0, MERGE_COVERAGE_FILES=True, VERBOSE=True)
DEBUG:coverage_comment:Operating on refs/pull/79/merge
INFO:coverage_comment:Generating comment for PR
DEBUG:httpx._client:HTTP Request: GET https://raw.githubusercontent.com/wiki/crazyscientist/osc-tiny/python-coverage-comment-action-badge.json "HTTP/1.1 404 Not Found"
DEBUG:coverage_comment:Exception while getting previous coverage data, attempting to download the file directly from the git repository (assuming the wiki is private).
DEBUG:coverage_comment:Unhandled error occurred when cloning wiki.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/wiki.py", line 85, in get_file_contents
    response.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 736, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://raw.githubusercontent.com/wiki/crazyscientist/osc-tiny/python-coverage-comment-action-badge.json'
For more information check: https://httpstatuses.com/404

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 16, in run
    return subprocess.run(
  File "/usr/local/lib/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('git', 'clone', '***github.com/crazyscientist/osc-tiny.wiki.git', '.')' returned non-zero exit status 128.

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 32, in _git
    return run(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 24, in run
    raise SubProcessError("/n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError: /nCloning into '.'...
fatal: remote error: access denied or repository not exported: /d/nw/d1/86/6a/195882036/161181449.wiki.git


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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/wiki.py", line 26, in cloned_wiki
    git.clone(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 39, in _git
    raise GitError from exc
coverage_comment.subprocess.GitError
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/wiki.py", line 85, in get_file_contents
    response.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 736, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://raw.githubusercontent.com/wiki/crazyscientist/osc-tiny/python-coverage-comment-action-badge.json'
For more information check: https://httpstatuses.com/404

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 16, in run
    return subprocess.run(
  File "/usr/local/lib/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('git', 'clone', '***github.com/crazyscientist/osc-tiny.wiki.git', '.')' returned non-zero exit status 128.

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 32, in _git
    return run(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 24, in run
    raise SubProcessError("/n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError: /nCloning into '.'...
fatal: remote error: access denied or repository not exported: /d/nw/d1/86/6a/195882036/161181449.wiki.git


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

Traceback (most recent call last):
  File "/usr/local/bin/coverage_comment", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 37, in main
    exit_code = action(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 69, in action
    return generate_comment(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 105, in generate_comment
    previous_coverage_data_file = wiki.get_file_contents(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/wiki.py", line 95, in get_file_contents
    with cloned_wiki(repository, git, github_token) as wiki_dir:
  File "/usr/local/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/wiki.py", line 34, in cloned_wiki
    raise exc
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/wiki.py", line 26, in cloned_wiki
    git.clone(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 39, in _git
    raise GitError from exc
coverage_comment.subprocess.GitError

Detailed statistics on the coverage data branch

It would be nice to use the coverage data branch not only for storing the data, but also to display other stats there.
For example, the HTML reports generated by pycoverage could be used for this.

Automated end to end test

Ping @kieferro

Trying to summarize what automated end to end tests would look like:

  • I think we'd need personnal access tokens from 2 distinct users. We can create 2 dedicated bot users just for the CI. The tests will be automatically skipped if the 2 tokens aren't passed via the env var
  • We'll use pytest fixtures to handle the creation and deletion of resources.
  • We'll use pytest fixtures to ease calling the gh CLI. The GH CLI can often output json, so we'll be able to easily read and write info to and from GitHub
  • And then we'll need some other fixtures:
  • repository fixture
    • cd to a temp directory
    • write a git repo with some code and the action configured (as well as a CI that computes coverage on some code)
    • create a github repo and push to it (wiki is active by default)
    • After the test, delete the github repo
  • fork fixture
    • fork the repo (bonus points for forking with a different repo name :) )
    • clone the fork
    • After the test, delete the fork
  • pr fixture (can be run from either user)
    • checkout a new branch
    • change some code
    • git commit -am foo && gh pr open

Also, gh run watch --exit-status lets us easily have a command we can call that will wait for the CI to run and raise if it failed.

With all that we can have:

  • A test that pushes some code on the default branch, waits for the CI and checks that the Coverage Badge is working.
  • A test that pushes some code, then creates a branch and pushes code from the same user, check that the comment is posted
  • A test that pushes some code, then from a different user, pushes code in a new branch and check that the comment is also posted

If we have that and given we have 100% coverage, we should be quite all set :D

Allow for optional use of a wiki

I'm trying to use this action on a private repository where I don't have the ability to enable the wiki (without upgrading to a paid GH package). It would be great if the use of a wiki would be optional. I understand that without a badge json, you cannot show changes in coverage, but even without that feature, it would be a great action.

No coverage comment

Hello, I have tried to debug this problem but run out of ideas. Base on exception message I see what line is raising the error its referring to missing GITHUB_TOKEN but its included

#.github/workflows/pr-review.yml
name: Pull request auto review

on:
    pull_request:
      branches:
        - main

jobs:
  test:
    name: Run tests & display coverage
    runs-on: ubuntu-latest
    timeout-minutes: 5
    permissions:
      pull-requests: write
      contents: write

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.9
      - name: Install dependencies
        run: |
          # install dependencies
          python -m pip install --upgrade pip
          pip install pipenv
          pipenv install --dev

      # - name: Lint with flake8
      #   run: |
      #     make lint
      - name: Test with coverage
        run: |
          make test
          cd src
          ls -al
      - name: Coverage comment
        id: coverage_comment
        uses: py-cov-action/python-coverage-comment-action@v3
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Store Pull Request comment to be posted
        uses: actions/upload-artifact@v3
        if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
        with:
          name: python-coverage-comment-action
          path: python-coverage-comment-action.txt

I was following readme file, and part responsible for github token looks good to me.

#/.github/workflows/coverage.yml
name: Post coverage comment

on:
  workflow_run:
    workflows: ["Pull request auto review"]
    types:
      - completed

jobs:
  test:
    name: Display coverage
    runs-on: ubuntu-latest
    if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
    permissions:
      pull-requests: write
      contents: write
      actions: read
    steps:
      - name: Post comment
        uses: py-cov-action/python-coverage-comment-action@v3
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}

Here is a full error with trackback

Error: Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com/py-cov-action/python-coverage-comment-action#basic-usage
Otherwise please look for open issues or open one in https://github.com/py-cov-action/python-coverage-comment-action/
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line 17, in run
    return subprocess.run(
  File "/usr/local/lib/python3.10/subprocess.py", line 526, 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 "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 39, in main
    exit_code = action(
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/main.py", line 75, in action
    coverage = coverage_module.get_coverage_info(merge=config.MERGE_COVERAGE_FILES)
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/coverage.py", line 75, in get_coverage_info
    json_coverage = subprocess.run("coverage", "json", "-o", "-")
  File "/usr/local/lib/python3.10/site-packages/coverage_comment/subprocess.py", line [25](https://github.com/org/repo/actions/runs/4864464278/jobs/8673513037#step:7:26), in run
    raise SubProcessError("\n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError: No data to report.

And bit of my test and coverage step what according to logs doing the job well.
Source code is located in /src and tests are located at /src/tests
Coverage config file

#/src/.coveragerc with content
[run]
relative_files = True

More step output

  
cd src; pipenv run coverage run -m pytest -v tests/
============================= test session starts ==============================
platform linux -- Python 3.9.16, pytest-7.3.1, pluggy-1.0.0 -- /home/runner/.local/share/virtualenvs/repo-name

============================= 28 passed in 26.59s ==============================
cd src; pipenv run coverage report -m

--------------------------------------------------------------------------
TOTAL                                          [75](https://github.com/repo-name/actions/runs/4864464278/jobs/8673513037#step:6:76)6     29    96%
total 112
drwxr-xr-x 4 runner docker  4096 May  2 18:21 .
drwxr-xr-x 8 runner docker  4096 May  2 18:20 ..
-rw-r--r-- 1 runner docker 53248 May  2 18:21 .coverage
-rw-r--r-- 1 runner docker    27 May  2 18:20 .coveragerc
drwxr-xr-x 3 runner docker  4096 May  2 18:21 .pytest_cache
-rw-r--r-- 1 runner docker     0 May  2 18:20 __init__.py

Sorry but I had to cut off filenames and repo name due to being private repo, but as pytest run with no problem, and I see .coverage file is created, I struggle to understand why subprocess try to generate report one more time and its failing, any ideas?

Will appreciate any hints ;)

Docker tag `latest` contains v2, not v3, breaking action.yml

It seems to me that after merging perhaps #36, the latest label in the Docker image contains v2 code, and not v3:

$ docker pull ewjoachim/python:latest
...
Digest: sha256:0b726959b7be0b79442334faa40797dc18535036cfd3d8dcf016475ea2256443
Status: Downloaded newer image for ewjoachim/python-coverage-comment-action:latest

$ docker run --rm -ti --entrypoint /bin/bash ewjoachim/python-coverage-comment-action:latest
root@8336838d94ee:/workdir# grep wiki /usr/local/lib/python3.10/site-packages/coverage_comment/main.py 
    wiki,
    previous_coverage_data_file = wiki.get_file_contents(
    log.info("Saving Badge into the repo wiki")
    wiki.upload_file(
    url = wiki.get_wiki_file_url(

This wouldn't matter much, except action.yml specifies :latest, not :v3:

https://github.com/ewjoachim/python-coverage-comment-action/blob/9a514f2ceccf48e6be062bf4f637a98b515a6f6a/action.yml#L67-L70

Many thanks for your work, it's a great action!

Use decimals/fractions everywhere

Floating-point types make knowing whether the coverage increased, decreased or stayed the same quite complicated (mainly: when it stays the same, floating point errors can make us think it changed).

There's a bit of work in #33 but I guess we'd gain from using consistently fractions or decimals everywhere applicable.

Switch to new note syntax

Syntax for admonitions, including Note has changed: https://github.com/orgs/community/discussions/16925#discussioncomment-6506860

A new syntax, [!NOTE], has been added, which will gradually replace the old one. However, the old syntax will continue to work for some time.

We're using the old syntax here:

Let's replace it.

(This may be made redundant by #211 but I'm just opening the issue to make sur we don't forget it if need be)

Action can't find source code to report

I'm facing an error, followed the instruction, error says its permission but it doesn't matter the permission I set.
Here's the debug logs minus folder paths("redacted" is my main package), after this it jjust repeats the last few lines for every file in the project
https://pastebin.com/rcv95F7b

##.coveragerc
[run]

branch = True
dynamic_context = test_function
source = redacted
relative_files = True

[report]
precision = 2
sort = Miss
show_missing = True
ignore_errors = True

[html]
show_contexts = True

the generation works locally

Multi-module monorepo support?

Soo, I spent quite some time trying to make the action work with our private monorepo setup and looks like I failed :-(

The problem is that when in monorepo, you most probably are running the pytest/coverage inside some sub-module. And thus even with relative files, the paths are relative to that submodule.

So, when being merged, you kinda lost the "submodule" info and now when running the action in the repo root, it rightfully complains about a missing .py file. The file is present, but just inside some of the sub-modules.

If there are any ideas/examples of monorepo setups, I'd be glad to see any suggestions.

Also, while the whole sub-module thing (at least in our case) has a root-level Poetry project, when running the same coverage combine or coverage json locally under a particular poetry shell, it works fine! I believe the reason for that is cause all the sub-modules are listed in the root project as dependencies and poetry resolves these quite well.

Version 3 tag does not point to the correct location

I noticed discrepancies with the version tag and the branch v3. I assume you where working in the branch v3 to prep for that version, but the tag v3.0.0 points to this Dockerfile @v3.0.0. that has a link to the image @v1, which was not the intent I assume?

What happens now if a user uses this action is confusing:
uses: py-cov-action/python-coverage-comment-action@v3 the branch will be checked out, and Docker image :v3 will be used.
uses: py-cov-action/[email protected] the tag will be checked out, and Docker image :v1 will be used.

I'd recommend cleaning up the branches after merging them to main, and correct the v3 tag to point to the right commit. It's best to keep things straightforward and use tags everywhere, and not branches.

Run the end to end tests in the CI

They're likely not runable through GitHub Actions because of restrictions, but we may have to have them run in CircleCI or some other provider.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.