ci_config_generator 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.
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/tmp
16
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ci_config.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tim Fischbach
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.
@@ -0,0 +1,40 @@
1
+ # CI Config Generator
2
+
3
+ [github.com/codevise/ci_config_generator](http://github.com/codevise/ci_config_generator)
4
+
5
+ Generate config files for continuous integration from templates inside
6
+ the repository.
7
+
8
+ ## Usage
9
+
10
+ Require generator tasks inside your `Rakefile`:
11
+
12
+ # Rakefile
13
+ require 'ci_config_generator/tasks'
14
+
15
+ Given `config/database.yml` is an ignored file, commit a
16
+ `config/database.yml.ci` file and invoke
17
+
18
+ $ rake ci:config:generate
19
+
20
+ in continuous integration. The task generates a `config/database.yml`
21
+ and interpolates environment variables:
22
+
23
+ # config/database.yml.ci
24
+ test:
25
+ db: "%{DB_NAME}"
26
+
27
+ $ rake ci:config:generate DB_NAME=test_db
28
+
29
+ # config/databse.yml
30
+ test:
31
+ db: "test_db"
32
+
33
+ The task fails if files would be overriden. So make sure to clean your
34
+ repository on each ci run.
35
+
36
+ ## License
37
+
38
+ Please fork and improve.
39
+
40
+ Copyright (c) 2013 Codevise Solutions Ltd. This software is licensed under the MIT License.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ci_config_generator/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Tim Fischbach"]
6
+ gem.email = ["tfischbach@codevise.de"]
7
+ gem.description = %q{Generate config files for continious integration.}
8
+ gem.summary = %q{Generate config files for continious integration from templates inside the repository.}
9
+ gem.homepage = "http://github.com/codevise/ci_config_generator"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "ci_config_generator"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = CiConfigGenerator::VERSION
17
+
18
+ gem.add_development_dependency 'rspec', '~> 2.11'
19
+ end
@@ -0,0 +1,4 @@
1
+ require "ci_config_generator/version"
2
+
3
+ module CiConfigGenerator
4
+ end
@@ -0,0 +1,30 @@
1
+ namespace :ci do
2
+ namespace :config do
3
+ desc 'Generate config files from *.ci templates'
4
+ task :generate do
5
+ Dir.glob('**/*.ci') do |file_name|
6
+ target_file_name = file_name.gsub(/.ci$/, '')
7
+
8
+ if File.exist?(target_file_name)
9
+ error "#{target_file_name} already exists."
10
+ # STDERR.puts("Skipping #{target_file_name} - file exists")
11
+ else
12
+ STDERR.puts("Creating #{target_file_name} from #{file_name}")
13
+ File.write(target_file_name, interpolate(file_name, ENV))
14
+ end
15
+ end
16
+ end
17
+
18
+ def interpolate(file_name, variables)
19
+ File.read(file_name).gsub(/%{[^}]+}/) do |match|
20
+ key = match.gsub(/^%{([^}]+)}/, '\1')
21
+ variables[key] || error("Cannot interpolate unknown environment variable '#{key}' in '#{file_name}'")
22
+ end
23
+ end
24
+
25
+ def error(message)
26
+ STDERR.puts("Error: #{message}")
27
+ exit 1
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module CiConfigGenerator
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'rake ci:config:generate' do
4
+ it 'creates files from template files ending with .ci' do
5
+ in_tmpdir do
6
+ File.write('database.yml.ci', 'db: "my_db"')
7
+
8
+ rake 'ci:config:generate'
9
+
10
+ expect(File.read('database.yml')).to eq('db: "my_db"')
11
+ end
12
+ end
13
+
14
+ it 'interpolates environment variables' do
15
+ in_tmpdir do
16
+ File.write('database.yml.ci', 'db: "%{DB_NAME}"')
17
+
18
+ rake 'ci:config:generate', :env => {'DB_NAME' => 'replaced'}
19
+
20
+ expect(File.read('database.yml')).to eq('db: "replaced"')
21
+ end
22
+ end
23
+
24
+ it 'does not override existing files' do
25
+ in_tmpdir do
26
+ File.write('database.yml.ci', 'db: "ci"')
27
+ File.write('database.yml', 'db: "custom"')
28
+
29
+ rake 'ci:config:generate'
30
+
31
+ expect(File.read('database.yml')).to eq('db: "custom"')
32
+ end
33
+ end
34
+
35
+ it 'fails if files exist' do
36
+ in_tmpdir do
37
+ File.write('database.yml.ci', 'db: "ci"')
38
+ File.write('database.yml', 'db: "custom"')
39
+
40
+ sucess = rake 'ci:config:generate'
41
+
42
+ expect(sucess).to be(false)
43
+ end
44
+ end
45
+
46
+ it 'does not touch files named exactly .ci', :focus => true do
47
+ in_tmpdir do
48
+ File.write('.ci', 'db: "ci"')
49
+
50
+ sucess = rake 'ci:config:generate'
51
+
52
+ expect(sucess).to be(true)
53
+ end
54
+ end
55
+
56
+ def in_tmpdir(&block)
57
+ path = File.expand_path("spec/tmp/")
58
+
59
+ FileUtils.rm_rf(path) if File.exists?(path)
60
+ FileUtils.mkdir_p(path)
61
+
62
+ Dir.chdir(path, &block)
63
+ end
64
+
65
+ def rake(task_name, options = {})
66
+ env = options[:env] && options[:env].map { |key, value| [key, value] * '=' } * ' '
67
+ system("#{env} rake #{task_name} -f lib/ci_config_generator/tasks.rb > rake.out 2>&1")
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.configure do |config|
2
+ config.treat_symbols_as_metadata_keys_with_true_values = true
3
+ config.run_all_when_everything_filtered = true
4
+ config.filter_run :focus
5
+
6
+ config.order = 'random'
7
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ci_config_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Fischbach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.11'
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: '2.11'
30
+ description: Generate config files for continious integration.
31
+ email:
32
+ - tfischbach@codevise.de
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - ci_config_generator.gemspec
44
+ - lib/ci_config_generator.rb
45
+ - lib/ci_config_generator/tasks.rb
46
+ - lib/ci_config_generator/version.rb
47
+ - spec/acceptance_spec.rb
48
+ - spec/spec_helper.rb
49
+ homepage: http://github.com/codevise/ci_config_generator
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.23
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Generate config files for continious integration from templates inside the
73
+ repository.
74
+ test_files:
75
+ - spec/acceptance_spec.rb
76
+ - spec/spec_helper.rb