Git Product home page Git Product logo

report-nyc-coverage-github-action's Introduction

GitHub Action: Report NYC coverage

GitHub Action that posts the report in a comment on a GitHub Pull Request from coverage data generated by nyc (istanbul).

See sample comment Sample comment image

Setup

Please refer to the folder .github/workflows to see how this action is used in this repo itself. Use it as a reference for setting it up for your repo.

Typical Usage

on: [pull_request]

jobs:
  my_app_job:
    runs-on: ubuntu-latest
    name: My App
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          fetch-depth: 1000 # Set this according to the size of your git history

      - name: Fetch base
        run: git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1000

      - name: Run tests
        run: npm run test

      - name: Generate NYC report
        run: |
          npx nyc report \
            --reporter json-summary \
            --report-dir nyc-coverage-report \
            --exclude-after-remap false

      - name: Report NYC coverage
        uses: sidx1024/[email protected]
        with:
          # Path to coverage file generated by "nyc report".
          coverage_file: "nyc-coverage-report/coverage-summary.json"

Usage

- uses: sidx1024/[email protected]
  with:
    # Path to coverage file generated by "nyc report".
    # Default: coverage-summary.json
    coverage_file: ""

    # Path to coverage file generated by "nyc report" for the base branch (for
    # comparison)
    # Default: .base_nyc_output/coverage-summary.json
    base_coverage_file: ""

    # Template file to be used for GitHub PR comment. Markdown and Svelte are
    # supported.
    # Default: comment-template.md
    comment_template_file: ""

    # "replace" or "new"
    # Default: replace
    comment_mode: ""

    # An alternative GitHub token, other than the default provided by GitHub Actions
    # runner. Optional.
    # Default: ${{ github.token }}
    github_token: ""

    # Absolute path to the source files. The path will be trimmed from the coverage
    # data. Optional. Default is the github workspace directory with a trailing slash.
    # Default: ${{ format('{0}/', github.workspace) }}
    sources_base_path: ""

    # Specify the order for coverage types to be included in the output table. (S:
    # statements, B: branches, F: functions, L: lines). Missing types will be
    # excluded.
    # Default: SBFL
    files_coverage_table_output_type_order: ""
