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

Logging comment content

Open rsardckt opened this issue 1 year ago • 3 comments

I'm creating a workflow for a private repository using the Basic usage without external contributors yml as an example. The coverage.json file appears to have been created as expected (I added an extra step after py-cov-action/[email protected] that runs coverage json -o coverage.json and then uploaded it to Github). But the comment continues to be generated with a 100% wrong coverage rate.

Investigating the package code, I was unable to discover the possible error. Is it possible to add logs that print the comment or coverage variables in the process_pr method? This will help me a lot.

Captura de Tela 2024-06-04 às 20 17 40

The totals attribute from the coverage.json is:

"totals": {"covered_lines": 16602, "num_statements": 37301, "percent_covered": 39.773116524612625, "percent_covered_display": "40", "missing_lines": 20699, "excluded_lines": 83, "num_branches": 12328, "num_partial_branches": 867, "covered_branches": 3137, "missing_branches": 9191}
test:
  name: Test Group
  runs-on: ubuntu-22.04
  services:
    redis:
      image: redis:6-alpine
      ports: ["6379:6379"]
    postgres:
      image: postgres:13-alpine
      env:
        POSTGRES_PASSWORD: postgres
      ports: ["5432:5432"]
      options: --tmpfs=/var/lib/postgresql/data
  permissions:
    pull-requests: write
    contents: write
  steps:
    - uses: actions/checkout@v3
      with:
        # full checkout so the code can generate versions from tags
        fetch-depth: 0
    - uses: actions/setup-python@v4
      with:
        python-version: ${{ env.PYTHON_VERSION }}
    - uses: actions/setup-node@v3
      with:
        node-version: '18'
    - uses: actions/cache@v3
      with:
        path: ~/.cache/pip
        key: pip-${{ hashFiles('requirements.txt') }}
        restore-keys: |
          pip-
    - uses: actions/cache@v3
      with:
        path: ~/.npm
        key: node-${{ hashFiles('package-lock.json') }}
        restore-keys: |
          node-
    - name: Install dependencies
      run: |
        make install
        npm ci
        mkdir -p iris/{media,media_test}/reports
        ./.venv/bin/manage.py collectstatic --noinput -v0
    - name: Test and generate coverage report
      run: |
        . .venv/bin/activate
        pytest -n auto -v --disable-pytest-warnings --test-group-count 200 --test-group=1 --test-group-random-seed=836739 --cov=iris --cov-report=xml
      env:
        COVERAGE_FILE: .coverage
    - name: Upload xml to GitHub artifact
      uses: actions/upload-artifact@v4
      with:
        name: coverage
        path: .coverage
coverage:
  name: Post coverage comment
  runs-on: ubuntu-22.04
  needs: 
    - test
  permissions:
    pull-requests: write
    contents: write
    actions: read
  steps:
    - uses: actions/checkout@v4
    - uses: actions/download-artifact@v4
      with:
        pattern: coverage-*
        merge-multiple: true
    - name: Coverage comment
      uses: py-cov-action/[email protected]
      with:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        MERGE_COVERAGE_FILES: true

Captura de Tela 2024-06-04 às 20 19 51

rsardckt avatar Jun 04 '24 23:06 rsardckt

If you want to debug the action in depth, one possible way is to fork it, edit your fork, and point your workflow yo the banch you edited on your fork. This way, you can add plenty of logs.

If there are things that would deserve being printed for debugging, don't hesitate to make a PR adding log.debug() statements. Those statements are visible if you enable debug logging

ewjoachim avatar Jun 05 '24 13:06 ewjoachim

I see you mention the Basic usage without external contributors, but your workflow looks a bit more like the Merging multiple coverage reports one. That's a bit more added complexity, and yet it doesn't seem like you're using a matrix. I'm not sure I understand you make it this way?

ewjoachim avatar Jun 05 '24 13:06 ewjoachim

Thanks, @ewjoachim . I'll fork it and add some logs.

In fact, the test job has other twins (test_1, test_2, test_3, ...). I only inserted one to make it easier to understand.

rsardckt avatar Jun 05 '24 13:06 rsardckt