【问题标题】:Is there currently a way to extract the output of a fastlane action within the fastlane actions?目前有没有办法在快车道动作中提取快车道动作的输出?
【发布时间】:2019-02-06 20:02:07
【问题描述】:

我正在使用第三方 fastlane 插件,它包含一个操作,可以显示我需要捕获的重要信息,例如链接。

我试图找到一种优雅的方法来在 fastlane 操作中捕获这些日志,我试图避免使用 shell 命令,但如果这是唯一的方法,那么我想我别无选择。

我需要此链接,因为它是一个独特且随机的链接,其中包含我要下载的资源。

我尝试重定向 stdout 无济于事,因为 fastlane 使用他们自己的记录器(通常是 UI.message)并且正要向 fastlane 提交功能请求,但我想也许其他人已经遇到了这个问题并设法克服了它。

有没有办法重定向这种类型的日志并捕获它?

这里是围绕 UI 的 fastlane 源代码:https://github.com/fastlane/fastlane/tree/master/fastlane_core/lib/fastlane_core/ui

这是我尝试重定向输出的方法之一: Capturing logger output inside a method

任何帮助/建议/资源将不胜感激!

【问题讨论】:

    标签: ruby output fastlane capture-output


    【解决方案1】:

    我不确定这是否正是 OP 想要的答案,但似乎确实有一种方法可以将操作结果作为 json 字符串获取。我在这里添加这个是因为我在搜索我的问题时发现了这个问题,并且在 fastlane 文档中并没有很明显地表明这是可能的。

    在我的 Fastlane 文件中,我使用了以下操作:

      packageName = "com.example.mine"
    
      versionName = google_play_track_release_names(
        package_name: packageName,
        track: "production"
      )
    
      versionCode = google_play_track_version_codes(
        package_name: packageName,
        track: "production"
      )
    
      UI.message "Package Info: #{packageName}, #{versionName} #{versionCode}"
    

    输出看起来像这样

    Package Info: com.example.mine, ["4.2.0"] [2027]
    

    我还通过 grep 管道命令来抑制所有屏幕输出,以获得我想要的行。 (我也找不到执行此操作的参数或选项。)

    fastlane android get_version | grep "Package Info
    

    希望这对像我这样的菜鸟有所帮助!

    【讨论】:

    • 非常感谢您的回答!这比我原本打算写的文件要好得多。非常感谢。
    【解决方案2】:

    我不知道这是否对你有帮助,但我设法使用这个简单的方法将 fastlane stdout 捕获到一个变量中以获得我想要的(在我的例子中是获取 iPhone 开发证书的通用名称)

    def with_captured_stdout
      original_stdout = $stdout
      $stdout = StringIO.new
      yield
      $stdout.string
    ensure
      $stdout = original_stdout
    end
    
    lane :test do |options|
      match_dev = with_captured_stdout { match(type: 'development') }
      puts match_dev
      @dev_index = match_dev.index('iPhone Developer')
      ENV['DEV_CODE_SIGN_ID'] = match_dev[@dev_index..match_dev.index(')', @dev_index)]
      # ENV['DEV_CODE_SIGN_ID'] = "iPhone Developer: Test Name (XXXXXXXX)"
    end
    

    来自https://stackoverflow.com/a/22777806/1034194

    【讨论】:

      【解决方案3】:

      我忘了更新这个,但最后我这样解决了:

      module Fastlane
        module Helper
          class UtilHelper
            # Redirects standard output and standard error to a file
            # (currently only way we know how to capture fastlane ui messages)
            def self.redirect_stdout_to_file(filename)
              original_stdout = $stdout.clone
              original_stderr = $stderr.clone
              $stderr.reopen File.new(filename, 'w')
              $stdout.reopen File.new(filename, 'w')
              yield
            ensure
              $stdout.reopen original_stdout
              $stderr.reopen original_stderr
            end
      
          end
        end
      end
      

      我是这样使用它的:

      temp_file = 'testlab.log'
      UtilHelper.redirect_stdout_to_file(temp_file) { upload_xctestrun() }
      

      upload_xctrestrun 的作用无关紧要,只要知道它是一个来自 fastlane 插件的函数,它使用 fastlane UI 对象输出消息,如下所示:

      UI.message("Some fastlane decorated message here")
      

      希望这对任何人都有帮助:)

      【讨论】:

        【解决方案4】:

        fastlane 的构建方式允许您将 UI 层替换为您自己的层。你可以在 fastlane.ci GitHub repo https://github.com/fastlane/ci/blob/master/app/features/build_runner/fastlane_build_runner_helpers/fastlane_ci_output.rb找到一个示例实现

        然后您将设置它的方式如下

              ci_output = FastlaneCI::FastlaneCIOutput.new(
                each_line_block: proc do |raw_row|
                  puts "new line here, access raw_row"
                end
              )
        
              FastlaneCore::UI.ui_object = ci_output
        

        【讨论】:

        • 我有点明白你在说什么,但我不是直接尝试访问 UI.messages 的结果,我想获取使用这些操作的输出,例如扫描。这些方面的东西:output = scan( arg: 'value')
        猜你喜欢
        • 2018-07-19
        • 1970-01-01
        • 1970-01-01
        • 2018-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多