Input Description Default Required
coverage_file Path to coverage file generated by "nyc report". coverage-summary.json true
base_coverage_file Path to coverage file generated by "nyc report" for the base branch (for comparison) .base_nyc_output/coverage-summary.json true
comment_template_file Template file to be used for GitHub PR comment. Markdown and Svelte are supported. comment-template.md false
comment_mode "replace" or "new" replace false
github_token An alternative GitHub token, other than the default provided by GitHub Actions runner. Optional. ${{ github.token }} false
sources_base_path Absolute path to the source files. The path will be trimmed from the coverage data. Optional. Default is the github workspace directory with a trailing slash. ${{ format('{0}/', github.workspace) }} false
files_coverage_table_output_type_order Specify the order for coverage types to be included in the output table. (S: statements, B: branches, F: functions, L: lines). Missing types will be excluded. SBFL false
**Output** **Description** **Default** **Required**
total_lines_coverage_percent Total lines coverage percent (XX.XX%) with level indicator undefined undefined
total_branches_coverage_percent Total branches coverage percent (XX.XX%) with level indicator undefined undefined
total_statements_coverage_percent Total statements coverage percent (XX.XX%) with level indicator undefined undefined
total_functions_coverage_percent Total functions coverage percent (XX.XX%) with level indicator undefined undefined
total_lines_coverage_percent_raw Total lines coverage percent (XX.XX) without percent and level indicator undefined undefined
total_branches_coverage_percent_raw Total branches coverage percent (XX.XX) without percent and level indicator undefined undefined
total_statements_coverage_percent_raw Total statements coverage percent (XX.XX) without percent and level indicator undefined undefined
total_functions_coverage_percent_raw Total functions coverage percent (XX.XX) without percent and level indicator undefined undefined
base_total_lines_coverage_percent Base total lines coverage percent (XX.XX%) with level indicator undefined undefined
base_total_branches_coverage_percent Base total branches coverage percent (XX.XX%) with level indicator undefined undefined
base_total_statements_coverage_percent Base total statements coverage percent (XX.XX%) with level indicator undefined undefined
base_total_functions_coverage_percent Base total functions coverage percent (XX.XX%) with level indicator undefined undefined
total_lines_coverage_percent_diff Total lines coverage percent diff (+XX.XX%) undefined undefined
total_statements_coverage_percent_diff Total branches coverage percent diff (+XX.XX%) undefined undefined
total_functions_coverage_percent_diff Total statements coverage percent diff (+XX.XX%) undefined undefined
total_branches_coverage_percent_diff Total functions coverage percent diff (+XX.XX%) undefined undefined
total_lines_coverage_percent_diff_raw Total lines coverage percent diff (-XX.XX) without percent sign undefined undefined
total_statements_coverage_percent_diff_raw Total branches coverage percent diff (-XX.XX) without percent sign undefined undefined
total_functions_coverage_percent_diff_raw Total statements coverage percent diff (-XX.XX) without percent sign undefined undefined
total_branches_coverage_percent_diff_raw Total functions coverage percent diff (-XX.XX) without percent sign undefined undefined
files_coverage_table HTML table content containing the file path and corresponding coverage percent for all files undefined undefined
changed_files_coverage_table HTML table content containing the file path and corresponding coverage percent for files changed in the PR undefined undefined
comment_body The comment body in HTML format undefined undefined
commit_sha Last commit SHA (commit due to which this action was executed) undefined undefined
short_commit_sha Last commit SHA in shorter format (6ef01b) undefined undefined
commit_link Relative link for the last commit undefined undefined
base_commit_sha Base commit SHA undefined undefined
base_short_commit_sha Base commit SHA in shorter format (bca317) undefined undefined
base_commit_link Relative link for the base commit undefined undefined
base_ref Base branch name undefined undefined

report-nyc-coverage-github-action's People

Contributors

jfkriz avatar sidx1024 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

report-nyc-coverage-github-action's Issues

Error "unexpected input coverage_file" when using example from README

Tried using in my workflow, starting from the example in the README.

My step looked like this (I tweaked the coverage folder name so that it was the default folder name used by nyc):

- name: Report NYC coverage
  uses: sidx1024/[email protected]
  with:
    coverage_file: "coverage/coverage-summary.json"

I get the following error:

Unexpected input(s) 'coverage_file', valid inputs are ['coverage_output_directory', 'comment_template_file', 'comment_mode', 'github_token', 'sources_base_path', 'files_coverage_table_output_type_order']

documentation utterly incomplete

I appreciate that you built this but it's really no use to anyone if there are no proper examples on how to use it. your own test pull requests don't show the base comparison thing and I'm trying hard to understand the complex workflow structure in your repo.

Can you PLEASE provide a SIMPLIFIED one-file example of a workflow configuration that actually works?

[Feature Request] Custom Coverage Level Icon

Hello, is there any plan to let user specifies their own coverage level icon? Personally, 80% is too low to be considered as high / green. Cheers.

function getCoverageLevelImage(percent) {
// https://github.com/istanbuljs/istanbuljs/blob/c1559005b3bb318da01f505740adb0e782aaf14e/packages/istanbul-lib-report/lib/watermarks.js
if (percent >= 80) {
return COVERAGE_LEVEL_IMAGE.high;
} else if (percent >= 50) {
return COVERAGE_LEVEL_IMAGE.medium;
} else {
return COVERAGE_LEVEL_IMAGE.low;
}
}

Github set-output is deprecated

Per this github blog post from Oct 2022, the set-output command is being deprecated. There are a couple references to set-output in this action - one in a github action file, and one in the index.js in the action itself.

Pull request #37 should resolve this issue. We are currently using it from my fork, and it is working as expected, and we don't receive the warninngs during the action run anymore.

[ Feature Request ] Make the comment_marker customizable

