singularity_dsl 1.6.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTEyYmQzY2NkMDJmOTc3Yjk3NDVkMGVlNGYzNDAxM2E1ODVlZTU4NA==
4
+ ODFhM2I0MWY1MzZjYTllMTBhOTk5NjU5OWRkMTRlOWMyNmI3ZDM4MA==
5
5
  data.tar.gz: !binary |-
6
- NTFhNzNkMjVjYThkMDJjNmQwYjAwYTMwMjNjOTE4ZjBhMTYxOWRlMQ==
6
+ ZjJlZDBlZTNhYTkwOWJlMDEyYjI0ZjYwODg2ZDMyN2Q3ZTJiNzBhZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGE1MGVlZDg0MGY4NDY2ZGU2OTgxNzM4MjQzNTg5OWFhNTBmMzhlMzE1MjNi
10
- MTVmOGQ1M2NhOWFhNzVjYzViMjIxZTkyZjY5ZDM5M2RhYWNlMzBhYTlhZWJm
11
- NTNhNmUxZGZjOWIyODg3NTQxZjE0OTc0NGIwMDY0ZDg2M2U4MTU=
9
+ MjEwNzEzNDdiMGExZTk5OWU2NTAyYjgyYmFlOTBhZmU1YzVhMzAwZTNiOGYx
10
+ NDMzNzAzM2VlNzZmMTlmYTFjODAxNTI0MjkzZjc1Zjg2YmUwNzA4YzQzYTk2
11
+ OTdiMWY1ZTVmMDNmNjgxOWJkNjMzZTA0ZDg1ODMwYTYzNzRjY2I=
12
12
  data.tar.gz: !binary |-
13
- Njc2OWNmNzFjMmFiMDczZTQ1ZmY1ZjFjMTQ0YmEzODRiZmViNThjM2ZiNDEw
14
- ODA2YTU2ZDRmNDJjZjNiMGVkN2VlNzFiNWU4ZWY4YmEyMjk5OGRmMmQ5NjAy
15
- ZTg2Y2ZlYmMzYzc1NDk2ZGZiZTk5MDVmZDg1ZWJlOWI2ZDgwNmM=
13
+ MzQyNGNmY2FjMjcwNDQyMTZhZjljZTU0ZWNkYzhhZWY5ZDhjNTgwM2QwZGRj
14
+ M2VjOWE2ZWNjZWRhMmY3ZjQyZGY5ODNlOWQxNzRlNmFmZjU1ZTRjOTY4ZWIz
15
+ YzNlY2I0NDBkNjQyNTU5NWRkZjE0YzAwODRkZmNhNjMwZTc1MTA=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- singularity_dsl (1.6.3)
4
+ singularity_dsl (2.0.0)
5
5
  coveralls (~> 0.7.9)
6
6
  json (~> 1.0)
7
7
  mixlib-shellout (~> 2.0)
@@ -18,7 +18,7 @@ GEM
18
18
  ast (2.0.0)
19
19
  astrolabe (1.3.0)
20
20
  parser (>= 2.2.0.pre.3, < 3.0)
21
- coveralls (0.7.10)
21
+ coveralls (0.7.11)
22
22
  multi_json (~> 1.10)
23
23
  rest-client (>= 1.6.8, < 2)
24
24
  simplecov (~> 0.9.1)
@@ -30,8 +30,8 @@ GEM
30
30
  json (1.8.2)
31
31
  mime-types (2.4.3)
32
32
  mixlib-shellout (2.0.1)
33
- multi_json (1.10.1)
34
- netrc (0.10.2)
33
+ multi_json (1.11.0)
34
+ netrc (0.10.3)
35
35
  parser (2.2.0.3)
36
36
  ast (>= 1.1, < 3.0)
37
37
  powerpack (0.1.0)
@@ -44,15 +44,15 @@ GEM
44
44
  rspec-core (~> 3.2.0)
45
45
  rspec-expectations (~> 3.2.0)
46
46
  rspec-mocks (~> 3.2.0)
