首页 > 解决方案 > grep xcov 结果转换为 fastfile 中的变量

问题描述

我正在使用 fastlane,但我不想使用 xcov slack 功能,我正在将所有信息编译到进一步发送的同一个 slack 通知中。

lane :run_my_stuff do

xcov(project: "my-app.xcodeproj", 
     scheme: "my_scheme",
     output_directory: "xcov_output",
     only_project_targets: true)

$coverage=sh("grep \"(\d+.\d+\%)\"")

slack(message: "",
      success: true,
      slack_url: "https://hooks.slack.com/services/xxxxxxxx...",
      default_payloads: [],
      link_names: true,
      attachment_properties: {
            fields: [{
                      title: "Coverage",
                      value: $coverage
                     }
            ]
      })
end

这不起作用,但我相信它显示了我正在努力实现的目标。我也尝试使用:

$coverage=sh("cat xcov_report/index.html | grep '\d\+.\d\+\%' | head -1")

标签: grepcode-coveragefastlane

解决方案


我发现我的代码出了什么问题。几件事(叹气)

  1. 不需要美元符号
coverage=sh("cat xcov_output/index.html | grep '\\d\\+.\\d\\+\\%' -o | head -1")
  1. 我所在的文件夹和我想的不一样。所以我将输出路径更改为fastlane/xcov_output

  2. 正则表达式的转义是不够的。所以我加倍了

结尾

xcov(project: "my-app.xcodeproj",
       scheme: "MOCK",
       output_directory: "fastlane/xcov_output",
       only_project_targets: true)

release_notes=sh("git tag -l --format='%(contents)' $(git describe $(git rev-list --tags --max-count=1))")

coverage=sh("cat xcov_output/index.html | grep '\\d\\+.\\d\\+\\%' -o | head -1")

slack(message: " b(#{number_of_commits}) <@XXXXX>",
       success: true,
       slack_url: "https://hooks.slack.com/services/...",
       default_payloads: [],
       link_names: true,
       attachment_properties: {
           fields: [
               {
                   title: "Release notes",
                   value: release_notes
               },
               {
                   title: "Environment",
                   value: environment.capitalize
               },
               {
                   title: "Coverage",
                   value: coverage
               }
           ]
       }
   )

推荐阅读