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

Base coverage collection skipped with base coverage file provided #242

Closed
Raigen opened this issue Mar 4, 2022 · 8 comments
Closed

Base coverage collection skipped with base coverage file provided #242

Raigen opened this issue Mar 4, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@Raigen
Copy link
Contributor

Raigen commented Mar 4, 2022

Describe a bug

The base coverage collection is still beeing skipped although a base coverage file is provided by the configuration. That means no coverage diff is reported on the PR comment.
My Bugfix from #239 was supposed to fix this issue but it does not seem to work.
I would look into it myself, but I do not have the time right now. If this is not picked up until next week I will come back to it myself.

Expected behavior

Base coverage is collected from the provided coverage file and coverage diff percentage is shown in the PR comment.
Also the branch should remain unchanged. We know it was working before when branches where switched, but that should be unnecessary and can cause other errors (see #236)

Details

Action version: 2.0.4
OS, where your action is running (windows, linux): linux

action.yml file
name: Test, build & Docker push
on: pull_request

concurrency:
  group: ${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        # We need full history for commitlint.
        with:
          fetch-depth: 0

      - name: Get coverage cache
        uses: actions/cache@v2
        with:
          key: base-coverage-${{ github.ref }}
          restore-keys: base-coverage-${{ github.base_ref }}
          path: ./coverage/base-report.json
      - name: Setup node
        uses: actions/setup-node@v2
        with:
          node-version: '16.14.0'
          cache: 'yarn'
      - name: Install project dependencies
        run: yarn --frozen-lockfile

      - name: Run linting
        if: ${{ false }}
        run: yarn lint
      - name: Run tests
        run: yarn test --runInBand --coverage --coverageThreshold '{}' --testLocationInResults --json --outputFile=./coverage/report.json

      # make sure the file exists
      - run: cat ./coverage/base-report.json
      - uses: artiomtr/jest-coverage-report-action@v2.0.4
        # It will annotate failing tests as well, so we can run it always.
        if: always()
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          package-manager: yarn
          coverage-file: ./coverage/report.json
          base-coverage-file: ./coverage/base-report.json
          annotations: all
          skip-step: all
Screenshots

image
image

Additional context

Log output
Run artiomtr/jest-coverage-report-action@v2.0.4
  with:
    github-token: ***
    package-manager: yarn
    coverage-file: ./coverage/report.json
    base-coverage-file: ./coverage/base-report.json
    annotations: all
    skip-step: all
    test-script: npx jest
    icons: emoji
Run $GITHUB_ACTION_PATH/run.sh
  $GITHUB_ACTION_PATH/run.sh
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    INPUT_GITHUB-TOKEN: ***
    INPUT_TEST-SCRIPT: npx jest
    INPUT_THRESHOLD: 
    INPUT_WORKING-DIRECTORY: 
    INPUT_ICONS: emoji
    INPUT_ANNOTATIONS: all
    INPUT_PACKAGE-MANAGER: yarn
    INPUT_SKIP-STEP: all
    INPUT_CUSTOM-TITLE: 
    INPUT_COVERAGE-FILE: ./coverage/report.json
    INPUT_BASE-COVERAGE-FILE: ./coverage/base-report.json
Running using node v16.14.0
Begin initialization stage...
Initialization stage ended
Begin stages.parsethreshold...
[...] (unrelated esbuild warning about jest.config.ts)
stages.parseThreshold ended
Begin head coverage collection...
Begin installing dependencies...
Installing dependencies skipped
Installing dependencies ended
Begin running tests...
Running tests skipped
Running tests ended
Begin collecting coverage...
Loading code coverage from file: coverage/report.json
Collecting coverage ended
Begin parsing coverage...
Parsing coverage ended
Head coverage collection ended
Begin switching to base branch...
Switching to base branch skipped
Switching to base branch ended
Begin base coverage collection...
Base coverage collection skipped
Base coverage collection ended
Begin switching back to original branch...
Switching back to original branch skipped
Switching back to original branch ended
Begin stages.checkthreshold...
stages.checkThreshold ended
Begin generating report...
Generating report ended
Begin report publish...
Report publish ended
Begin failed tests' annotations publication...
Failed tests' annotations publication skipped
Failed tests' annotations publication ended
Begin coverage annotations publication...
Coverage annotations publication ended
@Raigen Raigen added the bug Something isn't working label Mar 4, 2022
@raspo
Copy link
Contributor

raspo commented Mar 4, 2022

I am also having issues with the latest v2.0.4 and I have a similar setup where I run jest and collect coverage in separate steps and then use ArtiomTr/jest-coverage-report-action for the annotations.

     - name: Jest coverage report
        uses: ArtiomTr/jest-coverage-report-action@v2.0.4
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          coverage-file: ./temp-coverage-results/current/jest.results.json
          base-coverage-file: ./temp-coverage-results/target/jest.results.json
          threshold: 80
          skip-step: all
          annotations: failed-tests

With v2.0.4 it keeps failing with TypeError: Cannot convert undefined or null to object and I am not sure how to debug it.

CleanShot 2022-03-04 at 13 46 25


Out of curiosity I tried to use ArtiomTr/jest-coverage-report-action@Debug-action instead (mentioned in another conversation) and with that particular version it works perfectly every time: branch in not switching, reports are being collected, annotation with coverage diffs is generated, etc..

I did some research but wasn't able to figure out where the Debug-action version comes from... is it based on an older version?! @ArtiomTr

@ArtiomTr
Copy link
Owner

ArtiomTr commented Mar 5, 2022

@raspo,

The Debug-action is not a version, it is a branch. I created it from the main branch, so it should be the same as v2.0.4 version, with few console.log's added.

Looks like error occur on this line

const total = Object.values(map).reduce(

The variable map is null or undefined. I don't know what could cause that issue, but it is definitely is not related to this one. I will create a separate issue for this.

@Raigen
Copy link
Contributor Author

Raigen commented Mar 7, 2022

@ArtiomTr I tried the Debug-action branch and this bug is somehow fixed in there. No branch switches happening (so not an old version) and base coverage is loaded from the file.
I can reproduce it, v2.0.4 is skipping the base file, Debug-action is loading the base file.
I compared both branches and could only find console.log. Could the dist package be build differently?

@ArtiomTr
Copy link
Owner

ArtiomTr commented Mar 7, 2022

@Raigen, I've added some tweaks & rebuilt the package - could you try it now?

@Raigen
Copy link
Contributor Author

Raigen commented Mar 7, 2022

I tried artiomtr/jest-coverage-report-action@v2.0.5 and it works as expected. Thanks!

@ArtiomTr ArtiomTr closed this as completed Mar 7, 2022
@venux92
Copy link

venux92 commented Aug 24, 2022

@Raigen I was looking at your yml file and I was trying to understand something.
Did you commit base-report.json to your base branch first? as I can see you only output --outputFile=./coverage/report.json

I don't understand how this file is created especially because you do check if the file exists.
run: cat ./coverage/base-report.json

Thank you in advance.

@Raigen
Copy link
Contributor Author

Raigen commented Aug 25, 2022

@venux92 In my base branch I save the report with the cache action and load it in a PR with this:

      - name: Get coverage cache
        uses: actions/cache@v2
        with:
          key: base-coverage-${{ github.ref }}
          restore-keys: base-coverage-${{ github.base_ref }}
          path: ./coverage/base-report.json

By now we switched it over to an artifact, but the general idea is the same.

@venux92
Copy link

venux92 commented Aug 26, 2022

@Raigen Thanks for the clarification, make sense now, thank you =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants