Module: Polyrun::Env::Ci
- Defined in:
- lib/polyrun/env/ci.rb
Overview
CI-native shard index/total (spec2 ยง6.4) without extra gems.
Class Method Summary collapse
-
.detect_shard_index ⇒ Object
Returns Integer shard index or nil if not inferable from CI env.
-
.detect_shard_total ⇒ Object
Returns Integer shard total or nil.
- .polyrun_env ⇒ Object
- .present?(s) ⇒ Boolean
- .truthy?(s) ⇒ Boolean
Class Method Details
.detect_shard_index ⇒ Object
Returns Integer shard index or nil if not inferable from CI env.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/polyrun/env/ci.rb', line 8 def detect_shard_index return Integer(ENV["POLYRUN_SHARD_INDEX"]) if present?(ENV["POLYRUN_SHARD_INDEX"]) ci = truthy?(ENV["CI"]) if present?(ENV["CI_NODE_INDEX"]) && ci return Integer(ENV["CI_NODE_INDEX"]) end if present?(ENV["BUILDKITE_PARALLEL_JOB"]) && ci return Integer(ENV["BUILDKITE_PARALLEL_JOB"]) end if present?(ENV["CIRCLE_NODE_INDEX"]) && ci return Integer(ENV["CIRCLE_NODE_INDEX"]) end nil rescue ArgumentError, TypeError nil end |
.detect_shard_total ⇒ Object
Returns Integer shard total or nil.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/polyrun/env/ci.rb', line 28 def detect_shard_total return Integer(ENV["POLYRUN_SHARD_TOTAL"]) if present?(ENV["POLYRUN_SHARD_TOTAL"]) ci = truthy?(ENV["CI"]) if present?(ENV["CI_NODE_TOTAL"]) && ci return Integer(ENV["CI_NODE_TOTAL"]) end if present?(ENV["BUILDKITE_PARALLEL_JOB_COUNT"]) && ci return Integer(ENV["BUILDKITE_PARALLEL_JOB_COUNT"]) end if present?(ENV["CIRCLE_NODE_TOTAL"]) && ci return Integer(ENV["CIRCLE_NODE_TOTAL"]) end nil rescue ArgumentError, TypeError nil end |
.polyrun_env ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/polyrun/env/ci.rb', line 47 def polyrun_env e = ENV["POLYRUN_ENV"]&.strip return e if present?(e) return "ci" if truthy?(ENV["CI"]) "local" end |
.present?(s) ⇒ Boolean
56 57 58 |
# File 'lib/polyrun/env/ci.rb', line 56 def present?(s) !s.nil? && !s.to_s.empty? end |
.truthy?(s) ⇒ Boolean
60 61 62 |
# File 'lib/polyrun/env/ci.rb', line 60 def truthy?(s) %w[1 true yes].include?(s.to_s.downcase) end |