travis-extra 0.0.1

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: 4b7ffe710000c01322ea7b62fc2b33234ddeb49c
4
+ data.tar.gz: 1075a94e3b43fe72e1edcdc2c86afd7e90e06c11
5
+ SHA512:
6
+ metadata.gz: 54bd1e6e726c8d8503770cec5156dac23fc1d6b490048d7e3c4ea0c728ce34550514332c6c45b98f52f032af10bceef28a6f4ba9a8762f0618ffc7092aefb603
7
+ data.tar.gz: ca2c0aa1b70a2a357cb64842d7ffb2186f8e680e0b0d30220d6093082ff83329dff6f030f9c1500c3e7a2eb43555efd8f7999127add4f331be1d1fad2911f0dd
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Onni Hakala
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/Readme.md ADDED
@@ -0,0 +1,29 @@
1
+ # travis-extra
2
+
3
+ Helper script for doing more with Travis CI. It reads `.travis-extra.yml` file from current directory and exports environmental variables for your CI run.
4
+
5
+ ## Features
6
+ ### Add branch-specific env
7
+
8
+ This example `.travis-extra.yml`:
9
+ ```yaml
10
+ env:
11
+ branch:
12
+ master:
13
+ SOMEVAR=true
14
+ EXTRA_THING=taxi
15
+ ```
16
+
17
+ Will output these extra variables when `TRAVIS_BRANCH=master`.
18
+ ```bash
19
+ $ travis-extra --load-env
20
+ export SOMEVAR=true EXTRA_THING=taxi
21
+ ```
22
+
23
+ You can load them by running:
24
+ ```bash
25
+ $ eval $(travis-extra --load-env)
26
+ ```
27
+
28
+ ## License
29
+ MIT
data/bin/travis-extra ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'travis-extra/cli'
5
+ TravisExtra::CLI.run(ARGV)
@@ -0,0 +1,70 @@
1
+ require 'travis-extra/config'
2
+ require 'travis-extra/errors'
3
+ require 'travis-extra/environment'
4
+
5
+ module TravisExtra
6
+ class CLI
7
+ def self.run(*args)
8
+ new(args).run
9
+ end
10
+
11
+ OPTION_PATTERN = /\A--([a-z][a-z_\-]*)(?:=(.+))?\z/
12
+ attr_accessor :options, :fold_count
13
+
14
+ def initialize(*args)
15
+ options = {}
16
+ args.flatten.each do |arg|
17
+ next options.update(arg) if arg.is_a? Hash
18
+ die("invalid option %p" % arg) unless match = OPTION_PATTERN.match(arg)
19
+ key = match[1].tr('-', '_').to_sym
20
+ if options.include? key
21
+ options[key] = Array(options[key]) << match[2]
22
+ else
23
+ options[key] = match[2] || true
24
+ end
25
+ end
26
+
27
+ self.fold_count = 0
28
+ self.options = default_options.merge(options)
29
+ end
30
+
31
+ def run
32
+
33
+ begin
34
+ config = Config.parse
35
+ rescue ConfigNotFoundError => e
36
+ STDERR.puts "Error: #{e.message}"
37
+ exit 1
38
+ end
39
+
40
+ if options[:load_env]
41
+ if ENV['TRAVIS_BRANCH']
42
+ Environment.output(config['env'])
43
+ else
44
+ STDERR.puts "Error: TRAVIS_BRANCH is not set. Are you using this locally?"
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ def default_options
51
+ {
52
+ :app => File.basename(Dir.pwd),
53
+ :key_name => %x[hostname].strip
54
+ }
55
+ end
56
+
57
+ def shell(command)
58
+ system(command)
59
+ end
60
+
61
+ def die(message)
62
+ $stderr.puts(message)
63
+ exit 1
64
+ end
65
+
66
+ def env
67
+ ENV
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,16 @@
1
+ require 'yaml'
2
+
3
+ module TravisExtra
4
+ class Config
5
+ def self.parse(*args)
6
+ CONFIG_FILES.each do |file|
7
+ if File.exist?(file)
8
+ return YAML.load_file(file)
9
+ end
10
+ end
11
+ raise ConfigNotFoundError, "./.travis-extra.yml not found"
12
+ end
13
+
14
+ CONFIG_FILES=%w[ .travis-extra.yml, .travis-extra.yaml ]
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module TravisExtra
2
+ class Environment
3
+ attr_accessor :env
4
+
5
+ def self.output(config)
6
+ new(config).output
7
+ end
8
+
9
+ def initialize(config)
10
+ if config['branch'].key?(ENV['TRAVIS_BRANCH'])
11
+ @env = config['branch'][ENV['TRAVIS_BRANCH']]
12
+ end
13
+ end
14
+
15
+ def output
16
+ unless @env.empty?
17
+ puts "export " + @env.map{|k,v| "#{k}=#{v}"}.join(' ')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module TravisExtra
2
+ ConfigNotFoundError = Class.new(RuntimeError)
3
+ end
@@ -0,0 +1,3 @@
1
+ module TravisExtra
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,25 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "travis-extra/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "travis-extra"
6
+ s.version = TravisExtra::VERSION
7
+ s.author = "Onni Hakala"
8
+ s.email = "onni@keksi.io"
9
+ s.homepage = "https://github.com/onnimonni/travis-extra"
10
+ s.summary = %q{helper for travis ci}
11
+ s.description = %q{helper for travis ci which adds few extra abilities}
12
+ s.license = 'MIT'
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_path = 'lib'
17
+ s.required_ruby_version = '>= 1.9.3'
18
+
19
+ # prereleases from Travis CI
20
+ if ENV['CI']
21
+ digits = s.version.to_s.split '.'
22
+ digits[-1] = digits[-1].to_s.succ
23
+ s.version = digits.join('.') + ".travis.#{ENV['TRAVIS_JOB_NUMBER']}"
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: travis-extra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Onni Hakala
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: helper for travis ci which adds few extra abilities
14
+ email: onni@keksi.io
15
+ executables:
16
+ - travis-extra
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - LICENSE
22
+ - Readme.md
23
+ - bin/travis-extra
24
+ - lib/travis-extra/cli.rb
25
+ - lib/travis-extra/config.rb
26
+ - lib/travis-extra/environment.rb
27
+ - lib/travis-extra/errors.rb
28
+ - lib/travis-extra/version.rb
29
+ - travis-extra.gemspec
30
+ homepage: https://github.com/onnimonni/travis-extra
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.9.3
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.5.1
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: helper for travis ci
54
+ test_files: []