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

How to handle base-file #29

Closed
Floppy012 opened this issue Mar 21, 2023 · 6 comments · Fixed by #30
Closed

How to handle base-file #29

Floppy012 opened this issue Mar 21, 2023 · 6 comments · Fixed by #30
Labels
bug Something isn't working question Further information is requested

Comments

@Floppy012
Copy link

I just started using GitHub Actions and so far I love it. And I would like to use this action. But it's not really clear to me how to handle the base-file.

In my case the base-file should be the coverage report from the main branch. But how do I access that from an action running in a PR?

  • Committing the base coverage report and automating that seems a little strange
  • I cannot access artifacts that weren't created in the same workflow

The only option I see would be to use a cache for that. With the only downside being that the cache will be deleted when it's not being accessed for 7 days in a row.

Or is there a better way to handle this?

@jacekk
Copy link
Contributor

jacekk commented Mar 21, 2023

@Floppy012 I have two actions:

// .github/workflows/coverage-store.yml
name: Coverage Store

on:
    push:
        branches:
            - develop

permissions:
    actions: write
    contents: read
    packages: read

jobs:
    coverage_store:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v3
            - run: yarn install
            - run: yarn test-ci --coverage

            - name: Upload coverage for current branch
              uses: actions/upload-artifact@v3
              with:
                  name: coverage-reports-artifact
                  path: ./coverage/clover.xml

and

// .github/workflows/coverage-report.yml
name: Coverage Report

on:
    pull_request:
        branches-ignore:
            - 'dependabot/npm_and_yarn/**'

permissions:
    actions: read
    contents: read
    packages: read
    pull-requests: write

jobs:
    coverage_report:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v3
            - run: yarn install
            - run: yarn test-ci --coverage

            - name: Download coverage for DEVELOP branch
              uses: dawidd6/action-download-artifact@v2
              continue-on-error: true
              with:
                  branch: develop
                  name: coverage-reports-artifact
                  path: ./coverage/base/
                  search_artifacts: true
                  workflow: .github/workflows/coverage-store.yml
            - name: Coverage Report as Comment (Clover)
              uses: lucassabreu/comment-coverage-clover@v0.9.1
              with:
                  base-file: ./coverage/base/clover.xml
                  chart-size: 90
                  dir-prefix: ${{ github.workspace }}
                  file: ./coverage/clover.xml
                  show-percentage-change-on-table: true
                  table-coverage-change: 0.1

I hope this is helpful, as I've also had to figure this thing out 😄

@lucassabreu

This comment was marked as outdated.

@lucassabreu
Copy link
Owner

yours is better... less ifs makes it more clear

@lucassabreu lucassabreu added the question Further information is requested label Mar 21, 2023
@Floppy012
Copy link
Author

Wow! Thanks for the quick replies.

I managed to combine both examples into a solution that works for me. However I seem to have ran into a bug. My clover file only contains a single package node. And I get a type error when running the action:

TypeError: (packages || []).reduce is not a function Stack: TypeError: (packages || []).reduce is not a function
    at fromString (/home/runner/work/_actions/lucassabreu/comment-coverage-clover/v0.9.1/bin/index.js:89431:37)
    at /home/runner/work/_actions/lucassabreu/comment-coverage-clover/v0.9.1/bin/index.js:89744:29
    at step (/home/runner/work/_actions/lucassabreu/comment-coverage-clover/v0.9.1/bin/index.js:93:23)
    at Object.next (/home/runner/work/_actions/lucassabreu/comment-coverage-clover/v0.9.1/bin/index.js:74:53)
    at fulfilled (/home/runner/work/_actions/lucassabreu/comment-coverage-clover/v0.9.1/bin/index.js:64:58)

Probably caused by this line:

const allFiles = (packages || []).reduce(

My clover file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<coverage generated="1679408725" clover="4.3.1">
  <project timestamp="1679408725">
    <metrics complexity="0" elements="637" coveredelements="495" conditionals="0" coveredconditionals="0" statements="637" coveredstatements="495" coveredmethods="0" methods="0" classes="117" loc="4706" ncloc="637" files="117" packages="1" />
    <package name="Default">
      <metrics complexity="0" elements="637" coveredelements="495" conditionals="0" coveredconditionals="0" statements="637" coveredstatements="495" coveredmethods="0" methods="0" classes="117" loc="4706" ncloc="637" files="117" />
      <!-- files redacted  -->
    </package>
  </project>
  <testproject timestamp="1679408725">
    <metrics complexity="0" elements="0" coveredelements="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" coveredmethods="0" methods="0" classes="0" loc="0" ncloc="0" files="0" packages="0" />
  </testproject>
</coverage>

(I removed the files cause I'm not allowed to share that information)

@lucassabreu lucassabreu added the bug Something isn't working label Mar 21, 2023
@lucassabreu
Copy link
Owner

@Floppy012 can you update and retry to see if the problem is fixed?

@lucassabreu lucassabreu reopened this Mar 21, 2023
@lucassabreu lucassabreu pinned this issue Mar 21, 2023
@Floppy012
Copy link
Author

@Floppy012 can you update and retry to see if the problem is fixed?

@lucassabreu Works perfectly now. Thanks for your fast work 😄

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants