tod-travis 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86f58e51ec504a8404842bb71b6fad1824df4de2
4
+ data.tar.gz: 8bf17acc804c262a3bf16b05ab80b3b8005d2281
5
+ SHA512:
6
+ metadata.gz: 319989208dccf8f18f80a6f6ca87c50d1975673b4a8baeccfa49637711c628b269914a50e706287442e75677d21fda382f29b6d705525045f92d9d6bbd177c3f
7
+ data.tar.gz: e09771e194512d1fa734c6cce63a188ad46c97ac3e05ae80fcb8bcdcdaa1d416628429f133b3f3727a0c25f24fa4af62e293d041b42f3e14c1cef2b5aa770c4b
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ sudo: required
2
+ language: ruby
3
+
4
+ services:
5
+ - docker
6
+
7
+ before_script:
8
+ - docker build -t tod .
9
+
10
+ script:
11
+ - docker run -v $(pwd):/tod -it tod rspec
data/Dockerfile ADDED
@@ -0,0 +1,10 @@
1
+ FROM ruby:2.3.1
2
+
3
+ RUN mkdir -p /tod
4
+ WORKDIR /tod
5
+
6
+ COPY . /tod
7
+
8
+ RUN bundle install
9
+
10
+ CMD irb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tod.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright © 2016 Maciej Komorowski <mckomo@gmail.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the “Software”), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Tod
2
+
3
+ Tod runs commands from your `.travis.yml` file. Type `tod` instead of `docker run -v $(pwd):/my-app -it my-app some-tests` to run your tests
4
+
5
+ ## Installation
6
+
7
+ Install it yourself simply as:
8
+
9
+ ```bash
10
+ $ gem install tod
11
+ ```
12
+
13
+ Check the installation with following:
14
+
15
+ ```bash
16
+ $ which tod
17
+ /path/to/tod
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ #### tod
23
+
24
+ Runs scripts from the `script` section.
25
+
26
+ ```bash
27
+ tod # or tod script
28
+ ```
29
+
30
+ #### tod before
31
+
32
+ Runs scripts from the `before_script` section.
33
+
34
+ ```bash
35
+ tod before
36
+ ```
37
+
38
+ #### tod setup
39
+
40
+ Runs scripts from the `before_install` section.
41
+
42
+ ```bash
43
+ tod setup
44
+ ```
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/mckomo/tod](https://github.com/mckomo/tod). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/TODO.md ADDED
@@ -0,0 +1,4 @@
1
+ # TODO
2
+
3
+ * Use stdout and stderr streams to print intermediate output
4
+ * Enable adding surfix to the command execution e.g. `tod script spec/module_spec.rb`
data/exe/tod ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'clamp'
4
+ require 'tod'
5
+
6
+ Clamp do
7
+
8
+ SECTIONS = ['setup', 'before', 'script']
9
+
10
+ option ['-p', '--path'], 'PATH', 'Path to .travis.yml', :default => '.travis.yml'
11
+
12
+ parameter '[SECTION]', 'section from .travis.yml to execute', :default => :script do |section|
13
+ unless SECTIONS.include? section
14
+ raise ArgumentError.new "Try #{SECTIONS * ', '}."
15
+ end
16
+
17
+ section.to_sym
18
+ end
19
+
20
+ def execute
21
+ runner = Tod.build(from_yml: path)
22
+ code = runner.run(section)
23
+
24
+ exit code
25
+ end
26
+
27
+ end
@@ -0,0 +1,15 @@
1
+ module Tod
2
+ class Executor
3
+
4
+ def execute(command)
5
+ f = IO.popen(command)
6
+
7
+ output = f.readlines
8
+ f.close
9
+ code = $?.exitstatus
10
+
11
+ Result.new(code, output)
12
+ end
13
+
14
+ end
15
+ end
data/lib/tod/result.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Tod
2
+ class Result
3
+
4
+ attr_reader :code, :output
5
+
6
+ def initialize(code, output = '')
7
+ @code, @output = code, output
8
+ end
9
+
10
+ def ok?
11
+ code.zero?
12
+ end
13
+
14
+ def error?
15
+ !ok?
16
+ end
17
+
18
+ end
19
+ end
data/lib/tod/runner.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'open3'
2
+
3
+ module Tod
4
+ class Runner
5
+
6
+ def initialize(travis, executor: Executor.new, environment: ENV)
7
+ @travis = travis
8
+ @executor = executor
9
+ @environment = environment
10
+ end
11
+
12
+ def run(section)
13
+
14
+ setup_env
15
+
16
+ @travis.section(section).each do |command|
17
+
18
+ result = @executor.execute(command)
19
+
20
+ puts result.output unless result.output.empty?
21
+
22
+ if result.error?
23
+ return result.code
24
+ end
25
+
26
+ end
27
+
28
+ result_code = 0
29
+
30
+ end
31
+
32
+ private
33
+
34
+ def setup_env
35
+ @travis.env.each do |key, val|
36
+ @environment.store(key.to_s, val.to_s)
37
+ end
38
+ end
39
+
40
+ end
41
+ end
data/lib/tod/travis.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'yaml'
2
+ require 'active_support/hash_with_indifferent_access'
3
+
4
+ module Tod
5
+
6
+ class Travis
7
+
8
+ def initialize(yml = {})
9
+ @yml = yml.symbolize_keys
10
+ end
11
+
12
+ def env
13
+ Hash(@yml[:env]) || {}
14
+ end
15
+
16
+ def script
17
+ Array(@yml[:script]) || []
18
+ end
19
+
20
+ def before
21
+ Array(@yml[:before_script]) || []
22
+ end
23
+
24
+ def setup
25
+ Array(@yml[:before_install]) || []
26
+ end
27
+
28
+ def section(section)
29
+ send(section.to_sym)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Tod
2
+ VERSION = [0, 1, 0].join('.')
3
+ end
data/lib/tod.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'yaml'
2
+
3
+ require 'tod/version'
4
+ require 'tod/travis'
5
+ require 'tod/result'
6
+ require 'tod/executor'
7
+ require 'tod/runner'
8
+ require 'tod/runner'
9
+
10
+
11
+ module Tod
12
+
13
+ def self.build(from_yml: '.travis.yml')
14
+ yaml = YAML.load_file(from_yml)
15
+ travis = Travis.new(yaml)
16
+ Runner.new(travis)
17
+ end
18
+
19
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tod/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tod-travis"
8
+ spec.version = Tod::VERSION
9
+ spec.authors = ["mckomo"]
10
+ spec.email = ["mckomo@gmail.com"]
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = "Run travis.yml in your terminal"
14
+ spec.description = %q{Helper utility to run scripts from .travis.yml file}
15
+ spec.homepage = "http://mckomo.github.io"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "activesupport", "~> 5.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "mocha", "~> 1.1"
28
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tod-travis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mckomo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ description: Helper utility to run scripts from .travis.yml file
84
+ email:
85
+ - mckomo@gmail.com
86
+ executables:
87
+ - tod
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Dockerfile
95
+ - Gemfile
96
+ - LICENSE
97
+ - README.md
98
+ - TODO.md
99
+ - exe/tod
100
+ - lib/tod.rb
101
+ - lib/tod/executor.rb
102
+ - lib/tod/result.rb
103
+ - lib/tod/runner.rb
104
+ - lib/tod/travis.rb
105
+ - lib/tod/version.rb
106
+ - tod-travis.gemspec
107
+ homepage: http://mckomo.github.io
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Run travis.yml in your terminal
131
+ test_files: []