Skip to content

Commit aa80459

Browse files
committed
Use all steps from a github actions workflow
1 parent 5c9ed46 commit aa80459

File tree

3 files changed

+54
-48
lines changed

3 files changed

+54
-48
lines changed

lib/manageiq/cross_repo/runner/base.rb

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,6 @@ def build_test_script
2121

2222
private
2323

24-
def environment_setup_commands
25-
commands = []
26-
27-
if config["node_js"]
28-
commands << "source ~/.nvm/nvm.sh"
29-
commands += Array(config["node_js"]).map do |node_version|
30-
"nvm install #{node_version}"
31-
end
32-
end
33-
34-
commands.any? ? build_section("environment", *commands) : commands
35-
end
36-
37-
def section_commands
38-
sections = %w[before_install install before_script script]
39-
sections.flat_map do |section|
40-
commands = build_section_commands(section)
41-
build_section(section, *commands) if commands.present?
42-
end.compact
43-
end
44-
45-
def build_commands
46-
environment_setup_commands + section_commands
47-
end
48-
4924
def build_section_commands(section)
5025
# Travis sections can have a single command or an array of commands
5126
Array(config[section]).map { |cmd| "#{cmd} || exit $?" }
@@ -60,16 +35,6 @@ def build_section(section, *commands)
6035
end
6136

6237
def load_config!
63-
ci_config.tap do |config|
64-
# Set missing sections to the proper defaults
65-
config["install"] ||= defaults[config["language"]]["install"]
66-
67-
config["script"] = script_cmd if script_cmd.present?
68-
config["script"] ||= defaults[config["language"]]["script"]
69-
end
70-
end
71-
72-
def ci_config
7338
raise NotImplementedError, "must be implemented in a subclass"
7439
end
7540

lib/manageiq/cross_repo/runner/github.rb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@ def self.available?
1313

1414
private
1515

16-
def ci_config
17-
github_config = YAML.load_file(CONFIG_FILE)
18-
19-
steps = github_config["jobs"]["ci"]["steps"]
20-
steps_by_name = steps.index_by { |step| step["name"] }
21-
22-
language = steps.any? { |s| s["uses"] == "ruby/setup-ruby@v1" } ? "ruby" : "node_js"
23-
24-
result = {"language" => language}
16+
def build_commands
17+
config.dig("jobs", "ci", "steps").map do |step|
18+
if step["run"].nil?
19+
case step["uses"]
20+
when /ruby\/setup-ruby/
21+
step["run"] = defaults["ruby"]["install"]
22+
when /actions\/setup-node/
23+
step["run"] = defaults["node_js"]["install"]
24+
end
25+
end
26+
27+
build_section(step["name"], step["run"])
28+
end.compact
29+
end
2530

26-
result["before_install"] = steps_by_name["Set up system"]["run"] if steps_by_name["Set up system"]
27-
result["before_script"] = steps_by_name["Prepare tests"]["run"] if steps_by_name["Prepare tests"]
28-
result["script"] = steps_by_name["Run tests"]["run"] if steps_by_name["Run tests"]
31+
def load_config!
32+
ci_config
33+
end
2934

30-
result
35+
def ci_config
36+
YAML.load_file(CONFIG_FILE)
3137
end
3238
end
3339
end

lib/manageiq/cross_repo/runner/travis.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@ def self.available?
1212

1313
private
1414

15+
def environment_setup_commands
16+
commands = []
17+
18+
if config["node_js"]
19+
commands << "source ~/.nvm/nvm.sh"
20+
commands += Array(config["node_js"]).map do |node_version|
21+
"nvm install #{node_version}"
22+
end
23+
end
24+
25+
commands.any? ? build_section("environment", *commands) : commands
26+
end
27+
28+
def section_commands
29+
sections = %w[before_install install before_script script]
30+
sections.flat_map do |section|
31+
commands = build_section_commands(section)
32+
build_section(section, *commands) if commands.present?
33+
end.compact
34+
end
35+
36+
def build_commands
37+
environment_setup_commands + section_commands
38+
end
39+
40+
def load_config!
41+
ci_config.tap do |config|
42+
# Set missing sections to the proper defaults
43+
config["install"] ||= defaults[config["language"]]["install"]
44+
45+
config["script"] = script_cmd if script_cmd.present?
46+
config["script"] ||= defaults[config["language"]]["script"]
47+
end
48+
end
49+
1550
def ci_config
1651
YAML.load_file(CONFIG_FILE)
1752
end

0 commit comments

Comments
 (0)