cookbook_bumper 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 +7 -0
- data/.gitignore +25 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +90 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/cookbook_bumper.gemspec +34 -0
- data/exe/cookbook_bumper +6 -0
- data/lib/.update_environments2.swo +0 -0
- data/lib/cookbook_bumper/config.rb +36 -0
- data/lib/cookbook_bumper/cookbooks.rb +26 -0
- data/lib/cookbook_bumper/envfile.rb +92 -0
- data/lib/cookbook_bumper/envs.rb +45 -0
- data/lib/cookbook_bumper/git.rb +62 -0
- data/lib/cookbook_bumper/metadata.rb +56 -0
- data/lib/cookbook_bumper/rake_task.rb +29 -0
- data/lib/cookbook_bumper/version.rb +34 -0
- data/lib/cookbook_bumper.rb +34 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3b66af653fc0734c2692083f01708f65ced3b93
|
4
|
+
data.tar.gz: 472c80331bcdfd8ec67fe166e257dce661527bc7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5866da5946aa50600e1333d8d8d732c425776d0bc144f6aa8373fdc082dfbbfb593b6639e4eba8e0013aa2dd124fc6e010799f758f69874e993d52934fba24c2
|
7
|
+
data.tar.gz: 6ed45b5c12adbf581b7fd7d6de2ab59b9268439bc6cce872b112edf7d58419ee0b0afc74407c2d32b828684c6216b2cc62c7d49cb7fb05f4032add359897964f
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.rbc
|
2
|
+
.config
|
3
|
+
coverage
|
4
|
+
InstalledFiles
|
5
|
+
lib/bundler/man
|
6
|
+
pkg
|
7
|
+
rdoc
|
8
|
+
spec/reports
|
9
|
+
tmp
|
10
|
+
_Store
|
11
|
+
*~
|
12
|
+
*#
|
13
|
+
.#*
|
14
|
+
\#*#
|
15
|
+
.*.sw[a-z]
|
16
|
+
*.un~
|
17
|
+
*.tmp
|
18
|
+
*.bk
|
19
|
+
*.bkup
|
20
|
+
|
21
|
+
# ruby/bundler files
|
22
|
+
.rvmrc
|
23
|
+
Gemfile.lock
|
24
|
+
.bundle
|
25
|
+
*.gem
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Goldstar Events
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# CookbookBumper
|
2
|
+
|
3
|
+
CookBumper does exactly what you think, it bumps cookbook versions for you as you modify them.
|
4
|
+
|
5
|
+
When it runs it looks for cookbooks that have been modified and bumps them. It also updates your
|
6
|
+
environment files with the latest versions of all the cookbooks, and gives a nice little print out
|
7
|
+
of what it did.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'cookbook_bumper'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install cookbook_bumper
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Configure it as a rake task
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'cookbook_bumper/rake_task'
|
31
|
+
|
32
|
+
CookbookBumper::RakeTask.new(:bump)
|
33
|
+
```
|
34
|
+
|
35
|
+
Or use it directly from the command line
|
36
|
+
|
37
|
+
```bash
|
38
|
+
$ cookbook_bumper
|
39
|
+
production
|
40
|
+
-------------------------------------------------
|
41
|
+
Cookbook Action Old Ver New Ver
|
42
|
+
-------------------------------------------------
|
43
|
+
apparmor Deleted = 0.9.0
|
44
|
+
awscli Bumped = 0.0.3 0.0.4
|
45
|
+
backups Updated = 0.1.6 0.1.7
|
46
|
+
staging
|
47
|
+
-------------------------------------------------
|
48
|
+
Cookbook Action Old Ver New Ver
|
49
|
+
-------------------------------------------------
|
50
|
+
apparmor Deleted = 0.9.0
|
51
|
+
awscli Bumped = 0.0.3 0.0.4
|
52
|
+
backups Updated = 0.1.6 0.1.7
|
53
|
+
```
|
54
|
+
|
55
|
+
## Configuration
|
56
|
+
|
57
|
+
At the moment the only way to change the default settings is through the rake task
|
58
|
+
|
59
|
+
|
60
|
+
* `cookbook_path` - Where to look for cookbooks - `Array` (default: read from `knife.rb`)
|
61
|
+
* `environment_path` - Where to look for environment files - `Array` (default: read from `knife.rb`)
|
62
|
+
* `exclude_environment` - Names of environments to leave alone - `Array` (default: `['development']`)
|
63
|
+
* `repo_root` - Root of repository to look for changes - `String` (default\*: `./`)
|
64
|
+
* `knife_path` - Location of `knife.rb` - `String` (default\*: `./.chef/knife.rb`)
|
65
|
+
|
66
|
+
\*:_Relative paths are relative to the location of the Rakefile_
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
require 'cookbook_bumper/rake_task'
|
70
|
+
|
71
|
+
CookbookBumper::RakeTask.new(:bump) do |config|
|
72
|
+
config.knife_path = './knife.rb'
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Development
|
77
|
+
|
78
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
79
|
+
|
80
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/goldstar/cookbook_bumper.
|
85
|
+
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
90
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'cookbook_bumper'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'cookbook_bumper/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'cookbook_bumper'
|
10
|
+
spec.version = CookbookBumper::VERSION
|
11
|
+
spec.authors = ['Jason Scholl']
|
12
|
+
spec.email = ['jason.e.scholl@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = 'Chef Cookbook Bumper'
|
15
|
+
spec.description = 'Automatically bump cookbook versions and environment files, and verify all changes have associated version bumps '
|
16
|
+
spec.homepage = 'https://github.com/jescholl/cookbook_bumper'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
31
|
+
spec.add_dependency 'chef', '~> 13.0'
|
32
|
+
spec.add_dependency 'terminal-table', '~> 1.8'
|
33
|
+
spec.add_dependency 'git', '~> 1.3'
|
34
|
+
end
|
data/exe/cookbook_bumper
ADDED
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CookbookBumper
|
4
|
+
class Config
|
5
|
+
attr_accessor :repo_root, :exclude_environments, :knife_path
|
6
|
+
attr_writer :cookbook_path, :environment_path
|
7
|
+
def initialize
|
8
|
+
@exclude_environments = %w[development]
|
9
|
+
@knife_path = File.expand_path('.chef/knife.rb')
|
10
|
+
@repo_root = File.expand_path('.')
|
11
|
+
yield(self) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def cookbook_path
|
15
|
+
@cookbook_path || Array(fetch_chef_config(:cookbook_path)).map { |p| File.expand_path(p) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def environment_path
|
19
|
+
@environment_path || Array(fetch_chef_config(:environment_path)).map { |p| File.expand_path(p) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_chef_config(config_name)
|
23
|
+
read_chef_config unless config_already_read?
|
24
|
+
Chef::Config.send(config_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def config_already_read?
|
28
|
+
@knife_path == @knife_path_read
|
29
|
+
end
|
30
|
+
|
31
|
+
def read_chef_config
|
32
|
+
Chef::Config.from_file(@knife_path)
|
33
|
+
@knife_path_read = @knife_path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CookbookBumper
|
4
|
+
class Cookbooks
|
5
|
+
include Enumerable
|
6
|
+
attr_accessor :aliases
|
7
|
+
def initialize(cookbook_path)
|
8
|
+
@files = cookbook_path.map { |c| Dir[File.join(c, '*', 'metadata.rb')] }.flatten
|
9
|
+
@metadata = @files.map do |f|
|
10
|
+
CookbookBumper::Metadata.new(f)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](cookbook)
|
15
|
+
@metadata.select { |m| m.name == cookbook || m.aliases.include?(cookbook) }.tap do |cookbooks|
|
16
|
+
raise "multiple cookbooks named #{cookbook}" if cookbooks.length > 1
|
17
|
+
end.first
|
18
|
+
end
|
19
|
+
|
20
|
+
def each
|
21
|
+
@metadata.each do |md|
|
22
|
+
yield md
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
module CookbookBumper
|
5
|
+
class EnvFile
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
attr_reader :path, :log
|
9
|
+
def_delegators :cookbook_versions, :delete, :each, :keys, :values
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@path = path
|
13
|
+
@env = parse(File.read(path))
|
14
|
+
@log = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](cookbook)
|
18
|
+
cookbook_versions[cookbook]
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(cookbook, version)
|
22
|
+
cookbook_versions[cookbook] = version
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
@env['name']
|
27
|
+
end
|
28
|
+
|
29
|
+
def cookbook_versions
|
30
|
+
@env['cookbook_versions']
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
JSON.pretty_generate(deep_sort)
|
35
|
+
end
|
36
|
+
|
37
|
+
def log_change(cookbook_name, old_ver, new_ver)
|
38
|
+
action = if old_ver.nil?
|
39
|
+
'Added'
|
40
|
+
elsif new_ver.nil?
|
41
|
+
'Deleted'
|
42
|
+
elsif CookbookBumper.cookbooks[cookbook_name].bumped?
|
43
|
+
'Bumped'
|
44
|
+
else
|
45
|
+
'Updated'
|
46
|
+
end
|
47
|
+
@log << [cookbook_name, action, old_ver, new_ver]
|
48
|
+
end
|
49
|
+
|
50
|
+
def update
|
51
|
+
CookbookBumper.cookbooks.each do |cookbook|
|
52
|
+
if cookbook.version != self[cookbook.name]
|
53
|
+
log_change(cookbook.name, self[cookbook.name], cookbook.version)
|
54
|
+
self[cookbook.name] = cookbook.version.exact
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def clean
|
60
|
+
each do |cookbook_name, version|
|
61
|
+
# metadata wasn't found or metadata was found using a different name
|
62
|
+
if CookbookBumper.cookbooks[cookbook_name].nil? || CookbookBumper.cookbooks[cookbook_name].name != cookbook_name
|
63
|
+
log_change(cookbook_name, version, nil)
|
64
|
+
delete(cookbook_name)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def deep_sort(obj = @env)
|
70
|
+
if obj.is_a?(Hash)
|
71
|
+
obj.sort.map { |k, v| [k, deep_sort(v)] }.to_h
|
72
|
+
else
|
73
|
+
obj
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def save
|
78
|
+
File.write(path, self)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
# trim out merge/rebase conflict markings and let those sections be regenerated
|
84
|
+
def resolve_conflcits(json)
|
85
|
+
json.gsub(/^[<>=]{5}.+/, '')
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse(json)
|
89
|
+
JSON.parse(resolve_conflcits(json))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'terminal-table'
|
4
|
+
|
5
|
+
module CookbookBumper
|
6
|
+
class Envs
|
7
|
+
include Enumerable
|
8
|
+
def initialize(environment_path)
|
9
|
+
@files = environment_path.map { |e| Dir[File.join(e, '*')] }.flatten
|
10
|
+
@envs = @files.map { |file| CookbookBumper::EnvFile.new(file) }
|
11
|
+
@change_log = []
|
12
|
+
Terminal::Table::Style.defaults = { border_top: false, border_bottom: false, border_y: '', border_i: '' }
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](env_name)
|
16
|
+
@envs.select { |e| e.name == env_name }.tap do |envs|
|
17
|
+
raise "multiple environments named #{env_name}" if envs.length > 1
|
18
|
+
end.first
|
19
|
+
end
|
20
|
+
|
21
|
+
def each
|
22
|
+
@envs.each do |env|
|
23
|
+
yield env
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
reject { |e| CookbookBumper.config.exclude_environments.include?(e.name) }.each do |env|
|
29
|
+
env.clean
|
30
|
+
env.update
|
31
|
+
env.save
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def change_log
|
36
|
+
reject { |env| env.log.empty? }.map do |env|
|
37
|
+
Terminal::Table.new do |t|
|
38
|
+
t.title = env.name
|
39
|
+
t.headings = ['Cookbook', 'Action', 'Old Ver', 'New Ver']
|
40
|
+
t.rows = env.log
|
41
|
+
end
|
42
|
+
end.join("\n\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'git'
|
4
|
+
|
5
|
+
module CookbookBumper
|
6
|
+
class Git
|
7
|
+
attr_reader :diff
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@git = ::Git.open(Dir.pwd)
|
11
|
+
@diff = @git.diff('origin/master')
|
12
|
+
end
|
13
|
+
|
14
|
+
def changed_files
|
15
|
+
diff.map { |f| File.expand_path(f.path) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def changed_cookbooks
|
19
|
+
changed_files.map do |changed_file_path|
|
20
|
+
CookbookBumper.config.cookbook_path.map do |cookbook_path|
|
21
|
+
find_cookbook_by_file(changed_file_path, cookbook_path)
|
22
|
+
end.compact
|
23
|
+
end.flatten.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_cookbook_by_file(changed_file_path, cookbook_path)
|
27
|
+
changed_file_path.match(%r{^#{cookbook_path}/(?<cookbook>[^\/]+)}) do |m|
|
28
|
+
# ignore matches without metadata.rb, they are not cookbooks
|
29
|
+
if File.exist?(File.join(cookbook_path, m[:cookbook], 'metadata.rb'))
|
30
|
+
CookbookBumper.cookbooks[m[:cookbook]].name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def bumped_metadata
|
36
|
+
diff.select do |f|
|
37
|
+
CookbookBumper.config.cookbook_path.any? do |cookbook_path|
|
38
|
+
File.expand_path(f.path) =~ %r{#{cookbook_path}/[^/]+/metadata\.rb} &&
|
39
|
+
f.patch =~ /^\+version/
|
40
|
+
end
|
41
|
+
end.map(&:path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def bumped_cookbooks
|
45
|
+
bumped_metadata.map do |metadata_path|
|
46
|
+
metadata_path.match(%r{(?<cookbook>[^/]+)/metadata\.rb}) do |m|
|
47
|
+
CookbookBumper.cookbooks[m[:cookbook]].name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def unbumped_cookbooks
|
53
|
+
changed_cookbooks - bumped_cookbooks
|
54
|
+
end
|
55
|
+
|
56
|
+
def bump_changed
|
57
|
+
unbumped_cookbooks.each do |cookbook_name|
|
58
|
+
CookbookBumper.cookbooks[cookbook_name].bump
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'chef/cookbook/metadata'
|
4
|
+
|
5
|
+
module CookbookBumper
|
6
|
+
class Metadata
|
7
|
+
attr_reader :aliases, :path, :version
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
@aliases = []
|
12
|
+
@metadata = parse(path)
|
13
|
+
@version = CookbookBumper::Version.new(@metadata.version)
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse(path)
|
17
|
+
metadata = Chef::Cookbook::Metadata.new.tap { |m| m.from_file(path); m } # rubocop:disable Style/Semicolon
|
18
|
+
path.match(%r{/(?<cookbook_dir>[^/]+)/metadata\.rb$}) do |m|
|
19
|
+
@aliases |= [m[:cookbook_dir]] if metadata.name != m[:cookbook_dir]
|
20
|
+
end
|
21
|
+
metadata
|
22
|
+
end
|
23
|
+
|
24
|
+
def bumped?
|
25
|
+
@version != @metadata.version
|
26
|
+
end
|
27
|
+
|
28
|
+
def bump
|
29
|
+
version.bump
|
30
|
+
save
|
31
|
+
end
|
32
|
+
|
33
|
+
def updated_contents
|
34
|
+
File.read(path).sub(/^\s*version.*/) do |version_line|
|
35
|
+
version_line.sub(/[\d\.]+/, @metadata.version => @version)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def save
|
40
|
+
File.write(path, updated_contents)
|
41
|
+
end
|
42
|
+
|
43
|
+
def method_missing(method_sym, *args, &block)
|
44
|
+
if respond_to?(method_sym)
|
45
|
+
@metadata.send(method_sym, *args, &block)
|
46
|
+
else
|
47
|
+
puts "Couldn't find method #{method_sym}"
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def respond_to_missing?(method_sym, include_private = false)
|
53
|
+
@metadata.respond_to?(method_sym) || super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/tasklib'
|
5
|
+
require 'cookbook_bumper/config'
|
6
|
+
|
7
|
+
module CookbookBumper
|
8
|
+
class RakeTask < Rake::TaskLib
|
9
|
+
attr_reader :name
|
10
|
+
attr_accessor :config
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
@name = args.shift || :bump
|
14
|
+
|
15
|
+
desc 'Bump Cookbooks' unless ::Rake.application.last_description
|
16
|
+
|
17
|
+
task(name, *args) do
|
18
|
+
yield(@config = CookbookBumper::Config.new) if block_given?
|
19
|
+
run_task
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_task
|
24
|
+
# lazy load gem for snappier task list
|
25
|
+
require 'cookbook_bumper'
|
26
|
+
CookbookBumper.run(config)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CookbookBumper
|
4
|
+
VERSION = '0.1.0'
|
5
|
+
|
6
|
+
class Version
|
7
|
+
def initialize(ver_string)
|
8
|
+
@ver_string = ver_string
|
9
|
+
@major, @minor, @patch = parse(ver_string)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(ver_string)
|
13
|
+
ver_string.to_s.match(/(?<major>\d+)\.(?<minor>\d+)\.?(?<patch>\d*)/) do |v|
|
14
|
+
[v[:major], v[:minor], v[:patch]].map(&:to_i)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def ==(other)
|
19
|
+
parse(self) == parse(other)
|
20
|
+
end
|
21
|
+
|
22
|
+
def bump
|
23
|
+
@patch += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
[@major, @minor, @patch].join('.')
|
28
|
+
end
|
29
|
+
|
30
|
+
def exact
|
31
|
+
to_s.prepend('= ')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cookbook_bumper/version'
|
4
|
+
require 'cookbook_bumper/envs'
|
5
|
+
require 'cookbook_bumper/envfile'
|
6
|
+
require 'cookbook_bumper/git'
|
7
|
+
require 'cookbook_bumper/metadata'
|
8
|
+
require 'cookbook_bumper/cookbooks'
|
9
|
+
require 'cookbook_bumper/config'
|
10
|
+
require 'chef'
|
11
|
+
|
12
|
+
module CookbookBumper
|
13
|
+
def self.configure
|
14
|
+
yield config
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.config
|
18
|
+
@config ||= Config.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.cookbooks
|
22
|
+
@cookbooks ||= Cookbooks.new(config.cookbook_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.run(override_config = nil)
|
26
|
+
@config = override_config if override_config
|
27
|
+
envs = Envs.new(config.environment_path)
|
28
|
+
git = Git.new
|
29
|
+
|
30
|
+
git.bump_changed
|
31
|
+
envs.update
|
32
|
+
puts envs.change_log
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cookbook_bumper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Scholl
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: chef
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '13.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '13.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: terminal-table
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.8'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: git
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.3'
|
125
|
+
description: 'Automatically bump cookbook versions and environment files, and verify
|
126
|
+
all changes have associated version bumps '
|
127
|
+
email:
|
128
|
+
- jason.e.scholl@gmail.com
|
129
|
+
executables:
|
130
|
+
- cookbook_bumper
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".gitignore"
|
135
|
+
- ".rspec"
|
136
|
+
- ".rubocop.yml"
|
137
|
+
- ".ruby-version"
|
138
|
+
- ".travis.yml"
|
139
|
+
- Gemfile
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- bin/console
|
144
|
+
- bin/setup
|
145
|
+
- cookbook_bumper.gemspec
|
146
|
+
- exe/cookbook_bumper
|
147
|
+
- lib/.update_environments2.swo
|
148
|
+
- lib/cookbook_bumper.rb
|
149
|
+
- lib/cookbook_bumper/config.rb
|
150
|
+
- lib/cookbook_bumper/cookbooks.rb
|
151
|
+
- lib/cookbook_bumper/envfile.rb
|
152
|
+
- lib/cookbook_bumper/envs.rb
|
153
|
+
- lib/cookbook_bumper/git.rb
|
154
|
+
- lib/cookbook_bumper/metadata.rb
|
155
|
+
- lib/cookbook_bumper/rake_task.rb
|
156
|
+
- lib/cookbook_bumper/version.rb
|
157
|
+
homepage: https://github.com/jescholl/cookbook_bumper
|
158
|
+
licenses:
|
159
|
+
- MIT
|
160
|
+
metadata: {}
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.5.1
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Chef Cookbook Bumper
|
181
|
+
test_files: []
|