python-coverage-comment-action icon indicating copy to clipboard operation
python-coverage-comment-action copied to clipboard

Unrelated files may appear in comment

Open stickperson opened this issue 9 months ago • 3 comments

The diff calculation is similar to the two dot diff comparison and can result in files unrelated to a PR appearing in the coverage comment. This can happen if there is a merge to the base ref or default branch between the time the GHA was kicked off and this action is run.

I think this is a bug and not the desired result.

stickperson avatar Apr 15 '25 23:04 stickperson

Oh, you're probably right, it's a bug! Do you want to make a PR ?

ewjoachim avatar Apr 17 '25 08:04 ewjoachim

Sure, I can get to it today.

stickperson avatar Apr 17 '25 15:04 stickperson

This actually may be more complicated than originally planned. I actually think git fetch origin main --depth=1000 is not doing anything unless actions/checkout@v4 is using fetch-depth: 1000 (or 0). This GHA illustrates the point:

name: CI

on:
  pull_request:
concurrency:
  group: ${{ github.event_name }}-${{ github.ref }}

jobs:
  fetch_depth:
    name: Fetch all history
    runs-on: ubuntu-latest
    permissions:
      pull-requests: read
      contents: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Fetch base branch
        run: git fetch origin main --depth=1000
      - name: diff
        run: git diff -U0 FETCH_HEAD...
  no_fetch_depth:
    name: Fetch single commit
    runs-on: ubuntu-latest
    permissions:
      pull-requests: read
      contents: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Fetch base branch
        run: git fetch origin main --depth=1000
      - name: diff
        run: git diff -U0 FETCH_HEAD...

In no_fetch_depth, git diff -U0 FETCH_HEAD... fails with fatal: FETCH_HEAD...HEAD: no merge base. So I believe the actual fix is:

  • remove the git.fetch call since it will not do anything
  • update the diff command
  • instruct users to set fetch-depth: 1000 in the actions/checkout

Just double checking that sounds right before I go ahead and put up a fix.

edit: It actually might make sense to keep in the git.fetch call as that would update FETCH_HEAD to the base ref.

stickperson avatar Apr 18 '25 02:04 stickperson

Repoen because of revert https://github.com/py-cov-action/python-coverage-comment-action/issues/554

ewjoachim avatar Jul 13 '25 08:07 ewjoachim

Finally (hopefully) fixed in #573: I'm not using git anymore for the diff, but the github API. And using 3 dots :)

ewjoachim avatar Jul 13 '25 11:07 ewjoachim

And, released in https://github.com/py-cov-action/python-coverage-comment-action/releases/tag/v3.35

Thanks again @stickperson

ewjoachim avatar Jul 13 '25 11:07 ewjoachim