我正在 GitLab 上為 .NET 6 專案設定管道。coverage.cobertura.xml我運行測驗,然后在檔案中生成代碼覆寫率報告。這是測驗作業腳本:
test:
only:
- master
- /^feature/.*$/
stage: test
dependencies:
- build-application
variables:
CONFIGURATION: "Debug"
COVERAGE_FLAG: "XPlat Code Coverage"
LOGGER_FLAG: "junit;LogFilePath=$CI_PROJECT_DIR/junit/junit-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
TEST_PROJECTS: "./tests/*Tests/*.csproj"
script:
- 'dotnet test $TEST_PROJECTS
-c $CONFIGURATION
-r $CI_PROJECT_DIR/cobertura
--collect:"$COVERAGE_FLAG"
--test-adapter-path:.
--logger:"$LOGGER_FLAG"'
- chmod x ./scripts/print-dotnet-coverage.sh
- ./scripts/print-dotnet-coverage.sh $CI_PROJECT_DIR/cobertura
coverage: /TOTAL_COVERAGE=(\d .\d )/
artifacts:
when: on_success
paths:
- $CI_PROJECT_DIR/cobertura/*/coverage.cobertura.xml
- $CI_PROJECT_DIR/junit/junit-test-result.xml
reports:
coverage_report:
coverage_format: cobertura
path: $CI_PROJECT_DIR/cobertura/*/coverage.cobertura.xml
junit:
- $CI_PROJECT_DIR/junit/junit-test-result.xml
痛苦是測驗命令不會產生任何關于總覆寫率的輸出,所以我從新創建的coverage.cobertura.xml檔案中提取它并使用以下腳本將它列印到標準輸出
#!/usr/bin/env sh
REPORTS_DIR="${1}"
coverage=0
count=0
for i in $(find "$REPORTS_DIR" -name '*.xml');
do
printf "Found coverage report: %s\n" "$i"
coverage="$(xmllint --xpath 'string(/coverage/@line-rate)' ${i})"
count=$((count 1))
done;
printf "Found a total of %i report(s)\n" "$count"
coverage=$(echo "$coverage * 100" | bc) <-- error here
printf "TOTAL_COVERAGE=%2.4f\n" "$(echo "${coverage}")"
因為覆寫率是 0.8875,所以我必須乘以 100。但是我得到了一個錯誤
./scripts/print-dotnet-coverage.sh: 12: bc: not found
有誰知道如何解決這個錯誤或如何實作我的目的——在 GitLab CI 中將覆寫率乘以 100——而不使用 bc?
謝謝!
uj5u.com熱心網友回復:
請參閱以下示例專案以設定代碼覆寫率報告:dotnet-example
- .gitlab-ci.yml
- 測驗作業輸出
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/491438.html
下一篇:請使用<&解釋這個shell腳本
