Skip to content

Commit

Permalink
Merge pull request #82 from agrare/github_actions
Browse files Browse the repository at this point in the history
Changes for Github Actions
  • Loading branch information
Fryguy authored Feb 8, 2022
2 parents 35de770 + 4e4065c commit 15e773c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 65 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/manageiq_cross_repo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: ManageIQ Cross Repo Workflow

on:
workflow_call:
inputs:
test-repo:
required: true
type: string
repos:
required: true
type: string
test-suite:
required: false
type: string

jobs:
ci:
name: Run manageiq-cross_repo
runs-on: ubuntu-latest
strategy:
fail-fast: false
services:
postgres:
image: manageiq/postgresql:10
env:
POSTGRESQL_USER: root
POSTGRESQL_PASSWORD: smartvm
POSTGRESQL_DATABASE: vmdb_test
options: --health-cmd pg_isready --health-interval 2s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
env:
TEST_SUITE: ${{ inputs.test-suite }}
REPOS: ${{ inputs.repos }}
TEST_REPO: ${{ inputs.test-repo }}
PGHOST: localhost
PGPASSWORD: smartvm
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 12
registry-url: https://npm.manageiq.org/
- name: Run tests
run: bundle exec manageiq-cross_repo
2 changes: 1 addition & 1 deletion lib/manageiq/cross_repo/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run_tests
end

def env_vars
{"MANAGEIQ_REPO" => core_repo.path.to_s, "TRAVIS_BUILD_DIR" => test_repo.path.to_s, "BUNDLE_PATH" => bundle_path.to_s, "TEST_SUITE" => test_suite}
{"MANAGEIQ_REPO" => core_repo.path.to_s, "BUNDLE_PATH" => bundle_path.to_s, "TEST_SUITE" => test_suite}
end

def with_test_env
Expand Down
15 changes: 6 additions & 9 deletions lib/manageiq/cross_repo/runner/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
module ManageIQ::CrossRepo
class Runner
class Base
attr_accessor :script_cmd
attr_accessor :script_cmd, :config

def initialize(script_cmd = nil)
@script_cmd = script_cmd.presence
@config = load_config!
end

def build_test_script
Expand Down Expand Up @@ -49,9 +50,9 @@ def build_section_commands(section)

def build_section(section, *commands)
[
"echo 'travis_fold:start:#{section}'",
"echo '::group::#{section}'",
*commands,
"echo 'travis_fold:end:#{section}'"
"echo '::endgroup::'"
]
end

Expand All @@ -64,11 +65,7 @@ def build_script
end

def load_config!
config
end

def config
@config ||= travis_config.tap do |config|
ci_config.tap do |config|
# Set missing sections to the proper defaults
config["install"] ||= defaults[config["language"]]["install"]

Expand All @@ -77,7 +74,7 @@ def config
end
end

def travis_config
def ci_config
raise NotImplementedError, "must be implemented in a subclass"
end

Expand Down
20 changes: 12 additions & 8 deletions lib/manageiq/cross_repo/runner/github.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative "./base"
require "yaml"
require "active_support/core_ext/enumerable"

module ManageIQ::CrossRepo
class Runner
Expand All @@ -12,18 +13,21 @@ def self.available?

private

def travis_config
def ci_config
github_config = YAML.load_file(CONFIG_FILE)

steps = github_config["jobs"]["ci"]["steps"]
steps_by_name = steps.index_by { |step| step["name"] }

language = steps.any? { |s| s["uses"] == "ruby/setup-ruby@v1" } ? "ruby" : "node_js"

defaults[language].clone.tap do |config|
script_step = steps.detect { |s| s["name"] == "Run tests" }
config["script"] = script_step["run"] if script_step
end
end
result = {"language" => language}

result["before_install"] = steps_by_name["Set up system"]["run"] if steps_by_name["Set up system"]
result["before_script"] = steps_by_name["Prepare tests"]["run"] if steps_by_name["Prepare tests"]
result["script"] = steps_by_name["Run tests"]["run"] if steps_by_name["Run tests"]

def github_config
YAML.load_file(CONFIG_FILE)
result
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/manageiq/cross_repo/runner/travis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.available?

private

def travis_config
def ci_config
YAML.load_file(CONFIG_FILE)
end
end
Expand Down
42 changes: 29 additions & 13 deletions spec/manageiq/cross_repo/runner/github_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
describe ManageIQ::CrossRepo::Runner::Github do
describe "#build_test_script" do
let(:script_cmd) { nil }
let(:runner) do
described_class.new(script_cmd).tap do |r|
require "yaml"
allow(r).to receive(:github_config).and_return(YAML.load(github_yml))
end
let(:runner) { described_class.new(script_cmd) }

before do
require "yaml"
allow(YAML).to receive(:load_file).with(described_class::CONFIG_FILE).and_return(YAML.load(github_yml))
end

context "ruby" do
Expand All @@ -25,11 +25,15 @@
- '2.7'
steps:
- uses: actions/checkout@v2
- name: Set up system
run: bin/before_install
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Prepare tests
run: bin/setup
- name: Run tests
run: bundle exec rake
env:
Expand All @@ -47,12 +51,18 @@
expected_test_script = <<~SCRIPT
#!/bin/bash
echo 'travis_fold:start:install'
echo '::group::before_install'
bin/before_install || exit $?
echo '::endgroup::'
echo '::group::install'
bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} || exit $?
echo 'travis_fold:end:install'
echo 'travis_fold:start:script'
echo '::endgroup::'
echo '::group::before_script'
bin/setup || exit $?
echo '::endgroup::'
echo '::group::script'
bundle exec rake || exit $?
echo 'travis_fold:end:script'
echo '::endgroup::'
SCRIPT

expect(runner.build_test_script).to eq(expected_test_script)
Expand All @@ -65,12 +75,18 @@
expected_test_script = <<~SCRIPT
#!/bin/bash
echo 'travis_fold:start:install'
echo '::group::before_install'
bin/before_install || exit $?
echo '::endgroup::'
echo '::group::install'
bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} || exit $?
echo 'travis_fold:end:install'
echo 'travis_fold:start:script'
echo '::endgroup::'
echo '::group::before_script'
bin/setup || exit $?
echo '::endgroup::'
echo '::group::script'
cat db/schema.rb || exit $?
echo 'travis_fold:end:script'
echo '::endgroup::'
SCRIPT

expect(runner.build_test_script).to eq(expected_test_script)
Expand Down
66 changes: 33 additions & 33 deletions spec/manageiq/cross_repo/runner/travis_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
describe ManageIQ::CrossRepo::Runner::Travis do
describe "#build_test_script" do
let(:script_cmd) { nil }
let(:runner) do
described_class.new(script_cmd).tap do |r|
require "yaml"
allow(r).to receive(:travis_config).and_return(YAML.load(travis_yml))
end
let(:runner) { described_class.new(script_cmd) }

before do
require "yaml"
allow(YAML).to receive(:load_file).with(described_class::CONFIG_FILE).and_return(YAML.load(travis_yml))
end

context "ruby" do
Expand All @@ -23,12 +23,12 @@
expected_test_script = <<~SCRIPT
#!/bin/bash
echo 'travis_fold:start:install'
echo '::group::install'
bundle install || exit $?
echo 'travis_fold:end:install'
echo 'travis_fold:start:script'
echo '::endgroup::'
echo '::group::script'
bundle exec rake || exit $?
echo 'travis_fold:end:script'
echo '::endgroup::'
SCRIPT

expect(runner.build_test_script).to eq(expected_test_script)
Expand All @@ -41,12 +41,12 @@
expected_test_script = <<~SCRIPT
#!/bin/bash
echo 'travis_fold:start:install'
echo '::group::install'
bundle install || exit $?
echo 'travis_fold:end:install'
echo 'travis_fold:start:script'
echo '::endgroup::'
echo '::group::script'
cat db/schema.rb || exit $?
echo 'travis_fold:end:script'
echo '::endgroup::'
SCRIPT

expect(runner.build_test_script).to eq(expected_test_script)
Expand All @@ -72,16 +72,16 @@
expected_test_script = <<~SCRIPT
#!/bin/bash
echo 'travis_fold:start:environment'
echo '::group::environment'
source ~/.nvm/nvm.sh
nvm install 12
echo 'travis_fold:end:environment'
echo 'travis_fold:start:install'
echo '::endgroup::'
echo '::group::install'
yarn || exit $?
echo 'travis_fold:end:install'
echo 'travis_fold:start:script'
echo '::endgroup::'
echo '::group::script'
yarn run test || exit $?
echo 'travis_fold:end:script'
echo '::endgroup::'
SCRIPT

expect(runner.build_test_script).to eq(expected_test_script)
Expand All @@ -94,16 +94,16 @@
expected_test_script = <<~SCRIPT
#!/bin/bash
echo 'travis_fold:start:environment'
echo '::group::environment'
source ~/.nvm/nvm.sh
nvm install 12
echo 'travis_fold:end:environment'
echo 'travis_fold:start:install'
echo '::endgroup::'
echo '::group::install'
yarn || exit $?
echo 'travis_fold:end:install'
echo 'travis_fold:start:script'
echo '::endgroup::'
echo '::group::script'
cat yarn.lock || exit $?
echo 'travis_fold:end:script'
echo '::endgroup::'
SCRIPT

expect(runner.build_test_script).to eq(expected_test_script)
Expand All @@ -124,12 +124,12 @@
expected_test_script = <<~SCRIPT
#!/bin/bash
echo 'travis_fold:start:install'
echo '::group::install'
bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} || exit $?
echo 'travis_fold:end:install'
echo 'travis_fold:start:script'
echo '::endgroup::'
echo '::group::script'
bundle exec rake || exit $?
echo 'travis_fold:end:script'
echo '::endgroup::'
SCRIPT

expect(runner.build_test_script).to eq(expected_test_script)
Expand All @@ -153,13 +153,13 @@
expected_test_script = <<~SCRIPT
#!/bin/bash
echo 'travis_fold:start:install'
echo '::group::install'
bundle install || exit $?
echo 'travis_fold:end:install'
echo 'travis_fold:start:script'
echo '::endgroup::'
echo '::group::script'
bundle exec rake || exit $?
bundle exec rake spec:javascript || exit $?
echo 'travis_fold:end:script'
echo '::endgroup::'
SCRIPT

expect(runner.build_test_script).to eq(expected_test_script)
Expand Down

0 comments on commit 15e773c

Please sign in to comment.