Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codecov action not associating upload with branch when commit already exists #1296

Open
jberkenbilt opened this issue Feb 18, 2024 · 1 comment

Comments

@jberkenbilt
Copy link

Tl;Dr: I know guesses are not always helpful, but my guess as to what's happening is that if CI builds on a specific branch using the exact same commit that was previously built in a pull request, the commit doesn't get associated with the branch, perhaps because create-commit has already been run.

Details below.

I am brand new to CodeCov and have started using with qpdf. While I sometimes get pull requests that I merge using the merge button in GitHub, I often "merge" pull requests by doing a direct push of the tip of the pull request branch to main.

As I write this, my most recent build is here: https://app.codecov.io/gh/qpdf/qpdf/commit/689a093e328a5f1ab1ff82a55193c79fb474b4ea/tree

This commit was created when the codecov action was run in a pull request. Then I pushed to main directly, and at this time, https://app.codecov.io/gh/qpdf/qpdf shows now branches. (This may have changed by the time you read this.)

Also, in settings (https://app.codecov.io/gh/qpdf/qpdf/settings), I have "branch context" with only master as the value (my main branch is main) and no choices.

It would be great if, once a previously existing commit is uploaded from a github build of an actual branch (rather than a PR, so ${{ github.event_name == 'push' }}), the data would become associated with that branch automatically. I'd be okay with having to add some extra code to my workflow (e.g., conditionally setting override_branch) if that's a solution.

(15 minutes later)

I think my guess looks like it was correct. After the CodeCov step finished in my build, I had main as a choice in settings, and once I set the branch context to main, the coverage information was visible.

So.....

Is there a way to associate an upload with the main branch when CI runs for main even if the exact same commit was previously created?

Without this, main will get updated only when a commit in main appears for the first time in main, which basically means it will happen only if I push a commit to main that has never been through CI, which means (in practice) that I have to get everything in by merging a pull request or otherwise doing something to cause a new commit hash to appear.

@jberkenbilt jberkenbilt changed the title codecov action not associating upload with branch codecov action not associating upload with branch when commit already exists Feb 18, 2024
@jberkenbilt
Copy link
Author

My workaround:

  CodeCov:
    runs-on: ubuntu-latest
    needs: Prebuild
    steps:
      - uses: actions/checkout@v4
      - name: 'Code Coverage'
        run: build-scripts/test-coverage
      - id: set_branch
        run: |
          if [ "${{ github.event_name }}" = "push" ]; then
            echo "override_branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
          else
            echo "override_branch=" >> $GITHUB_OUTPUT
          fi
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          override_branch: ${{ steps.set_branch.outputs.override_branch }}

This seems to have worked. If this looks okay, maybe it could be added to the documentation. If this looks like good default behavior, perhaps the -B flag could default from GITHUB_REF on a push action if override_branch is not given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant