travish 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +15 -0
- data/VERSION +1 -1
- data/lib/environment_parser.rb +75 -0
- data/lib/travish.rb +25 -21
- data/spec/environment_parser_spec.rb +48 -0
- data/spec/spec_helper.rb +1 -0
- data/travish.gemspec +9 -5
- metadata +19 -4
- data/test/helper.rb +0 -34
- data/test/test_travish.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c366abeba5827d1aebfcd355aef252f83182b168
|
4
|
+
data.tar.gz: bba5edc2c510e5285ceeb08589bfce8c030bf4df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 601836afba0897ae33cebbb573b6f29cce17b8c749ea34921a1202e6dffde3d833b0452cf708161a8e7b67691dedb56fb6f6a2baf28b3c1630e3ebab330dbba6
|
7
|
+
data.tar.gz: d6b874ddd50cf66eb78aa9d5e4c2a91e93b162530bffd202af5ca8e4300946144d2568cd7f1c688dcabbe17ee40232c534c1faf658cad2bb6c137beb0fb0960b
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -11,6 +11,7 @@ GEM
|
|
11
11
|
builder (3.2.2)
|
12
12
|
descendants_tracker (0.0.4)
|
13
13
|
thread_safe (~> 0.3, >= 0.3.1)
|
14
|
+
diff-lcs (1.2.5)
|
14
15
|
docile (1.1.5)
|
15
16
|
faraday (0.9.1)
|
16
17
|
multipart-post (>= 1.2, < 3)
|
@@ -54,6 +55,19 @@ GEM
|
|
54
55
|
rake (10.4.2)
|
55
56
|
rdoc (3.12.2)
|
56
57
|
json (~> 1.4)
|
58
|
+
rspec (3.2.0)
|
59
|
+
rspec-core (~> 3.2.0)
|
60
|
+
rspec-expectations (~> 3.2.0)
|
61
|
+
rspec-mocks (~> 3.2.0)
|
62
|
+
rspec-core (3.2.2)
|
63
|
+
rspec-support (~> 3.2.0)
|
64
|
+
rspec-expectations (3.2.0)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.2.0)
|
67
|
+
rspec-mocks (3.2.1)
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
+
rspec-support (~> 3.2.0)
|
70
|
+
rspec-support (3.2.2)
|
57
71
|
shoulda (3.5.0)
|
58
72
|
shoulda-context (~> 1.0, >= 1.0.1)
|
59
73
|
shoulda-matchers (>= 1.4.1, < 3.0)
|
@@ -76,5 +90,6 @@ DEPENDENCIES
|
|
76
90
|
bundler (~> 1.0)
|
77
91
|
jeweler (~> 2.0.1)
|
78
92
|
rdoc (~> 3.12)
|
93
|
+
rspec (~> 3.2.0)
|
79
94
|
shoulda
|
80
95
|
simplecov
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Travish
|
2
|
+
# Handles parsing the environment from a .travis.yml file
|
3
|
+
# and merging it with overrides from other source such as
|
4
|
+
# ENV
|
5
|
+
class EnvironmentParser
|
6
|
+
STRING_REG_EX = /^(.+)="?(.+?)"?$/
|
7
|
+
|
8
|
+
attr_accessor :environment_hash
|
9
|
+
|
10
|
+
# Create a new instance of `EnvironmentParser`
|
11
|
+
def initialize(env, *args)
|
12
|
+
@env = env
|
13
|
+
@env = [@env] if @env.is_a? String
|
14
|
+
@override_envs = args
|
15
|
+
@override_envs ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
# The resulting environment hash after merging
|
19
|
+
# the environment from the travis file with
|
20
|
+
# the specified overrides. This method is lazy
|
21
|
+
# and calculates its result on the first call
|
22
|
+
def environment_hash
|
23
|
+
@environment_hash ||= build_environment_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Build the environment hash by extracting the environment
|
29
|
+
# variables from the provided travis environment and merging
|
30
|
+
# with any provided overrides
|
31
|
+
def build_environment_hash
|
32
|
+
parsed_variables = {}
|
33
|
+
@env.each do |env_row|
|
34
|
+
# Each row can potentially contain multiple environment
|
35
|
+
# variables
|
36
|
+
variables = extract_variables(env_row)
|
37
|
+
|
38
|
+
variables.each do |variables_with_values|
|
39
|
+
variables_with_values.each do |key, value|
|
40
|
+
parsed_variables[key] = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
@override_envs.each do |env|
|
46
|
+
parsed_variables = parsed_variables.merge env
|
47
|
+
end
|
48
|
+
|
49
|
+
parsed_variables
|
50
|
+
end
|
51
|
+
|
52
|
+
# Extract environment variables from a value
|
53
|
+
# The value is expected to be either a hash or a string with
|
54
|
+
# one or more key value pairs on the form
|
55
|
+
# KEY=VALUE
|
56
|
+
def extract_variables(variable)
|
57
|
+
return [variable] if variable.is_a? Hash
|
58
|
+
return extract_variables_from_string(variable) if variable.is_a? String
|
59
|
+
|
60
|
+
[]
|
61
|
+
end
|
62
|
+
|
63
|
+
# Extract variables from a string on the form
|
64
|
+
# KEY1=VALUE1 KEY2="VALUE2"
|
65
|
+
# Optional quoting around the value is allowed
|
66
|
+
def extract_variables_from_string(string)
|
67
|
+
string.split(/ /).map do |defintion|
|
68
|
+
match = defintion.match STRING_REG_EX
|
69
|
+
next nil unless match
|
70
|
+
|
71
|
+
{ match[1] => match[2] }
|
72
|
+
end.reject(&:nil?)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/travish.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require 'yaml'
|
3
|
+
require 'environment_parser'
|
3
4
|
|
4
5
|
module Travish
|
5
6
|
class Runner
|
6
|
-
|
7
|
+
|
7
8
|
def help
|
8
9
|
puts ""
|
9
10
|
puts "Travish - emulates the OSX experience for travis."
|
@@ -12,52 +13,55 @@ module Travish
|
|
12
13
|
puts ""
|
13
14
|
puts " ./"
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
def run
|
17
18
|
validate
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
run_commands
|
22
|
-
run_commands
|
23
|
-
run_commands
|
24
|
-
|
25
|
-
|
19
|
+
travis_file = default_yml.merge local_travis_yml
|
20
|
+
parser = EnvironmentParser.new(travis_file['env']['global'], ENV)
|
21
|
+
|
22
|
+
run_commands(travis_file["before_install"], parser.environment_hash)
|
23
|
+
run_commands(travis_file["install"], parser.environment_hash)
|
24
|
+
run_commands(travis_file["before_script"], parser.environment_hash)
|
25
|
+
run_commands(travis_file["script"], parser.environment_hash)
|
26
|
+
end
|
27
|
+
|
26
28
|
# -- faffing
|
27
|
-
|
29
|
+
|
28
30
|
def initialize(args)
|
29
31
|
# find a command
|
30
32
|
@params = args
|
31
33
|
command = @params[0].to_sym rescue :help
|
32
34
|
commands.include?(command) ? send(command.to_sym) : help
|
33
35
|
end
|
34
|
-
|
36
|
+
|
35
37
|
private
|
36
|
-
|
37
|
-
def run_commands
|
38
|
+
|
39
|
+
def run_commands(array, environment = {})
|
40
|
+
return if array.nil?
|
41
|
+
array = [array] if array.is_a?(String)
|
38
42
|
array.each do |command|
|
39
|
-
|
43
|
+
puts "> " + command
|
44
|
+
system(environment, command)
|
40
45
|
end
|
41
46
|
end
|
42
|
-
|
47
|
+
|
43
48
|
def local_travis_yml
|
44
49
|
YAML.load_file('.travis.yml')
|
45
50
|
end
|
46
|
-
|
51
|
+
|
47
52
|
def default_yml
|
48
53
|
{}
|
49
54
|
end
|
50
|
-
|
55
|
+
|
51
56
|
def validate
|
52
57
|
unless File.exists? ".travis.yml"
|
53
58
|
puts "You need to have a `travis.yml` in this folder."
|
54
59
|
exit
|
55
60
|
end
|
56
61
|
end
|
57
|
-
|
62
|
+
|
58
63
|
def commands
|
59
64
|
(public_methods - Object.public_methods).sort.map{ |c| c.to_sym }
|
60
65
|
end
|
61
|
-
|
62
|
-
end
|
66
|
+
end
|
63
67
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/environment_parser.rb'
|
3
|
+
|
4
|
+
module Travish
|
5
|
+
RSpec.describe EnvironmentParser do
|
6
|
+
describe '.environment_hash' do
|
7
|
+
let(:global_env) do
|
8
|
+
[
|
9
|
+
'KEY1=VALUE1 KEY2=VALUE2',
|
10
|
+
{ 'KEY3' => 'VALUE3' },
|
11
|
+
'KEY_WITH_QUOTED_VALUE="QUOTED"'
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:overrides) do
|
16
|
+
[
|
17
|
+
{ 'KEY1' => 'V1', 'KEY2' => 'V2', 'KEY3' => 'not V3' },
|
18
|
+
{ 'KEY3' => 'V3' }
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'produces the correct result without overrides' do
|
23
|
+
parser = described_class.new(global_env)
|
24
|
+
hash = parser.environment_hash
|
25
|
+
|
26
|
+
expect(hash).to eq('KEY1' => 'VALUE1',
|
27
|
+
'KEY2' => 'VALUE2',
|
28
|
+
'KEY3' => 'VALUE3',
|
29
|
+
'KEY_WITH_QUOTED_VALUE' => 'QUOTED')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'produces the corect result with overrides' do
|
33
|
+
parser = described_class.new(global_env, *overrides)
|
34
|
+
hash = parser.environment_hash
|
35
|
+
|
36
|
+
expect(hash).to eq('KEY1' => 'V1', 'KEY2' => 'V2',
|
37
|
+
'KEY3' => 'V3', 'KEY_WITH_QUOTED_VALUE' => 'QUOTED')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'produces the correct result with a single string as the environment' do
|
41
|
+
parser = described_class.new('KEY=VALUE OTHER_KEY="OTHER_VALUE"')
|
42
|
+
hash = parser.environment_hash
|
43
|
+
|
44
|
+
expect(hash).to eq('KEY' => 'VALUE', 'OTHER_KEY' => 'OTHER_VALUE')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rspec'
|
data/travish.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: travish 0.0
|
5
|
+
# stub: travish 0.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "travish"
|
9
|
-
s.version = "0.0
|
9
|
+
s.version = "0.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Orta Therox"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-04-07"
|
15
15
|
s.description = " Emulates a tiny subset of the travis workflow for running your own CI based on the .travis.yml "
|
16
16
|
s.email = "orta.therox@gmail.com"
|
17
17
|
s.executables = ["travish"]
|
@@ -28,9 +28,10 @@ Gem::Specification.new do |s|
|
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION",
|
30
30
|
"bin/travish",
|
31
|
+
"lib/environment_parser.rb",
|
31
32
|
"lib/travish.rb",
|
32
|
-
"
|
33
|
-
"
|
33
|
+
"spec/environment_parser_spec.rb",
|
34
|
+
"spec/spec_helper.rb",
|
34
35
|
"travish.gemspec"
|
35
36
|
]
|
36
37
|
s.homepage = "http://github.com/orta/travish"
|
@@ -47,12 +48,14 @@ Gem::Specification.new do |s|
|
|
47
48
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
48
49
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
49
50
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.2.0"])
|
50
52
|
else
|
51
53
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
52
54
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
53
55
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
54
56
|
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
55
57
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rspec>, ["~> 3.2.0"])
|
56
59
|
end
|
57
60
|
else
|
58
61
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
@@ -60,6 +63,7 @@ Gem::Specification.new do |s|
|
|
60
63
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
61
64
|
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
62
65
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 3.2.0"])
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: travish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orta Therox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.2.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.2.0
|
83
97
|
description: " Emulates a tiny subset of the travis workflow for running your own
|
84
98
|
CI based on the .travis.yml "
|
85
99
|
email: orta.therox@gmail.com
|
@@ -98,9 +112,10 @@ files:
|
|
98
112
|
- Rakefile
|
99
113
|
- VERSION
|
100
114
|
- bin/travish
|
115
|
+
- lib/environment_parser.rb
|
101
116
|
- lib/travish.rb
|
102
|
-
-
|
103
|
-
-
|
117
|
+
- spec/environment_parser_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
104
119
|
- travish.gemspec
|
105
120
|
homepage: http://github.com/orta/travish
|
106
121
|
licenses:
|
data/test/helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
|
3
|
-
module SimpleCov::Configuration
|
4
|
-
def clean_filters
|
5
|
-
@filters = []
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
SimpleCov.configure do
|
10
|
-
clean_filters
|
11
|
-
load_adapter 'test_frameworks'
|
12
|
-
end
|
13
|
-
|
14
|
-
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
-
add_filter "/.rvm/"
|
16
|
-
end
|
17
|
-
require 'rubygems'
|
18
|
-
require 'bundler'
|
19
|
-
begin
|
20
|
-
Bundler.setup(:default, :development)
|
21
|
-
rescue Bundler::BundlerError => e
|
22
|
-
$stderr.puts e.message
|
23
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
-
exit e.status_code
|
25
|
-
end
|
26
|
-
require 'test/unit'
|
27
|
-
require 'shoulda'
|
28
|
-
|
29
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
30
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
|
-
require 'travish'
|
32
|
-
|
33
|
-
class Test::Unit::TestCase
|
34
|
-
end
|