47
- rspec-core (3.2.0)
47
+ rspec-core (3.2.1)
48
48
  rspec-support (~> 3.2.0)
49
49
  rspec-expectations (3.2.0)
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
51
  rspec-support (~> 3.2.0)
52
- rspec-mocks (3.2.0)
52
+ rspec-mocks (3.2.1)
53
53
  diff-lcs (>= 1.2.0, < 2.0)
54
54
  rspec-support (~> 3.2.0)
55
- rspec-support (3.2.1)
55
+ rspec-support (3.2.2)
56
56
  rubocop (0.29.1)
57
57
  astrolabe (~> 1.3)
58
58
  parser (>= 2.2.0.1, < 3.0)
@@ -69,7 +69,7 @@ GEM
69
69
  tins (~> 1.0)
70
70
  terminal-table (1.4.5)
71
71
  thor (0.19.1)
72
- tins (1.3.4)
72
+ tins (1.3.5)
73
73
 
74
74
  PLATFORMS
75
75
  ruby
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- require 'singularity_dsl/cli/cli'
4
+ require 'singularity_dsl/cli'
5
5
  SingularityDsl::Cli::Cli.start
@@ -45,7 +45,6 @@ module SingularityDsl
45
45
  end
46
46
 
47
47
  def change_list(list)
48
- list = list.split("\n") if list.is_a? String
49
48
  list = [*list]
50
49
  list.sort!
51
50
  @runner.dsl.changeset = list
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/application'
4
+ require 'singularity_dsl/cli/command/command'
5
+ require 'singularity_dsl/stdout'
6
+
7
+ module SingularityDsl
8
+ module Cli
9
+ module Command
10
+ # base command that runs application instances
11
+ class AppRunnerCommand < Command
12
+ include SingularityDsl::Stdout
13
+
14
+ def initialize_app
15
+ SingularityDsl::Application.new.tap do |app|
16
+ inject_flags app, user_flags
17
+ if tasks_path
18
+ info "Loading tasks from #{tasks_path}"
19
+ app.load_tasks tasks_path
20
+ end
21
+ info "Loading CI script from #{singularity_script} ..."
22
+ app.load_script singularity_script
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def user_flags
29
+ options[:flags] || []
30
+ end
31
+
32
+ def script
33
+ options[:script]
34
+ end
35
+
36
+ def script_path_exists?
37
+ !script.nil? && ::File.exist?(script)
38
+ end
39
+
40
+ def singularity_script
41
+ fail "Invalid script given: #{script}" unless script_path_exists?
42
+ ::File.expand_path script
43
+ end
44
+
45
+ def inject_flags(app, flags = [])
46
+ flags.each do |pair|
47
+ key = pair.split(':', 2).first
48
+ val = pair.split(':', 2).last
49
+ app.runner.dsl.flag key if key == val
50
+ app.runner.dsl.flag key, val unless key == val
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ module SingularityDsl
4
+ module Cli
5
+ module Command
6
+ # base command class
7
+ # options are just a hash
8
+ # (preferably passed in from Cli::Cli via Thor)
9
+ class Command
10
+ attr_reader :options
11
+
12
+ def initialize(opts = {})
13
+ @options = opts
14
+ end
15
+
16
+ def execute
17
+ fail 'cannot execute a base Command'
18
+ end
19
+
20
+ def tasks_path
21
+ return false unless task_path_exists
22
+ expanded_path
23
+ end
24
+
25
+ private
26
+
27
+ def given_path
28
+ options[:task_path]
29
+ end
30
+
31
+ def expanded_path
32
+ ::File.expand_path given_path
33
+ end
34
+
35
+ def task_path_exists
36
+ !given_path.nil? && ::File.exist?(given_path)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/command'
4
+ require 'singularity_dsl/dsl/dsl'
5
+ require 'singularity_dsl/stdout'
6
+
7
+ require 'rainbow'
8
+ require 'terminal-table'
9
+
10
+ module SingularityDsl
11
+ module Cli
12
+ module Command
13
+ # tasks command
14
+ # Prints out known tasks in the given task path
15
+ class Tasks < Command
16
+ include SingularityDsl::Stdout
17
+
18
+ def execute
19
+ dsl = SingularityDsl::Dsl::Dsl.new
20
+ dsl.load_tasks_in_path tasks_path if tasks_path
21
+ table = task_table
22
+ dsl.task_list.each do |task|
23
+ task_rows(dsl, task).each { |row| table.add_row row }
24
+ end
25
+ data table
26
+ end
27
+
28
+ private
29
+
30
+ def task_table
31
+ headers = [
32
+ Rainbow('Task').yellow,
33
+ Rainbow('Task Function').yellow,
34
+ Rainbow('Description').yellow
35
+ ]
36
+ table = ::Terminal::Table.new headings: headers
37
+ table.style = { border_x: '', border_y: '', border_i: '' }
38
+ table
39
+ end
40
+
41
+ def desc_rows(desc)
42
+ desc_lines = []
43
+ line = ''
44
+ desc.split(' ').each do |word|
45
+ if (line + word).length > 80
46
+ desc_lines.push line.strip
47
+ line = ''
48
+ end
49
+ line += " #{word}"
50
+ end
51
+ desc_lines.push line.strip
52
+ desc_lines
53
+ end
54
+
55
+ def task_rows(dsl, task_class)
56
+ desc_lines = desc_rows task_class.new.description
57
+ name = dsl.task_name task_class
58
+ task_name = dsl.task task_class
59
+ rows = [[name, task_name, desc_lines.shift]]
60
+ desc_lines.each { |line| rows.push ['', '', line] }
61
+ rows
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/app_runner_command'
4
+
5
+ module SingularityDsl
6
+ module Cli
7
+ module Command
8
+ # CLI test command - actually runs the entire application
9
+ # with or without a batch
10
+ class Test < AppRunnerCommand
11
+ def execute
12
+ app = initialize_app
13
+ # Exposes the app that is created so that child classes
14
+ # can perform injections / configurations on the fly
15
+ yield(app) if block_given?
16
+ exit(app.run batch, options[:all_tasks])
17
+ end
18
+
19
+ def batch
20
+ options[:batch] || false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/test'
4
+ require 'singularity_dsl/git_helper'
5
+
6
+ module SingularityDsl
7
+ module Cli
8
+ module Command
9
+ # testmerge command
10
+ # perform a merge, inject a changeset, run test command
11
+ class TestMerge < Test
12
+ attr_reader :git, :diff_list
13
+
14
+ def initialize(options)
15
+ super options
16
+ @diff_list = []
17
+ @git = SingularityDsl::GitHelper.new
18
+ @git.verbosity options[:verbose]
19
+ end
20
+
21
+ def perform_merge(git_fork, branch, base_branch, base_fork = nil)
22
+ git.merge_refs git_fork, branch, base_branch, base_fork
23
+ @diff_list += get_diff_list(base_branch, base_fork)
24
+ remove_remotes git_fork, base_fork
25
+ self
26
+ end
27
+
28
+ def execute
29
+ super { |app| inject_diff_list app }
30
+ end
31
+
32
+ def batch
33
+ target = options[:run_task]
34
+ target = false if target.nil? || target.strip.eql?('')
35
+ target
36
+ end
37
+
38
+ private
39
+
40
+ def inject_diff_list(app)
41
+ return if diff_list.empty?
42
+ info 'Running with diff-list'
43
+ list_items diff_list
44
+ app.change_list diff_list
45
+ end
46
+
47
+ def get_diff_list(ref, url)
48
+ git.diff_remote ref, url, '--name-only'
49
+ end
50
+
51
+ def remove_remotes(*urls)
52
+ urls.each { |url| git.remove_remote url }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/tasks'
4
+ require 'singularity_dsl/cli/command/test'
5
+ require 'singularity_dsl/cli/command/test_merge'
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command'
4
+ require 'singularity_dsl/version'
5
+
6
+ require 'thor'
7
+
8
+ module SingularityDsl
9
+ module Cli
10
+ # CLI (Thor) interface for CLI commands
11
+ class Cli < Thor
12
+ class_option :task_path,
13
+ aliases: '-t',
14
+ type: :string,
15
+ desc: 'Directory where custom tasks are defined',
16
+ default: './.singularity'
17
+ class_option :all_tasks,
18
+ aliases: '-a',
19
+ type: :boolean,
20
+ desc: 'Do not stop on task failure(s), collect all results'
21
+ class_option :script,
22
+ aliases: '-s',
23
+ type: :string,
24
+ desc: 'Specify path to a .singularityrc file',
25
+ default: './.singularityrc'
26
+ class_option :env,
27
+ type: :array,
28
+ desc: 'EnvVars to set, formatted as VAR:VAL'
29
+ class_option :verbose,
30
+ type: :boolean,
31
+ desc: 'Turn on verbose logging.'
32
+ class_option :flags,
33
+ type: :array,
34
+ desc: <<-EOD
35
+ Runtime flags to set for use with flag_set?, formatted as VAR:VAL
36
+ EOD
37
+
38
+ def initialize(*args)
39
+ super
40
+ env_vars(options[:env] || [])
41
+ end
42
+
43
+ map %w(--version -v) => :__print_version
44
+ desc '--version, -v', 'print the version'
45
+ def __print_version
46
+ puts "Singularity Runner & DSL v#{::SingularityDsl::VERSION}"
47
+ end
48
+
49
+ desc 'tasks', 'Available tasks.'
50
+ def tasks
51
+ Command::Tasks.new(options).execute
52
+ end
53
+
54
+ desc 'test', 'Run singularity script.'
55
+ def test
56
+ Command::Test.new(options).execute
57
+ end
58
+
59
+ desc 'batch BATCH_NAME',
60
+ 'Run single task batch in the .singularityrc script.'
61
+ def batch(batch)
62
+ Command::Test.new(options.merge(batch: batch).freeze).execute
63
+ end
64
+
65
+ desc 'testmerge FORK BRANCH INTO_BRANCH [INTO_FORK]',
66
+ 'Perform a testmerge into the local repo and then run .singularityrc'
67
+ option :run_task,
68
+ aliases: '-r',
69
+ type: :string,
70
+ desc: 'Run a batch instead, after testmerge.',
71
+ default: ''
72
+ def testmerge(git_fork, branch, base_branch, base_fork = nil)
73
+ Command::TestMerge.new(options)
74
+ .perform_merge(git_fork, branch, base_branch, base_fork)
75
+ .execute
76
+ end
77
+
78
+ private
79
+
80
+ def env_vars(vals)
81
+ vals.each do |pair|
82
+ key = pair.split(':', 2).first
83
+ val = pair.split(':', 2).last
84
+ ENV[key] = val
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -36,7 +36,7 @@ module SingularityDsl
36
36
  cmd = remote_cmd branch, url, "diff #{flags}"
37
37
  task = Mixlib::ShellOut.new cmd
38
38
  task.run_command
39
- task.stdout
39
+ task.stdout.split("\n").map(&:strip)
40
40
  end
41
41
 
42
42
  def add_remote(url)
@@ -6,12 +6,6 @@ require 'rake'
6
6
  class Rake < Task
7
7
  attr_accessor :target, :rake
8
8
 
9
- def initialize(&block)
10
- ::Rake.application.init
11
- @rake = ::Rake.application
12
- super(&block)
13
- end
14
-
15
9
  def target(target)
16
10
  @target = target
17
11
  @target.strip!
@@ -19,8 +13,10 @@ class Rake < Task
19
13
 
20
14
  def execute
21
15
  throw 'target is required' if @target.nil?
22
- @rake.load_rakefile
23
- ret = @rake[@target].invoke
16
+ ::Rake.application.init
17
+ rake = ::Rake.application
18
+ rake.load_rakefile
19
+ ret = rake[@target].invoke
24
20
  return ret.count if ret.is_a? Array
25
21
  ret
26
22
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version const for gem
4
4
  module SingularityDsl
5
- VERSION = '1.6.3'
5
+ VERSION = '2.0.0'
6
6
  end
@@ -1,27 +1,23 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'singularity_dsl/cli/cli'
3
+ require 'singularity_dsl/cli'
4
+ require 'singularity_dsl/cli/command'
4
5
 
5
6
  describe 'Cli' do
6
7
  let(:cli) { SingularityDsl::Cli::Cli.new }
7
8
 
8
- context '#testmerge' do
9
- before(:each) do
10
- expect(cli.git).to receive(:merge_refs)
11
- expect(cli).to receive(:diff_list)
12
- expect(cli).to receive(:remove_remotes)
13
- end
9
+ before :each do
10
+ @cmd_double = double
11
+ allow(@cmd_double).to receive :execute
12
+ end
14
13
 
15
- it 'runs test method if no run_task' do
16
- allow(cli).to receive(:target_run_task).and_return(false)
17
- expect(cli).to receive(:test)
18
- cli.testmerge 'fork', 'fork_branch', 'base_branch'
19
- end
14
+ describe '#batch' do
15
+ it 'injects batch name directly into options' do
16
+ expect(SingularityDsl::Cli::Command::Test).to receive(:new)
17
+ .with(hash_including('batch' => 'foo'))
18
+ .and_return(@cmd_double)
20
19
 
21
- it 'runs batch method if no run_task' do
22
- allow(cli).to receive(:target_run_task).and_return('test_batch')
23
- expect(cli).to receive(:batch)
24
- cli.testmerge 'fork', 'fork_branch', 'base_branch'
20
+ cli.batch 'foo'
25
21
  end
26
22
  end
27
23
  end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/app_runner_command'
4
+
5
+ describe SingularityDsl::Cli::Command::AppRunnerCommand do
6
+ let(:cmd) { SingularityDsl::Cli::Command::AppRunnerCommand.new }
7
+
8
+ describe '#initialize_app' do
9
+ context 'no script given' do
10
+ it 'fails' do
11
+ expect { cmd.initialize_app }.to raise_error(/Invalid script/)
12
+ end
13
+ end
14
+
15
+ context 'a script is given' do
16
+ let(:script) { 'path/to/a/singularity/script' }
17
+ let(:cfg) { { script: script } }
18
+ let(:cmd) do
19
+ SingularityDsl::Cli::Command::AppRunnerCommand.new cfg
20
+ end
21
+
22
+ context 'and it is an invalid path' do
23
+ before :each do
24
+ # TODO: this may be indicative of a must larger problem...
25
+ allow(::File).to receive(:exist?).and_return false
26
+ end
27
+
28
+ it 'fails' do
29
+ expect { cmd.initialize_app }.to raise_error(/Invalid script/)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/command'
4
+
5
+ describe SingularityDsl::Cli::Command::Command do
6
+ let(:cmd) { SingularityDsl::Cli::Command::Command.new }
7
+
8
+ describe '#initialize' do
9
+ it 'sets default options to {}' do
10
+ expect(cmd.options).to eql({})
11
+ end
12
+ end
13
+
14
+ describe '#execute' do
15
+ it 'fails' do
16
+ expect { cmd.execute }.to raise_error(/cannot execute/)
17
+ end
18
+ end
19
+
20
+ describe '#tasks_path' do
21
+ context 'no path given in options' do
22
+ it 'returns false' do
23
+ expect(cmd.tasks_path).to eql false
24
+ end
25
+ end
26
+
27
+ context 'path given in options' do
28
+ let(:file) { 'some/file/dir/path/thing/given' }
29
+ let(:cmd) { SingularityDsl::Cli::Command::Command.new task_path: file }
30
+
31
+ context 'and path exists' do
32
+ let(:expanded_file) { '/expanded/some/file/dir/path/thing/given' }
33
+ before :each do
34
+ allow(::File).to receive(:exist?)
35
+ .with(file).and_return true
36
+ allow(::File).to receive(:expand_path)
37
+ .with(file).and_return expanded_file
38
+ end
39
+
40
+ it 'returns expanded path' do
41
+ expect(cmd.tasks_path).to eql expanded_file
42
+ end
43
+ end
44
+
45
+ context 'and path does not exist' do
46
+ before :each do
47
+ allow(::File).to receive(:exist?)
48
+ .with(file).and_return false
49
+ end
50
+
51
+ it 'returns expanded path' do
52
+ expect(cmd.tasks_path).to eql false
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/tasks'
4
+
5
+ describe SingularityDsl::Cli::Command::Tasks do
6
+ describe '#execute' do
7
+ let(:cmd) { SingularityDsl::Cli::Command::Tasks.new }
8
+
9
+ it 'prints out a table of built-in tasks' do
10
+ # this is...kind of hard to test
11
+ expect(cmd).to receive(:data)
12
+ cmd.execute
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/test_merge'
4
+
5
+ describe SingularityDsl::Cli::Command::TestMerge do
6
+ describe '#batch' do
7
+ context ':run_task given' do
8
+ let(:cmd) { SingularityDsl::Cli::Command::TestMerge.new(run_task: 'foo') }
9
+
10
+ it 'returns batch' do
11
+ expect(cmd.batch).to eql 'foo'
12
+ end
13
+ end
14
+
15
+ context ':run_task not given' do
16
+ let(:cmd) { SingularityDsl::Cli::Command::TestMerge.new(run_task: '') }
17
+
18
+ it 'returns false when :run_task is an empty string' do
19
+ expect(cmd.batch).to eql false
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singularity_dsl/cli/command/test'
4
+
5
+ describe SingularityDsl::Cli::Command::Test do
6
+ describe '#batch' do
7
+ context ':batch given in options' do
8
+ let(:cmd) { SingularityDsl::Cli::Command::Test.new(batch: 'foo') }
9
+
10
+ it 'returns the given value' do
11
+ expect(cmd.batch).to eql 'foo'
12
+ end
13
+ end
14
+
15
+ context ':batch not given' do
16
+ let(:cmd) { SingularityDsl::Cli::Command::Test.new }
17
+
18
+ it 'returns the given value' do
19
+ expect(cmd.batch).to eql false
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singularity_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chr0n1x
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -184,9 +184,13 @@ files:
184
184
  - bin/singularity_runner
185
185
  - lib/singularity_dsl.rb
186
186
  - lib/singularity_dsl/application.rb
187
- - lib/singularity_dsl/cli/cli.rb
188
- - lib/singularity_dsl/cli/table.rb
189
- - lib/singularity_dsl/cli/utils.rb
187
+ - lib/singularity_dsl/cli.rb
188
+ - lib/singularity_dsl/cli/command.rb
189
+ - lib/singularity_dsl/cli/command/app_runner_command.rb
190
+ - lib/singularity_dsl/cli/command/command.rb
191
+ - lib/singularity_dsl/cli/command/tasks.rb
192
+ - lib/singularity_dsl/cli/command/test.rb
193
+ - lib/singularity_dsl/cli/command/test_merge.rb
190
194
  - lib/singularity_dsl/dsl/batch.rb
191
195
  - lib/singularity_dsl/dsl/changeset.rb
192
196
  - lib/singularity_dsl/dsl/components.rb
@@ -210,6 +214,11 @@ files:
210
214
  - singularity_dsl.gemspec
211
215
  - spec/singularity_dsl/application_spec.rb
212
216
  - spec/singularity_dsl/cli/cli_spec.rb
217
+ - spec/singularity_dsl/cli/command/app_runner_command_spec.rb
218
+ - spec/singularity_dsl/cli/command/command_spec.rb
219
+ - spec/singularity_dsl/cli/command/tasks_spec.rb
220
+ - spec/singularity_dsl/cli/command/test_merge_spec.rb
221
+ - spec/singularity_dsl/cli/command/test_spec.rb
213
222
  - spec/singularity_dsl/dsl/batch_spec.rb
214
223
  - spec/singularity_dsl/dsl/changeset_spec.rb
