有没有办法在 ci-cd in github 中显示代码覆盖率结果矩阵?

Is there a way to display code coverage results metrix in ci-cd in github?

我在 visual studio 2019 企业中使用代码覆盖工具。

我得到一个 .coverage 文件,但我想在 CI 中显示矩阵结果。

你知道怎么做吗?

谢谢。

P.S

有一个GitHub动作danielpalme/ReportGenerator 但它将结果显示到文件中。我需要相同的但在 CI-CD 运行 本身中显示结果。

您需要使用能够分析由 dotnet testng test 或类似工具生成的代码覆盖率报告的代码分析服务。例如codecov.io

  • 转到codecov.io

    • 使用托管 git 存储库的帐户登录 (Github)
    • 点击右上角头像→设置→访问
    • 生成代币 → name = GithubCI
    • 将您的令牌复制到临时记事本
  • 转到托管在托管服务 (github.com)

    上的 git 存储库
    • 设置选项卡 → 机密
    • 在此处添加您的 codecov.io 令牌,或者在存储库 secrets/organization secrets
  • 然后我有以下 github 工作流(对于 angular)到 运行 单元测试,生成代码覆盖率报告。然后工作流将覆盖率报告发布到 codecov.io

name: npm-publish

on:
  push:
    branches: [ master ]

jobs:
  build:
  
    name: npm-publish
    runs-on: ubuntu-latest
    
    permissions: 
      contents: read
      packages: write 
    
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    
    - name: Setup node
      uses: actions/setup-node@v2
      with:
        node-version: 14

    - name: Install dependencies
      run: npm install
    
    - name: Build
      run: npm run nx run-many -- --target=build --projects=ng-youtube-player-demo --configuration production --with-deps

    - name: Test
      run: npm run nx run-many -- --target=test --projects=ng-youtube-player-demo --with-deps  --watch=false --browsers=ChromeHeadless --coverage --coverageReporters=lcovonly

    - name: Upload code coverage report
      uses: codecov/codecov-action@v1
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        directory: ./coverage/libs/mintplayer-ng-youtube-api
      
    - name: Upload code coverage report
      uses: codecov/codecov-action@v1
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        directory: ./coverage/libs/mintplayer-ng-youtube-player
      
    - name: Push to NPM
      uses: JS-DevTools/npm-publish@v1
      with:
        package: 'dist/libs/mintplayer-ng-youtube-api/package.json'
        registry: 'https://registry.npmjs.org'
        token: ${{ secrets.PUBLISH_NODE_TO_NPMJS_COM }}
        access: 'public'

    - name: Push to NPM
      uses: JS-DevTools/npm-publish@v1
      with:
        package: 'dist/libs/mintplayer-ng-youtube-player/package.json'
        registry: 'https://registry.npmjs.org'
        token: ${{ secrets.PUBLISH_NODE_TO_NPMJS_COM }}
        access: 'public'

    - name: Push to Github
      uses: JS-DevTools/npm-publish@v1
      with:
        package: 'dist/libs/mintplayer-ng-youtube-api/package.json'
        registry: 'https://npm.pkg.github.com'
        token: ${{ github.token }}
        access: 'public'

    - name: Push to Github
      uses: JS-DevTools/npm-publish@v1
      with:
        package: 'dist/libs/mintplayer-ng-youtube-player/package.json'
        registry: 'https://npm.pkg.github.com'
        token: ${{ github.token }}
        access: 'public'

npm test 生成我的代码覆盖率报告。接下来的步骤:

- name: Upload code coverage report
  uses: codecov/codecov-action@v1
  with:
    token: ${{ secrets.CODECOV_TOKEN }}
    directory: ./coverage/libs/mycompany-ng-youtube-player

将覆盖率报告上传到 codecov.io。然后他们会分析您的报告,完成后,您可以在 readme.md

上贴上徽章
[![codecov](https://codecov.io/gh/MyCompany/mycompany-ng-youtube-player/branch/master/graph/badge.svg?token=K0B355423X3)](https://codecov.io/gh/MyCompany/mycompany-ng-youtube-player)

codecov.io 上找到此徽章降价 → 您的存储库 → 设置 → 徽章 → 复制降价

这对我有用:

 1. Using danielpalme/ReportGenerator action for generating csv file 
 2. Read the csv file to the ci-cd



  - name: Read Code Coverage
    id: covergae
    uses: juliangruber/read-file-action@v1
    with:
       path: Summary.csv
    
  - name: Echo Code Coverage
    run: echo "${{ steps.covergae.outputs.content }}"