blob: 9e93b4705582b3f88560e51c10b66c20516f36c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/env ruby
# frozen_string_literal: true
# In spec/scripts/setup/generate_as_if_foss_env_spec.rb we completely stub it
require 'gitlab' unless Object.const_defined?(:Gitlab)
require 'set' # rubocop:disable Lint/RedundantRequireStatement -- Ruby 3.1 and earlier needs this. Drop this line after Ruby 3.2+ is only supported.
class GenerateAsIfFossEnv
def initialize
@client = Gitlab.client(endpoint: ENV['CI_API_V4_URL'], private_token: '')
@rspec_jobs = Set.new
@jest_jobs = Set.new
end
def variables
@variables ||= generate_variables
end
def display
variables.each do |key, value|
puts "#{key}=#{value}"
end
end
private
attr_reader :client, :rspec_jobs, :jest_jobs
def generate_variables
scan_jobs
{
START_AS_IF_FOSS: 'true',
RUBY_VERSION: ENV['RUBY_VERSION']
}.merge(rspec_variables).merge(jest_variables)
end
def scan_jobs
each_job do |job|
detect_rspec(job) || detect_jest(job)
end
end
def each_job
client.pipeline_jobs(ENV['CI_PROJECT_ID'], ENV['CI_PIPELINE_ID']).auto_paginate do |job|
yield(job)
end
end
def detect_rspec(job)
rspec_type = job.name[/^rspec ([\w\-]+)/, 1]
rspec_jobs << rspec_type if rspec_type
end
def detect_jest(job)
jest_type = job.name[/^jest([\w\-]*)/, 1]
jest_jobs << jest_type if jest_type
end
def rspec_variables
return {} if rspec_jobs.empty?
rspec_jobs.inject({ ENABLE_RSPEC: 'true' }) do |result, rspec|
result.merge("ENABLE_RSPEC_#{rspec.upcase.tr('-', '_')}": 'true')
end
end
def jest_variables
return {} if jest_jobs.empty?
jest_jobs.inject({ ENABLE_JEST: 'true' }) do |result, jest|
result.merge("ENABLE_JEST#{jest.upcase.tr('-', '_')}": 'true')
end
end
end
GenerateAsIfFossEnv.new.display if $PROGRAM_NAME == __FILE__
|