Unrelated files may appear in comment
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.
Oh, you're probably right, it's a bug! Do you want to make a PR ?
Sure, I can get to it today.
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: 1000in theactions/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.
Repoen because of revert https://github.com/py-cov-action/python-coverage-comment-action/issues/554
Finally (hopefully) fixed in #573: I'm not using git anymore for the diff, but the github API. And using 3 dots :)
And, released in https://github.com/py-cov-action/python-coverage-comment-action/releases/tag/v3.35
Thanks again @stickperson