The DEFAULT_COMMENT_MARKER serves as the unique identifier for PR comments, essential for determining which PR comment to update in replace mode. However, this approach becomes problematic when reporting multiple NYC code coverage results. Currently, each subsequent report overwrites the previous one, compelling users to opt for the new mode. This mode, while effective, can lead to an overload of comments in pull requests, a situation particularly cumbersome in monolithic architectures where, for example, ten services might generate ten new comments with each pipeline run. To mitigate this issue, making the comment marker customizable would be beneficial. By allowing each instantiation to define its own marker, we can utilize the replace mode more effectively, eliminating the risk of overwriting incorrect comments.

A mandatory permission is missing from the documentation

With your "Typical Usage" example, I got the following error.

/usr/bin/git diff --name-only --diff-filter=ACMRT origin/rework/syncPattern...32c41d0b5f2a8f8e8a80d95a3153662c383df78d .github/workflows/Test module.yml Error: HttpError: Resource not accessible by integration at /home/runner/work/_actions/sidx1024/report-nyc-coverage-github-action/v1.2.7/dist/index.js:5463:21 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async run (/home/runner/work/_actions/sidx1024/report-nyc-coverage-github-action/v1.2.7/dist/index.js:1[14](https://github.com/MBelangerB/RiotModule/actions/runs/5171112701/jobs/9314450935#step:8:15)07:5)

After some trial and error, I finally realized that the problem was that I didn't have the permissions to write in my PR.

I added this to my workflow.

on: [pull_request]

# To be able to write in the PR, we need write permission. 
permissions:
   pull-requests: write

{...}

jobs:
  build:

I think it would be a good idea to add it to your example.

Node 20?

Just wanted to see if this repo is still being maintained and if it was on the roadmap to update to Node 20 as Node 16 is being deprecated in Github actions. Thanks.

Unable to find default comment_template.md

The comment file isn't being found - this is because the source path for the search defaults to the application directory you're building, not the action runner directory:
Error: Error: ENOENT: no such file or directory, open '/home/runner/work/JsFunctionAppTest/JsFunctionAppTest/comment-template.md'
Providing the full comment template path to the action results in it working:

    - name: Report NYC coverage
      uses: sidx1024/[email protected]
      with:
        coverage_file: "coverage/coverage-summary.json"
        comment_template_file: "/home/runner/work/_actions/sidx1024/report-nyc-coverage-github-action/v1.2.6/comment-template.md"

The rest of the error:

Run sidx10[2](https://github.com/####/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:2)4/[email protected]
  with:
    coverage_file: coverage/coverage-summary.json
    comment_mode: new
    base_coverage_file: .base_nyc_output/coverage-summary.json
    comment_template_file: comment-template.md
    github_token: ***
    sources_base_path: /home/runner/work/JsFunctionAppTest/JsFunctionAppTest/
    files_coverage_table_output_type_order: SBFL
Base coverage json was not readable.
/usr/bin/git diff --name-only --diff-filter=ACMRT origin/master...4758df2bbd[3](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:3)0bc16c5a67a298d6caed260af9725
fatal: ambiguous argument 'origin/master...[4](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:4)7[5](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:5)8df2bbd30bc1[6](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:6)c5a6[7](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:7)a29[8](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:8)d6caed260af[9](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:9)725': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
A non-fatal error occurred while performing git diff:  {
  exitCode: 128,
  stdout: '',
  stderr: "fatal: ambiguous argument 'origin/master...4758df2bbd30bc16c5a67a298d6caed260af9725': unknown revision or path not in the working tree.\n" +
    "Use '--' to separate paths from revisions, like this:\n" +
    "'git <command> [<revision>...] -- [<file>...]'\n"
}
Error: Error: ENOENT: no such file or directory, open '/home/runner/work/JsFunctionAppTest/JsFunctionAppTest/comment-template.md'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at run (/home/runner/work/_actions/sidx[10](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:10)24/report-nyc-coverage-github-action/v1.2.6/dist/index.js:10[23](https://github.com/###/JsFunctionAppTest/runs/6453607763?check_suite_focus=true#step:9:23)1:32)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.