codacy / codacy-coverage-reporter-action

GitHub Action for the codacy-coverage-reporter
Other
58 stars 15 forks source link

[TS-711] Wrong commit UUID is discovered #78

Closed milkshakeuk closed 6 months ago

milkshakeuk commented 9 months ago

Hi, your action doesn't allow a mechanism to specify the commit UUID and in my case its auto discovering the wrong commit id:

See my Action Run here: https://github.com/nHapiNET/nHapi/actions/runs/7222494087/job/19679576963

it "should" discover 6371a8bfc534e7b9df7e724ab4e9d42fdf26ae23 (as seen in the checkout step) but is discovering 50be0187277c901ced58db7ded7acc098f6420d3 and therefor associating the coverage reports with the wrong commit, I know the Codacy Coverage Reporter script has an option to pass --commit-uuid but you aren't using this?

Am I doing something wrong? or is could there be missing feature in this action?

github-actions[bot] commented 9 months ago

Internal ticket created : TS-711

milkshakeuk commented 9 months ago

I believe this is linked to #67, although I can manually use the Codacy Coverage Reporter Cli to pass in the correct commit id, I would rather use a prebuild action which already supports this.

SchoolGuy commented 8 months ago

So this is also linked to https://github.com/cobbler/cobbler/issues/3379. I had to resort to the workaround that @milkshakeuk linked. I am still baffled how Codecov is able to do this without needing to resort to these workarounds directly from the fork.

The workaround looks something like this:

testing.yml:

name: Testing Cobbler

on:
  push:
    branches: [ main, release* ]
  pull_request:
    branches: [ main, release* ]

jobs:
  run_tests:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v4
      - name: Pull Docker Test Container
        run: docker pull registry.opensuse.org/systemsmanagement/cobbler/github-ci/containers/cobbler-test-github:main
      - name: Run previously built Docker Container
        run: docker run --privileged -t -d -v $PWD:/code --name cobbler registry.opensuse.org/systemsmanagement/cobbler/github-ci/containers/cobbler-test-github:main
      - name: Setup Cobbler in the Container
        shell: 'script -q -e -c "bash {0}"'
        run: |
          docker exec -u 0 -it cobbler bash -c "./docker/develop/scripts/setup-supervisor.sh"
      - name: Run the Tests inside the Docker Container
        shell: 'script -q -e -c "bash {0}"'
        run: |
          docker exec -u 0 -it cobbler bash -c "pytest --cov=./cobbler --benchmark-skip && git config --global --add safe.directory /code && coverage xml && codecov --token=1064928c-6477-41be-9ac2-7ce5e6d1fd8b --commit=${GITHUB_SHA}"
      - name: Stop and remove the container
        run: docker stop cobbler && docker rm cobbler
      # https://github.com/actions/upload-artifact
      - name: Upload coverage report to GH artifacts
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: coverage.xml
          if-no-files-found: error

coverage-upload.yml:

name: Coverage Upload

on:
  workflow_run:
    workflows: [Testing Cobbler]
    types:
      - completed

jobs:
  run_tests:
    runs-on: ubuntu-latest
    steps:
      # https://github.com/dawidd6/action-download-artifact
      - name: Download artifact
        id: download-artifact
        uses: dawidd6/action-download-artifact@v3
        with:
          name: coverage-report
          workflow: testing.yml
          allow_forks: true
          workflow_conclusion: success
      # https://github.com/codacy/codacy-coverage-reporter-action
      # - name: Run codacy-coverage-reporter
      #   uses: codacy/codacy-coverage-reporter-action@v1
      #   with:
      #     project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
      #     coverage-reports: coverage.xml
      - name: Publish Code Coverage Results
        run: |
          auth="--project-token ${{ secrets.CODACY_PROJECT_TOKEN }}"
          commit_uuid="--commit-uuid ${{ github.event.workflow_run.head_sha }}"

          bash <(curl -Ls https://coverage.codacy.com/get.sh) report $auth $commit_uuid -r coverage.xml --partial &&\
          bash <(curl -Ls https://coverage.codacy.com/get.sh) final $auth $commit_uuid
yoanm commented 6 months ago

Workaround proposal => #83

lolgab commented 6 months ago

Hi @yoanm, Thank you for opening the issue and for the workaround proposed. We were already having special code to handle the pull_request workflows in GitHub Actions, which also have different commit SHA. I did a similar thing for workflow_run workflows in https://github.com/codacy/codacy-coverage-reporter/pull/492 and now both the CLI reporter and the GitHub Action should get the right commit SHA by default. I'm closing this issue. Feel free to reopen if this is not working as expected.