我想把json-coverage jest的结果漂亮地打印到github actions中。我有一个ci.yml文件,包含以下内容:
- name: Run Unit Tests
run: |
yarn test:next:unit --runInBand --coverage --coverageReporters="text-summary"
- name: Echo Coverage
run: |
cat coverage/coverage-summary.json | head -1 > coverage-testing/coverage.json
这将在作业终端中打印jest的coverage-summary的第一行,如下所示:
{"total": {"lines":{"total":18326,"covered":11,"skipped":0,"pct":0.06},"statements":{"total":62625,"covered":11,"skipped":0,"pct":0.01},"functions":{"total":19047,"covered":4,"skipped":0,"pct":0.02},"branches":{"total":60202,"covered":11,"skipped":0,"pct":0.01},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
}
我可以通过将其添加到ci.yml中,将其直接打印到UI中运行的github操作中:
- name: Print to github
run: cat coverage-testing/coverage.json >> $GITHUB_STEP_SUMMARY
它显示在github操作运行的注解下
jest-next summary
{"total": {"lines":{"total":52,"covered":11,"skipped":0,"pct":21.15},"statements":{"total":54,"covered":11,"skipped":0,"pct":20.37},"functions":{"total":16,"covered":4,"skipped":0,"pct":25},"branches":{"total":18,"covered":11,"skipped":0,"pct":61.11},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
Job summary generated at run-time
现在来看看漂亮的打印。我已经尝试了一些jq命令,包括迭代to_entries,使github操作作业摘要看起来更像是markdown。我得到了错误,因为数组是嵌套的,我通过将-r改为-R并添加try来消除这些错误,但没有任何东西打印到github。由于这些尝试都是在CI中进行的,而且jest测试很不可靠,修改一个东西然后等待是很麻烦的。有人碰巧已经有这样的脚本了吗?我不挑剔它的格式,我只是希望它看起来不像json而更像markdown。
1条答案
按热度按时间4ioopgfo1#
通过输入流,可以很快地将其表示为路径/值对的列表,然后可以将路径连接成更可读的形式并转储它。
如果你想保留一些结构,你需要首先决定...