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

Crashes when run as a GitHub Action #104

Open
neilco opened this issue Oct 27, 2021 · 3 comments
Open

Crashes when run as a GitHub Action #104

neilco opened this issue Oct 27, 2021 · 3 comments

Comments

@neilco
Copy link

neilco commented Oct 27, 2021

Version(if relevant):

type-coverage 2.18.0
typescript 4.3.5

Environment(if relevant):

  • GitHub Action running ubuntu-latest

Code(if relevant):

Type Coverage config in package.json

  "typeCoverage": {
    "atLeast": 90,
    "cache": true,
    "debug": false,
    "detail": false,
    "ignoreCatch": true,
    "ignoreFiles": [
        [REDACTED]
    ],
    "project": "tsconfig.json",
    "strict": true,
    "ignoreUnread": true,
    "ignoreNested": true,
    "ignoreAsAssertion": true,
    "ignoreTypeAssertion": true,
    "ignoreNonNullAssertion": true,
    "showRelativePath": true
  }

Expected:

Running type-coverage will only output the ratio used to calculate the coverage percentage and the result of the "at least" condition. If the condition is not met, exit with exit code 1. For example:

101706 / 119972 84.77%
The type coverage rate(84.77%) is lower than the target(90%).
error Command failed with exit code 1.

Actual:

Running type-coverage dumps thousands of log lines and exits abruptly. For example:

Screenshot 2021-10-27 at 16 31 45

@plantain-00 plantain-00 added the help wanted Extra attention is needed label Oct 27, 2021
@neilco
Copy link
Author

neilco commented Oct 28, 2021

I've tried switching the runner to the macos-11 (same OS as I'm running locally) and the same behaviour persists when run as a GitHub Action.

Screenshot 2021-10-28 at 09 38 46

@neilco
Copy link
Author

neilco commented Oct 28, 2021

I've been digging into this a little more and found it's related to the --at-least flag and the sheer size of the project. The project in question has on the order of 120,000 identifiers but only about 85% of those are not any. This means this enumeration produces on the order of 20,000 console.log messages. The GitHub Action runner does not like this and bails before completing the enumeration.

For a CI/CD perspective, we're not interested in the detail in the 20K log lines. We're only interested in whether the type coverage meets our threshold. So we can use a shell pipeline to limit the output to just the last two lines:

type-coverage | tail -n 2

The problem with this is: even if type-coverage exits with 1 since atLeastFailed is true, $? will be 0 because that's the exit code for tail -n 2. Thankfully, Bash helpfully maintains an array of exit codes for each segment of a pipeline and we can capture the exit code of type-coverage using ${PIPESTATUS[0]}.

Now my GitHub Action step to run type-coverage looks like this:

- name: Check TypeScript Coverage
  shell: bash
  run: |
    type-coverage | tail -n 2
    exit ${PIPESTATUS[0]}

This correctly fails when --at-least is higher than the actual type coverage, but succeeds when it is lower or equal.

A better solution than this workaround would be to modify this predicate: if (detail || atLeastFailed || isFailed). If it were if (detail && (atLeastFailed || isFailed)), it would only print out the anys if --detail was passed. That's probably how most users would expect this tool to work.

ASIDE: In my original report, I said:

"Running type-coverage will only output the ratio used to calculate the coverage percentage and the result of the 'at least' condition."

Having now looked at the code here, I know this is not correct. It turns out the anys array returned by lint is empty when I run this tool on macOS. That explains why I wasn't seeing the log lines the GitHub Action was producing 🤦🏻‍♂️

@plantain-00
Copy link
Owner

v2.19.0-alpha.0 support --no-detail-when-failed and noDetailWhenFailed, it will not show detail message when the CLI failed, it should fix this issue and not breaking anything.

@plantain-00 plantain-00 added fixed and released and removed help wanted Extra attention is needed labels Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants