script-ci-lib 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.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in script-ci-lib.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ script-ci-lib (0.0.1)
5
+ methadone (~> 1.2.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aruba (0.5.0)
11
+ childprocess (= 0.2.3)
12
+ cucumber (>= 1.1.1)
13
+ ffi (>= 1.0.11)
14
+ rspec-expectations (>= 2.7.0)
15
+ builder (3.1.4)
16
+ childprocess (0.2.3)
17
+ ffi (~> 1.0.6)
18
+ cucumber (1.2.1)
19
+ builder (>= 2.1.2)
20
+ diff-lcs (>= 1.1.3)
21
+ gherkin (~> 2.11.0)
22
+ json (>= 1.4.6)
23
+ diff-lcs (1.1.3)
24
+ ffi (1.0.11)
25
+ gherkin (2.11.5)
26
+ json (>= 1.4.6)
27
+ json (1.7.5)
28
+ methadone (1.2.2)
29
+ bundler
30
+ rake (0.9.4)
31
+ rdoc (3.12)
32
+ json (~> 1.4)
33
+ rspec-expectations (2.12.0)
34
+ diff-lcs (~> 1.1.3)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ aruba
41
+ rake (~> 0.9.2)
42
+ rdoc
43
+ script-ci-lib!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Istvan Hoka
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Script::Ci::Lib
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'script-ci-lib'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install script-ci-lib
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = script-ci-lib - DESCRIBE YOUR GEM
2
+
3
+ Author:: YOUR NAME (YOUR EMAIL)
4
+ Copyright:: Copyright (c) 2012 YOUR NAME
5
+
6
+
7
+ DESCRIBE YOUR GEM HERE
8
+
9
+ == Links
10
+
11
+ * {Source on Github}[LINK TO GITHUB]
12
+ * RDoc[LINK TO RDOC.INFO]
13
+
14
+ == Install
15
+
16
+ == Examples
17
+
18
+ == Contributing
19
+
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ require 'rake/testtask'
30
+
31
+ require 'cucumber'
32
+ require 'cucumber/rake/task'
33
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
34
+ require 'rdoc/task'
35
+
36
+ include Rake::DSL
37
+
38
+ Bundler::GemHelper.install_tasks
39
+
40
+
41
+ Rake::TestTask.new do |t|
42
+ t.pattern = 'test/tc_*.rb'
43
+ end
44
+
45
+
46
+ CUKE_RESULTS = 'results.html'
47
+ CLEAN << CUKE_RESULTS
48
+ Cucumber::Rake::Task.new(:features) do |t|
49
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
50
+ t.fork = false
51
+ end
52
+
53
+ Rake::RDocTask.new do |rd|
54
+
55
+ rd.main = "README.rdoc"
56
+
57
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
58
+ end
59
+
60
+ task :default => [:test,:features]
61
+
data/bin/script-ci-lib ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'script-ci-lib'
6
+
7
+ class App
8
+ include Methadone::Main
9
+ include Methadone::CLILogging
10
+ include Methadone::SH
11
+
12
+ main do |script_dir|
13
+ destination_root = Pathname.new(script_dir)
14
+ destination_lib = destination_root.join('ci/lib')
15
+
16
+ exit_now!(1, "#{destination_root} is not a directory") unless destination_root.directory?
17
+
18
+ info "setting up in #{destination_root}"
19
+
20
+ source_dir = File.expand_path(File.dirname(__FILE__) + '/../lib/source')
21
+
22
+ destination_lib.mkpath
23
+
24
+ Dir["#{source_dir}/*"].each do |file|
25
+ destination = destination_lib.join(File.basename(file))
26
+ info "=> #{destination}"
27
+
28
+ sh! "cp -p #{file} #{destination}"
29
+ end
30
+
31
+
32
+ end
33
+
34
+ arg :script_dir, 'Where to put the CI lib files'
35
+
36
+ version ScriptCiLib::VERSION
37
+ use_log_level_option
38
+
39
+ go!
40
+ end
@@ -0,0 +1,12 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "script-ci-lib"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should document that this app takes options
11
+ And the following options should be documented:
12
+ |--version|
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end
@@ -0,0 +1,3 @@
1
+ module ScriptCiLib
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "script-ci-lib/version"
2
+
3
+ module ScriptCiLib
4
+ end
@@ -0,0 +1,95 @@
1
+ #!/bin/bash
2
+
3
+ function init_rvm {
4
+ if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
5
+ source "$HOME/.rvm/scripts/rvm"
6
+ elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
7
+ source "/usr/local/rvm/scripts/rvm"
8
+ else
9
+ printf "ERROR: An RVM installation was not found.\n"
10
+ fi
11
+
12
+ rvm use $CI_RUBY --create
13
+ }
14
+
15
+ function ci_env_run {
16
+ echo "~> running '$1'"
17
+ T="$(date +%s)"
18
+ RUBY_HEAP_MIN_SLOTS=1000000 RUBY_HEAP_SLOTS_INCREMENT=1000000 RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 RUBY_GC_MALLOC_LIMIT=100000000 RUBY_HEAP_FREE_MIN=50000 RUBY_FREE_MIN=50000 RAILS_ENV=$CI_ENV $1
19
+ exit_value=$?
20
+ T="$(($(date +%s)-T))"
21
+ echo "~> Time: ${T} seconds ($1)"
22
+ return $exit_value
23
+ }
24
+
25
+ function exit_on_error {
26
+ if [ ! $? -eq 0 ]; then
27
+ echo "~> running '$1' failed" 1>&2
28
+ exit 1
29
+ fi
30
+ }
31
+
32
+ function ci_env_run_err {
33
+ ci_env_run "$1"
34
+ exit_on_error "$1"
35
+ }
36
+
37
+ function run_cucumber_profile_with_rerun {
38
+ RERUN_TXT=tmp/rerun.txt
39
+ rm -f $RERUN_TXT
40
+ ci_env_run "bundler_stubs/cucumber features -p $1 --format rerun --out tmp/rerun.txt --format html --out=$(ci_reports_dir)/cucumber_$1.html --format junit --out=$(ci_reports_dir)/features-$1"
41
+ if [ ! $? -eq 0 ]; then
42
+ printf "~> Some features failed. Trying them again:\n"
43
+ cat $RERUN_TXT
44
+ printf "\n"
45
+
46
+ ci_env_run_err "bundler_stubs/cucumber @$RERUN_TXT -p $1 --format html --out=$(ci_reports_dir)/cucumber_rerun_$1.html --format junit --out=$(ci_reports_dir)/features-$1"
47
+ fi
48
+ }
49
+
50
+ function run_parallel_cucumber_with_rerun {
51
+ RERUN_TXT=tmp/rerun.txt
52
+ rm -f $RERUN_TXT
53
+ ci_env_run "bundler_stubs/parallel_cucumber features -n $CONCURRENCY -o '-p $1 --format rerun --out $(ci_reports_dir)/rerun_\\\$TEST_ENV_NUMBER.txt --format progress --format html --out $(ci_reports_dir)/cucumber_$1_\\\$TEST_ENV_NUMBER.html --format junit --out $(ci_reports_dir)'"
54
+ if [ ! $? -eq 0 ]; then
55
+ printf "~> Some features failed. Trying them again:\n"
56
+
57
+ # Join all reruns into one file
58
+ find $(ci_reports_dir) -type f -iname 'rerun_*.txt' -exec cat {} \; -exec echo " " \; > $RERUN_TXT
59
+
60
+ printf "\n"
61
+
62
+ ci_env_run_err "bundler_stubs/cucumber @$RERUN_TXT -p $1 --format html --out $(ci_reports_dir)/cucumber_$1_rerun.html --format junit --out $(ci_reports_dir)"
63
+ fi
64
+ }
65
+
66
+ function run_parallel_rspec {
67
+ ci_env_run_err "bundler_stubs/parallel_rspec spec -n $CONCURRENCY -o '--format progress --format html --out $(ci_reports_dir)/rspec\\\$TEST_ENV_NUMBER.html --format JUnitFormatter --out $(ci_reports_dir)/rspec\\\$TEST_ENV_NUMBER.xml'"
68
+ }
69
+
70
+ function run_parallel_rspec_v1 {
71
+ ci_env_run_err "bundler_stubs/parallel_rspec spec -n $CONCURRENCY -o '--format progress --format html:$(ci_reports_dir)/rspec\\\$TEST_ENV_NUMBER.html'"
72
+ }
73
+
74
+ function ci_build_dir {
75
+ echo "$JENKINS_HOME/jobs/$JOB_NAME/builds"
76
+ }
77
+
78
+ function ci_reports_dir {
79
+ echo "tmp/reports"
80
+ }
81
+
82
+ function ci_env_hash {
83
+ if [ -z "$CI_ENV" ] ; then
84
+ CI_ENV="test"
85
+ else
86
+ CI_ENV=$(echo $CI_ENV | md5sum | awk '{print $1}')
87
+ fi
88
+ echo $CI_ENV
89
+ }
90
+
91
+ function setup_ci_vars {
92
+ export JENKINS_HOME=${JENKINS_HOME:-"tmp"}
93
+ export CI_ENV=$(ci_env_hash)
94
+ export CONCURRENCY=${CONCURRENCY:-"4"}
95
+ }
@@ -0,0 +1,98 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+
4
+ module CI
5
+ # Helper for setting up environment dependent config files for CI.
6
+ # It expects to find ERB templates for config files in rails-root/config/ci/
7
+ # which it renders with the rails_root and ci_env variables.
8
+ class ConfigHelper
9
+ attr_reader :rails_root, :ci_env
10
+
11
+ DEFAULT_CONFIG_PATHS = %W[
12
+ config/environments/test.rb
13
+ ]
14
+
15
+ def self.setup!(rails_root, ci_env, config_paths=DEFAULT_CONFIG_PATHS)
16
+ new(rails_root, ci_env, config_paths).setup!
17
+ end
18
+
19
+ class ConfigTemplate
20
+ include ERB::Util
21
+
22
+ def initialize(template, options={})
23
+ options.each do |k, v|
24
+ instance_variable_set("@#{k}", v)
25
+ end
26
+ @erb = ERB.new(File.read(template))
27
+ end
28
+
29
+ def render
30
+ @erb.result(binding)
31
+ end
32
+
33
+ def to_s
34
+ render
35
+ end
36
+ end
37
+
38
+ def initialize(rails_root, ci_env, config_paths)
39
+ @rails_root = rails_root
40
+ @ci_env = ci_env
41
+ @config_paths = config_paths
42
+ end
43
+
44
+ def setup!
45
+ setup_configs!
46
+ setup_environment!
47
+ end
48
+
49
+ def setup_environment!
50
+ return if 'test' == ci_env
51
+
52
+ @config_paths.each do |path|
53
+ test_config = File.join(rails_root, path)
54
+ env_config = destination_config_path(path)
55
+ FileUtils.ln_s(test_config, env_config)
56
+ end
57
+
58
+ end
59
+
60
+ def setup_configs!
61
+ find_config_templates.each do |template|
62
+ result = ConfigTemplate.new(template, config_template_options)
63
+
64
+ File.open(destination_config(template), 'w') do |f|
65
+ f.write(result)
66
+ end
67
+ end
68
+ end
69
+
70
+ private
71
+ def destination_config_path(path)
72
+ source = File.expand_path File.join(rails_root, path)
73
+ name = if File.directory?(source)
74
+ ci_env
75
+ else
76
+ ext = File.extname(path)
77
+ "#{ci_env}#{ext}"
78
+ end
79
+
80
+ File.join(File.dirname(source), name)
81
+ end
82
+
83
+ def destination_config(template)
84
+ File.join(rails_root, 'config', File.basename(template).gsub(/\.erb$/, ''))
85
+ end
86
+
87
+ def find_config_templates
88
+ Dir[rails_root + '/config/ci/*.erb']
89
+ end
90
+
91
+ def config_template_options
92
+ {
93
+ :rails_root => rails_root,
94
+ :ci_env => ci_env
95
+ }
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'script-ci-lib/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "script-ci-lib"
8
+ gem.version = ScriptCiLib::VERSION
9
+ gem.authors = ["Istvan Hoka"]
10
+ gem.email = ["istvan@2xwide.com"]
11
+ gem.description = %q{CI library scripts}
12
+ gem.summary = %q{Bootstrap your Rails project with CI scripts to run on Jenkins}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_development_dependency('rdoc')
20
+ gem.add_development_dependency('aruba')
21
+ gem.add_development_dependency('rake', '~> 0.9.2')
22
+ gem.add_dependency('methadone', '~> 1.2.2')
23
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ class TestSomething < Test::Unit::TestCase
4
+ def test_truth
5
+ assert true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: script-ci-lib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Istvan Hoka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: aruba
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: methadone
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.2.2
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.2.2
78
+ description: CI library scripts
79
+ email:
80
+ - istvan@2xwide.com
81
+ executables:
82
+ - script-ci-lib
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - LICENSE.txt
89
+ - README.md
90
+ - README.rdoc
91
+ - Rakefile
92
+ - bin/script-ci-lib
93
+ - features/script-ci-lib.feature
94
+ - features/step_definitions/script-ci-lib_steps.rb
95
+ - features/support/env.rb
96
+ - lib/script-ci-lib.rb
97
+ - lib/script-ci-lib/version.rb
98
+ - lib/source/functions
99
+ - lib/source/helpers.rb
100
+ - script-ci-lib.gemspec
101
+ - test/tc_something.rb
102
+ homepage: ''
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
115
+ - 0
116
+ hash: -1007016498664484188
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: -1007016498664484188
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.24
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Bootstrap your Rails project with CI scripts to run on Jenkins
132
+ test_files:
133
+ - features/script-ci-lib.feature
134
+ - features/step_definitions/script-ci-lib_steps.rb
135
+ - features/support/env.rb
136
+ - test/tc_something.rb