微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Github Action 中解析 VSTest 输出并用作 YAML 变量

如何解决在 Github Action 中解析 VSTest 输出并用作 YAML 变量

我非常接近这个工作,但我不知道足够的 yaml-foo 来查看解决方案。

很明显,没有办法告诉coverlet (https://github.com/coverlet-coverage/coverlet) 不要在结果路径中使用随机GUID:

image

(来自https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md)。

我正在做一堆代码覆盖率报告,作为其中的一部分,我想使用 https://github.com/simon-k/dotnet-code-coverage-badge 为项目生成一个 GitHub 徽章。

我的构建工作流程:

name: Build Terminal.Gui with .NET Core

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.100

    - name: Install dependencies
      run: dotnet restore

    - name: Build
      run: dotnet build --configuration Release --no-restore

    - name: Test
      run: dotnet test --no-restore --verbosity normal --collect:"XPlat Code Coverage"  --settings UnitTests/coverlet.runsettings

    - name: Create Test Coverage Badge
      uses: simon-k/dotnet-code-coverage-badge@v1.0.0
      id: create_coverage_badge
      with:
        label: Unit Test Coverage
        color: brightgreen
        path: UnitTest/TestResults/<uuid>/coverage.opencover.xml
        gist-filename: code-coverage.json
        # https://gist.github.com/migueldeicaza/90ef67a684cb71db1817921a970f8d27
        gist-id: 90ef67a684cb71db1817921a970f8d27
        gist-auth-token: ${{ secrets.GIST_AUTH_TOKEN }}  

徽章工具需要 opencover.xml 文件的路径。我可以很好地生成文件,但它最终位于文件UnitTests/TestResults/<UUID>/coverage.opencover.xml 中。

根据上述内容,我无法(但显然)更改 VSTest 的行为。所以我需要想办法将输出中的 UUID 捕获到一个变量中并在 path: 中使用它。

那个 UUID 就在测试运行结果中,我只需要以某种方式抓住它:

image

这可能吗?或者,是否有某种方法可以使用通配符执行复制命令,将 UnitTest/TestResults/*/内容复制到某个确定性的位置?

解决方法

我已经弄清楚了,我正在回答我自己的问题,以防其他一些 YAML 菜鸟有类似的问题:

只需使用 Linux mv 命令来移动文件:

- name: Test
      run: |
        dotnet test --no-restore --verbosity normal --collect:"XPlat Code Coverage"  --settings UnitTests/coverlet.runsettings
        mv -v UnitTests/TestResults/*/*.* UnitTests/TestResults/

    - name: Create Test Coverage Badge
      uses: simon-k/dotnet-code-coverage-badge@v1.0.0
      id: create_coverage_badge
      with:
        label: Unit Test Coverage
        color: brightgreen
        path: UnitTests/TestResults/coverage.opencover.xml
        gist-filename: code-coverage.json
        # https://gist.github.com/migueldeicaza/90ef67a684cb71db1817921a970f8d27
        gist-id: 90ef67a684cb71db1817921a970f8d27
        gist-auth-token: ${{ secrets.GIST_AUTH_TOKEN }}   

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。