215
224
  - spec/singularity_dsl/dsl/dsl_spec.rb
@@ -251,6 +260,11 @@ summary: ''
251
260
  test_files:
252
261
  - spec/singularity_dsl/application_spec.rb
253
262
  - spec/singularity_dsl/cli/cli_spec.rb
263
+ - spec/singularity_dsl/cli/command/app_runner_command_spec.rb
264
+ - spec/singularity_dsl/cli/command/command_spec.rb
265
+ - spec/singularity_dsl/cli/command/tasks_spec.rb
266
+ - spec/singularity_dsl/cli/command/test_merge_spec.rb
267
+ - spec/singularity_dsl/cli/command/test_spec.rb
254
268
  - spec/singularity_dsl/dsl/batch_spec.rb
255
269
  - spec/singularity_dsl/dsl/changeset_spec.rb
256
270
  - spec/singularity_dsl/dsl/dsl_spec.rb
@@ -1,137 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'singularity_dsl/application'
4
- require 'singularity_dsl/cli/table'
5
- require 'singularity_dsl/cli/utils'
6
- require 'singularity_dsl/dsl/dsl'
7
- require 'singularity_dsl/errors'
8
- require 'singularity_dsl/git_helper'
9
- require 'singularity_dsl/version'
10
- require 'thor'
11
-
12
- module SingularityDsl
13
- # CLI
14
- module Cli
15
- # CLI Thor app
16
- class Cli < Thor
17
- include Errors
18
- include Table
19
- include Utils
20
-
21
- attr_reader :git
22
-
23
- def initialize(*args)
24
- super
25
- @diff_list = nil
26
- @git = GitHelper.new
27
- @git.verbosity options[:verbose]
28
- env_vars(options[:env] || [])
29
- end
30
-
31
- class_option :task_path,
32
- aliases: '-t',
33
- type: :string,
34
- desc: 'Directory where custom tasks are defined',
35
- default: './.singularity'
36
- class_option :all_tasks,
37
- aliases: '-a',
38
- type: :boolean,
39
- desc: 'Do not stop on task failure(s), collect all results'
40
- class_option :script,
41
- aliases: '-s',
42
- type: :string,
43
- desc: 'Specify path to a .singularityrc file',
44
- default: './.singularityrc'
45
- class_option :env,
46
- type: :array,
47
- desc: 'EnvVars to set, formatted as VAR:VAL'
48
- class_option :verbose,
49
- type: :boolean,
50
- desc: 'Turn on verbose logging.'
51
- class_option :flags,
52
- type: :array,
53
- desc: <<-EOD
54
- Runtime flags to set for use with flag_set?, formatted as VAR:VAL
55
- EOD
56
-
57
- map %w(--version -v) => :__print_version
58
- desc '--version, -v', 'print the version'
59
- def __print_version
60
- puts "Singularity Runner & DSL v#{SingularityDsl::VERSION}"
61
- end
62
-
63
- # TASKS COMMAND
64
- desc 'tasks', 'Available tasks.'
65
- def tasks
66
- dsl = Dsl::Dsl.new
67
- dsl.load_tasks_in_path tasks_path if ::File.exist? tasks_path
68
- table = task_table
69
- dsl.task_list.each do |task|
70
- task_rows(dsl, task).each { |row| table.add_row row }
71
- end
72
- puts table
73
- end
74
-
75
- # TEST COMMAND
76
- desc 'test', 'Run singularity script.'
77
- def test(app = nil)
78
- app ||= setup_app(Application.new,
79
- singularity_script,
80
- tasks_path,
81
- options[:flags] || [])
82
- exit(app.run false, options[:all_tasks])
83
- end
84
-
85
- # BATCH COMMAND
86
- desc 'batch BATCH_NAME',
87
- 'Run single task batch in the .singularityrc script.'
88
- def batch(batch, app = nil)
89
- app ||= setup_app(Application.new,
90
- singularity_script,
91
- tasks_path,
92
- options[:flags] || [])
93
- exit(app.run batch, options[:all_tasks])
94
- end
95
-
96
- # TEST-MERGE COMMAND
97
- desc 'testmerge FORK BRANCH INTO_BRANCH [INTO_FORK]',
98
- 'Perform a testmerge into the local repo and then run .singularityrc'
99
- option :run_task,
100
- aliases: '-r',
101
- type: :string,
102
- desc: 'Run a batch instead, after testmerge.',
103
- default: ''
104
- def testmerge(git_fork, branch, base_branch, base_fork = nil)
105
- @git.merge_refs git_fork, branch, base_branch, base_fork
106
- @diff_list = diff_list base_branch, base_fork
107
- remove_remotes git_fork, base_fork
108
- batch target_run_task if target_run_task
109
- test unless target_run_task
110
- end
111
-
112
- private
113
-
114
- def diff_list(ref, url)
115
- @git.diff_remote ref, url, '--name-only'
116
- end
117
-
118
- def remove_remotes(*urls)
119
- urls.each { |url| @git.remove_remote url }
120
- end
121
-
122
- def target_run_task
123
- target = options[:run_task]
124
- target = false if target.eql? ''
125
- target
126
- end
127
-
128
- def singularity_script
129
- File.expand_path options[:script]
130
- end
131
-
132
- def tasks_path
133
- File.expand_path options[:task_path]
134
- end
135
- end
136
- end
137
- end
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rainbow'
4
- require 'terminal-table'
5
-
6
- module SingularityDsl
7
- # CLI
8
- module Cli
9
- # util CLI table formatting fxs
10
- module Table
11
- private
12
-
13
- def task_rows(dsl, task_class)
14
- desc_lines = desc_rows task_class.new.description
15
- name = dsl.task_name task_class
16
- task_name = dsl.task task_class
17
- rows = [[name, task_name, desc_lines.shift]]
18
- desc_lines.each { |line| rows.push ['', '', line] }
19
- rows
20
- end
21
-
22
- def desc_rows(desc)
23
- desc_lines = []
24
- line = ''
25
- desc.split(' ').each do |word|
26
- if (line + word).length > 80
27
- desc_lines.push line.strip
28
- line = ''
29
- end
30
- line += " #{word}"
31
- end
32
- desc_lines.push line.strip
33
- desc_lines
34
- end
35
-
36
- def task_table
37
- headers = [
38
- Rainbow('Task').yellow,
39
- Rainbow('Task Function').yellow,
40
- Rainbow('Description').yellow
41
- ]
42
- table = Terminal::Table.new headings: headers
43
- table.style = { border_x: '', border_y: '', border_i: '' }
44
- table
45
- end
46
- end
47
- end
48
- end
@@ -1,54 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'singularity_dsl/stdout'
4
-
5
- module SingularityDsl
6
- # CLI
7
- module Cli
8
- # util functions
9
- module Utils
10
- include Stdout
11
-
12
- private
13
-
14
- def env_vars(vals)
15
- vals.each do |pair|
16
- key = pair.split(':', 2).first
17
- val = pair.split(':', 2).last
18
- ENV[key] = val
19
- end
20
- end
21
-
22
- def setup_app(app, singularity_script, tasks_path, flags = [])
23
- inject_flags app, flags
24
- inject_diff_list app
25
- if ::File.exist? tasks_path
26
- info "Loading tasks from #{tasks_path}"
27
- app.load_tasks tasks_path
28
- end
29
- info "Loading CI script from #{singularity_script} ..."
30
- app.load_script singularity_script
31
- app
32
- end
33
-
34
- def inject_flags(app, flags = [])
35
- flags.each do |pair|
36
- key = pair.split(':', 2).first
37
- val = pair.split(':', 2).last
38
- app.runner.dsl.flag key if key == val
39
- app.runner.dsl.flag key, val unless key == val
40
- end
41
- app
42
- end
43
-
44
- def inject_diff_list(app)
45
- unless @diff_list.nil?
46
- info 'Running with diff-list'
47
- list_items @diff_list
48
- app.change_list @diff_list
49
- end
50
- app
51
- end
52
- end
53
- end
54
- end