Skip to content

Commit fc494e2

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

File tree

4 files changed

+65
-82
lines changed

4 files changed

+65
-82
lines changed

lib/manageiq/cross_repo/runner/base.rb

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +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-
49-
def build_section_commands(section)
50-
# Travis sections can have a single command or an array of commands
51-
Array(config[section]).map { |cmd| "#{cmd} || exit $?" }
52-
end
53-
5424
def build_section(section, *commands)
5525
[
5626
"echo '::group::#{section}'",
@@ -60,16 +30,6 @@ def build_section(section, *commands)
6030
end
6131

6232
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
7333
raise NotImplementedError, "must be implemented in a subclass"
7434
end
7535

lib/manageiq/cross_repo/runner/github.rb

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@ 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+
else
25+
next
26+
end
27+
end
28+
29+
build_section(step["name"], "#{step["run"]} || exit $?")
30+
end.compact
31+
end
2532

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"]
33+
def load_config!
34+
ci_config
35+
end
2936

30-
result
37+
def ci_config
38+
YAML.load_file(CONFIG_FILE)
3139
end
3240
end
3341
end

lib/manageiq/cross_repo/runner/travis.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,46 @@ 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 build_section_commands(section)
41+
# Travis sections can have a single command or an array of commands
42+
Array(config[section]).map { |cmd| "#{cmd} || exit $?" }
43+
end
44+
45+
def load_config!
46+
ci_config.tap do |config|
47+
# Set missing sections to the proper defaults
48+
config["install"] ||= defaults[config["language"]]["install"]
49+
50+
config["script"] = script_cmd if script_cmd.present?
51+
config["script"] ||= defaults[config["language"]]["script"]
52+
end
53+
end
54+
1555
def ci_config
1656
YAML.load_file(CONFIG_FILE)
1757
end

spec/manageiq/cross_repo/runner/github_spec.rb

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,47 +51,22 @@
5151
expected_test_script = <<~SCRIPT
5252
#!/bin/bash
5353
54-
echo '::group::before_install'
54+
echo '::group::Set up system'
5555
bin/before_install || exit $?
5656
echo '::endgroup::'
57-
echo '::group::install'
57+
echo '::group::Set up Ruby'
5858
bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} || exit $?
5959
echo '::endgroup::'
60-
echo '::group::before_script'
60+
echo '::group::Prepare tests'
6161
bin/setup || exit $?
6262
echo '::endgroup::'
63-
echo '::group::script'
63+
echo '::group::Run tests'
6464
bundle exec rake || exit $?
6565
echo '::endgroup::'
6666
SCRIPT
6767

6868
expect(runner.build_test_script).to eq(expected_test_script)
6969
end
70-
71-
context "with a script_cmd" do
72-
let(:script_cmd) { "cat db/schema.rb" }
73-
74-
it "builds a test script" do
75-
expected_test_script = <<~SCRIPT
76-
#!/bin/bash
77-
78-
echo '::group::before_install'
79-
bin/before_install || exit $?
80-
echo '::endgroup::'
81-
echo '::group::install'
82-
bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} || exit $?
83-
echo '::endgroup::'
84-
echo '::group::before_script'
85-
bin/setup || exit $?
86-
echo '::endgroup::'
87-
echo '::group::script'
88-
cat db/schema.rb || exit $?
89-
echo '::endgroup::'
90-
SCRIPT
91-
92-
expect(runner.build_test_script).to eq(expected_test_script)
93-
end
94-
end
9570
end
9671

9772
# TODO: Add node_js when we have a node_js repo

0 commit comments

Comments
 (0)