You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

meta_message_builder.rb 3.5 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. require 'cucumber/messages'
  2. require 'cucumber/ci_environment'
  3. module Cucumber
  4. class Runtime
  5. # Builder to instanciate a Cucumber::Messages::Meta message filled-in with
  6. # the runtime meta-data:
  7. # - protocol version: the version of the Cucumber::Messages protocol
  8. # - implementation: the name and version of the implementation (e.g. cucumber-ruby 8.0.0)
  9. # - runtime: the name and version of the runtime (e.g. ruby 3.0.1)
  10. # - os: the name and version of the operating system (e.g. linux 3.13.0-45-generic)
  11. # - cpu: the name of the CPU (e.g. x86_64)
  12. # - ci: informtion about the CI environment if any, including:
  13. # - name: the name of the CI environment (e.g. Jenkins)
  14. # - url: the URL of the CI environment (e.g. https://ci.example.com)
  15. # - build_number: the build number of the CI environment (e.g. 123)
  16. # - git: the git information of the CI environment if any
  17. # - remote: the remote of the git repository (e.g. git@github.com:cucumber/cucumber-ruby.git)
  18. # - revision: the revision of the git repository (e.g. abcdef)
  19. # - branch: the name of the git branch (e.g. main)
  20. # - tag: the name of the git tag (e.g. v1.0.0)
  21. class MetaMessageBuilder
  22. class << self
  23. # Builds a Cucumber::Messages::Meta filled-in with the runtime meta-data
  24. #
  25. # @param [env] environment data from which the CI information will be
  26. # retrieved (default ENV). Can be used to mock the environment for
  27. # testing purpose.
  28. #
  29. # @return [Cucumber::Messages::Meta] the meta message
  30. #
  31. # @see Cucumber::Runtime::MetaMessageBuilder
  32. #
  33. # @example
  34. # Cucumber::Runtime::MetaMessageBuilder.build_meta_message
  35. #
  36. def build_meta_message(env = ENV)
  37. Cucumber::Messages::Meta.new(
  38. protocol_version: protocol_version,
  39. implementation: implementation,
  40. runtime: runtime,
  41. os: os,
  42. cpu: cpu,
  43. ci: ci(env)
  44. )
  45. end
  46. private
  47. def protocol_version
  48. Cucumber::Messages::VERSION
  49. end
  50. def implementation
  51. Cucumber::Messages::Product.new(
  52. name: 'cucumber-ruby',
  53. version: Cucumber::VERSION
  54. )
  55. end
  56. def runtime
  57. Cucumber::Messages::Product.new(
  58. name: RUBY_ENGINE,
  59. version: RUBY_VERSION
  60. )
  61. end
  62. def os
  63. Cucumber::Messages::Product.new(
  64. name: RbConfig::CONFIG['target_os'],
  65. version: Sys::Uname.uname.version
  66. )
  67. end
  68. def cpu
  69. Cucumber::Messages::Product.new(
  70. name: RbConfig::CONFIG['target_cpu']
  71. )
  72. end
  73. def ci(env)
  74. ci_data = Cucumber::CiEnvironment.detect_ci_environment(env)
  75. return nil unless ci_data
  76. Cucumber::Messages::Ci.new(
  77. name: ci_data[:name],
  78. url: ci_data[:url],
  79. build_number: ci_data[:buildNumber],
  80. git: git_info(ci_data)
  81. )
  82. end
  83. def git_info(ci_data)
  84. return nil unless ci_data[:git]
  85. Cucumber::Messages::Git.new(
  86. remote: ci_data[:git][:remote],
  87. revision: ci_data[:git][:revision],
  88. branch: ci_data[:git][:branch],
  89. tag: ci_data[:git][:tag]
  90. )
  91. end
  92. end
  93. end
  94. end
  95. end

No Description

Contributors (1)