Skip to content
This repository was archived by the owner on Dec 24, 2021. It is now read-only.

Commit 1b51c3f

Browse files
Version bump v1.4.0 -> v2.0.0
- Removes mono-repo support from Rakefile libs - Handles dependency management in Berksfile for metadata.rb - Explicitly requires 'paint' everywhere it's used
1 parent 9004c9c commit 1b51c3f

19 files changed

+394
-376
lines changed

.rubocop.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Lint/HandleExceptions:
1010
- '**/*.rake'
1111

1212
Metrics/AbcSize:
13-
Max: 30
13+
Max: 35
1414

1515
Metrics/BlockLength:
1616
Exclude:
@@ -48,3 +48,10 @@ Style/FormatStringToken:
4848

4949
Style/FrozenStringLiteralComment:
5050
Enabled: false
51+
52+
# Currently this rule is buggy, so we'll just skip it
53+
Style/Next:
54+
Enabled: false
55+
56+
Style/StderrPuts:
57+
Enabled: false

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
We follow [Semantic Versioning](http://semver.org/) as a way of measuring stability of an update. This
44
means we will never make a backwards-incompatible change within a major version of the project.
55

6+
## v2.0.0 (2018-09-17)
7+
8+
- [BREAKING] Removes support for mono-repo Rakefile
9+
- Alters `gramsay` command to not need a subject anymore (given no mono-repo support)
10+
- Adds dependency management helpers for deterministic builds in wrapper cookbooks
11+
612
## v1.4.0 (2018-09-15)
713

814
- Adds Simplecov for measuring test coverage

README.md

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,38 @@ You will need to include this in your Rakefile located in each recipe directory.
7272
this will be a full test, but there are options to use only a smaller set of tests if you
7373
choose.
7474

75-
### Full cookbook testing (usually what you want as this is the gate to production)
75+
### Everything (usually what you want)
7676

7777
For an individual cookbook repository, include a Rakefile with the following contents:
7878

7979
```ruby
80+
require 'rordan_gramsay/chef_tasks/dependencies'
8081
require 'rordan_gramsay/chef_tasks/lint'
8182
require 'rordan_gramsay/chef_tasks/kitchen'
8283
require 'rordan_gramsay/chef_tasks/test'
8384

84-
task default: ['test:all']
85+
task default: ['lint:all']
8586
```
8687

87-
This will provide the following testing options from the command line:
88+
This will provide the following testing and dependency management options from the command line:
8889

8990
```
9091
$ rake -T
9192
92-
rake kitchen # Runs integration tests using Test Kitchen
93-
rake lint # Lints cookbook using all tools
94-
rake test # Runs all linting and integration tests
93+
rake dependency:check # Check if version pinning is done correctly
94+
rake dependency:clean # Remove pinned dependencies from metadata.rb
95+
rake dependency:migrate # [EXPERIMENTAL] Migrate cookbook dependencies from metadata.rb to Berksfile (for use with dependency:pin task)
96+
rake dependency:pin # Pin dependencies
97+
rake dependency:update # Update dependency graph
98+
rake kitchen # Runs integration tests using Test Kitchen
99+
rake lint # Lints cookbook using all tools
100+
rake test # Runs all linting and integration tests
95101
```
96102

97-
For a monolithic repo style of cookbook tracking, see the **Recursive testing** section below.
103+
Rather than copy-paste, if you have this gem installed you may also run `gramsay init` in the base
104+
of the cookbook project directory and it will lay down a Rakefile with those contents for you.
105+
106+
### Cookbook testing
98107

99108
### Lint testing only
100109

@@ -114,29 +123,41 @@ $ rake -T
114123
rake lint # Lints cookbook using all tools
115124
```
116125

117-
### Recursive testing
126+
### Dependency management
127+
128+
Long story short, Berkshelf has a much richer ecosystem for handling cookbook dependencies with more
129+
nuance than the built-in Chef dependency resolver. To facilitate deterministic builds with a wrapper-cookbook
130+
approach, we have a set of rake tasks to handle pinning to exact versions of all dependencies.
118131

119-
For a monolithic repository situation, where multiple cookbooks are stored in the
120-
`cookbooks/` directory relative to the project root, there is a set of rake tasks to
121-
handle this mass testing. Add the following to a Rakefile in the monolithic repo root
122-
directory:
132+
Pinning a dependency A that depends on B which, in turn, depends on C makes it so that you only need to
133+
declare the dependency on A to have the metadata reflect the resolved versions of A, B, and C in the
134+
`metadata.rb`. This way we can resolve the dependency graph ahead of time and leave the executing of those
135+
cookbooks to `chef-client` at runtime.
136+
137+
Cookbooks that have their name starting with `role_` or `wrapper_` will be treated as a wrapper cookbook
138+
and be subject to these deterministic builds (e.g., `depends 'cats', '= 1.2.3'`). All other cookbooks will
139+
be treated like library cookbooks and have the pessimistic version constraint operator (`~>`). This ensures
140+
their dependencies always remain in the same major version, so `depends 'cats', '~> 3.0'` ensures a cookbook
141+
matching both `>= 3.0.0` and `< 4.0.0`.
123142

124143
```ruby
125-
require 'rordan_gramsay/chef_tasks/master_repo'
144+
require 'rordan_gramsay/chef_tasks/dependencies'
145+
146+
task default: ['dependency:check']
126147
```
127148

128149
This will provide the following testing options from the command line:
129150

130151
```
131152
$ rake -T
132153
133-
rake lint # Runs linting, style checks, and overall formatting checks for each cookbook
134-
rake test # Runs all linting and tests on all cookbooks
154+
rake dependency:check # Check if version pinning is done correctly
155+
rake dependency:clean # Remove pinned dependencies from metadata.rb
156+
rake dependency:migrate # [EXPERIMENTAL] Migrate cookbook dependencies from metadata.rb to Berksfile (for use with dependency:pin task)
157+
rake dependency:pin # Pin dependencies
158+
rake dependency:update # Update dependency graph
135159
```
136160

137-
In order to make use of this, each cookbook repo must also implement the tasks defined
138-
in the cookbook Rakefiles.
139-
140161
## Contributing
141162

142163
See [CONTRIBUTING.md](/CONTRIBUTING.md).
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require 'paint'
2+
require_relative '../dependencies'
3+
4+
# rubocop:disable Lint/UnneededCopDisableDirective
5+
6+
file 'Berksfile.lock' do
7+
`berks install`
8+
end
9+
10+
task dependency: ['dependency:check']
11+
12+
namespace :dependency do
13+
desc 'Check if version pinning has been done correctly'
14+
task :check do
15+
$stdout.puts(Paint['Inspecting version constraints for errors', :yellow, :bold])
16+
obj = RordanGramsay::Dependencies::Pinning.new
17+
obj.check
18+
abort if obj.failure?
19+
end
20+
21+
desc 'Remove pinned dependencies from metadata.rb'
22+
task :clean do
23+
$stdout.puts(Paint['Removing dependency entries from metadata.rb', :yellow, :bold])
24+
obj = RordanGramsay::Dependencies::Pinning.new
25+
obj.clean
26+
abort if obj.failure?
27+
end
28+
29+
desc '[EXPERIMENTAL] Migrate cookbook dependencies from metadata.rb to Berksfile (for use with dependency:pin task)'
30+
task :migrate do
31+
$stdout.puts(Paint['Attempting to migrate dependencies from metadata.rb to Berksfile', :yellow, :bold])
32+
obj = RordanGramsay::Dependencies::Pinning.new
33+
obj.migrate
34+
abort if obj.failure?
35+
$stdout.puts(Paint[' This may or may not have worked. Please audit the dependencies in Berksfile', :yellow, :bold])
36+
$stdout.puts(Paint % [' to ensure they look correct, then run %{cmd}', :yellow, :bold, cmd: Paint['rake dependency:update', :white, :bold]])
37+
end
38+
39+
desc 'Update dependency graph'
40+
task :update do
41+
$stdout.puts(Paint['Updating Berksfile.lock', :yellow, :bold])
42+
`berks update`
43+
44+
$stdout.puts(Paint['Pinning dependencies from Berksfile to metadata.rb', :yellow, :bold])
45+
obj = RordanGramsay::Dependencies::Pinning.new
46+
obj.call
47+
abort if obj.failure?
48+
end
49+
50+
desc 'Pin dependencies'
51+
task :pin do
52+
$stdout.puts(Paint['Pinning dependencies from Berksfile to metadata.rb', :yellow, :bold])
53+
obj = RordanGramsay::Dependencies::Pinning.new
54+
obj.call
55+
abort if obj.failure?
56+
end
57+
end
58+
59+
# rubocop:enable Lint/UnneededCopDisableDirective

lib/rordan_gramsay/chef_tasks/lint/comments.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rake'
2+
require 'paint'
23
require_relative '../../lint/cookbook_comments_checker'
34

45
namespace :lint do

lib/rordan_gramsay/chef_tasks/master_repo.rb

Lines changed: 0 additions & 143 deletions
This file was deleted.

lib/rordan_gramsay/chef_tasks/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
task slow: ['kitchen:test']
77

8-
task quick: ['lint:all']
8+
task quick: ['dependency:check', 'lint:all']
99
end
1010
desc 'Runs all linting and integration tests'
1111
task test: ['test:all']

0 commit comments

Comments
 (0)