knife-changelog 1.4.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8be4794cbe4a60468b7bb2ff5ad22bd741ef974e3580b1cca57bb2d6aae48ed6
4
- data.tar.gz: 7a1a688801825095a4ed8e5dc1ac5bf66fe6cf54276fc02be6539ed36df84a02
3
+ metadata.gz: 731b3e420e21b2512be8e155a1b1de2c86a3c8176df2a8757e9a92fae75c234d
4
+ data.tar.gz: 25c25fc1a184540546610fa5b6881b75ab5b5d41b3631034393167d386e3727d
5
5
  SHA512:
6
- metadata.gz: a99aeeed6a9505f636e0c1c8df1b8775d9f1e6dfd839240d3680e6c4526a15c568f8a14a1bd02133bd5f22f4bc6f95e093e581702c45ec50a71d41593715a939
7
- data.tar.gz: bb700c5d7f199a831692f154f02fa7c64038f8b508e4069f309682b1546defbceeedc7a1dffcea4d20290d8966b869ae07037f9ad0c52e86558e027d28efc6cd
6
+ metadata.gz: a68e9e0ce0671437e659e87230827d103bfebd82902aeb563b7d7158b8235ef922c910477e5ebb6a357ed74a03daf8aeb29456f37835c6e8fb49efd5e276e601
7
+ data.tar.gz: 136e3c7cebc581e1a08844fe24d03fcbd157ad7cd8e43ffec185a8c1c10c49bcb76c461bfc2400e65e10e49910260a54b7c1a85ee3cc5f0354c24c9a6716968b
@@ -0,0 +1,15 @@
1
+ name: Tests
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ matrix:
8
+ ruby-version: ['2.5', '2.7']
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: ${{ matrix.ruby-version }}
14
+ bundler-cache: true
15
+ - run: bundle exec rake
@@ -0,0 +1,18 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ tags: [ '*' ]
5
+ jobs:
6
+ release:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ ruby-version: 2.7
13
+ - run: |
14
+ install -D -m 600 <(echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}") $HOME/.gem/credentials
15
+ gem build *.gemspec
16
+ gem push *.gem
17
+ env:
18
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
 
3
- begin
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:spec)
6
5
 
7
- task :default => :spec
8
- rescue LoadError
9
- end
6
+ task default: :spec
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'knife-changelog'
8
- spec.version = '1.4.0'
8
+ spec.version = '1.6.0'
9
9
  spec.authors = ['Gregoire Seux']
10
10
  spec.email = ['kamaradclimber@gmail.com']
11
11
  spec.summary = 'Facilitate access to cookbooks changelog'
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.6'
22
21
  spec.add_development_dependency 'pry'
23
22
  spec.add_development_dependency 'rake'
24
23
  spec.add_development_dependency 'rspec'
@@ -64,7 +64,7 @@ class Chef
64
64
  description: 'Update Berksfile'
65
65
 
66
66
  def run
67
- Log.info config
67
+ Log.info config.to_s
68
68
  if config[:policyfile] && File.exist?(config[:policyfile])
69
69
  puts PolicyChangelog.new(
70
70
  @name_args,
@@ -18,7 +18,7 @@ class KnifeChangelog
18
18
  end
19
19
  end
20
20
 
21
- def initialize(config)
21
+ def initialize(config = {})
22
22
  @tmp_prefix = 'knife-changelog'
23
23
  @config = config
24
24
  @tmp_dirs = []
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ require 'chef/log'
3
+ require_relative 'changelog'
4
+
5
+ class KnifeChangelog
6
+ class GitSubmodule < Changelog
7
+
8
+ def run(submodules)
9
+ raise ::ArgumentError, "Submodules must be an Array instead of #{submodules.inspect}" unless submodules.is_a?(::Array)
10
+ submodules.map do |submodule|
11
+ Chef::Log.debug "Checking changelog for #{submodule} (submodule)"
12
+ format_changelog(submodule, *handle_submodule(submodule))
13
+ end.compact.join("\n")
14
+ ensure
15
+ clean
16
+ end
17
+ end
18
+ end
@@ -11,6 +11,9 @@ require 'rest-client'
11
11
 
12
12
  class PolicyChangelog
13
13
  TMP_PREFIX = 'knife-changelog'
14
+ # Regex matching Chef cookbook version syntax
15
+ # See https://docs.chef.io/cookbook_versioning.html#syntax
16
+ VERSION_REGEX = /^[1-9]*[0-9](\.[0-9]+){1,2}$/
14
17
 
15
18
  # Initialzes Helper class
16
19
  #
@@ -104,14 +107,30 @@ class PolicyChangelog
104
107
  # @param current [String] current cookbook version tag
105
108
  # @param target [String] target cookbook version tag
106
109
  # @return [String] changelog between tags for one cookbook
107
- def git_changelog(source_url, current, target)
110
+ def git_changelog(source_url, current, target, cookbook = nil)
108
111
  dir = Dir.mktmpdir(TMP_PREFIX)
109
112
  repo = Git.clone(source_url, dir)
110
- repo.log.between(git_ref(current, repo), git_ref(target, repo)).map do |commit|
113
+ cookbook_path = cookbook ? git_cookbook_path(repo, cookbook) : '.'
114
+ repo.log.path(cookbook_path).between(git_ref(current, repo, cookbook), git_ref(target, repo, cookbook)).map do |commit|
111
115
  "#{commit.sha[0, 7]} #{commit.message.lines.first.strip}"
112
116
  end.join("\n")
113
117
  end
114
118
 
119
+ # Tries to find the location of a specific cookbook in the given repo
120
+ #
121
+ # @param repo [Git::Base] Git repository object
122
+ # @param cookbook [String] name of the cookbook to search the location
123
+ # @return [String] reative location of the cookbook in the repo
124
+ def git_cookbook_path(repo, cookbook)
125
+ metadata_files = ['metadata.rb', '*/metadata.rb'].flat_map { |location| repo.ls_files(location).keys }
126
+ metadata_path = metadata_files.find do |path|
127
+ path = ::File.join(repo.dir.to_s, path)
128
+ ::Chef::Cookbook::Metadata.new.tap { |m| m.from_file(path) }.name == cookbook
129
+ end
130
+ raise "Impossible to find matching metadata for #{cookbook} in #{repo.remote.url}" unless metadata_path
131
+ ::File.dirname(metadata_path)
132
+ end
133
+
115
134
  # Tries to convert a supermarket tag to a git reference
116
135
  # if there is a difference in formatting between the two.
117
136
  # This is issue is present for the 'java' cookbook.
@@ -119,9 +138,11 @@ class PolicyChangelog
119
138
  #
120
139
  # @param ref [String] version reference
121
140
  # @param repo [Git::Base] Git repository object
141
+ # @param cookbook [String] name of the cookbook to ref against
122
142
  # @return [String]
123
- def git_ref(myref, repo)
143
+ def git_ref(myref, repo, cookbook_name = nil)
124
144
  possible_refs = ['v' + myref, myref]
145
+ possible_refs += possible_refs.map { |ref| "#{cookbook_name}-#{ref}" } if cookbook_name
125
146
  possible_refs += possible_refs.map { |ref| ref.chomp('.0') } if myref[/\.0$/]
126
147
  existing_ref = possible_refs.find do |ref|
127
148
  begin
@@ -159,7 +180,7 @@ class PolicyChangelog
159
180
  output = ["\nChangelog for #{name}: #{data['current_version']}->#{data['target_version']}"]
160
181
  output << '=' * output.first.size
161
182
  output << if data['current_version']
162
- git_changelog(data['source_url'], data['current_version'], data['target_version'])
183
+ git_changelog(data['source_url'], data['current_version'], data['target_version'], name)
163
184
  else
164
185
  'Cookbook was not in the Policyfile.lock.json'
165
186
  end
@@ -178,7 +199,11 @@ class PolicyChangelog
178
199
 
179
200
  # Search for cookbook downgrade and raise an error if any
180
201
  def validate_downgrade!(data)
181
- downgrade = data.select { |_, ck| ::Gem::Version.new(ck['target_version']) < ::Gem::Version.new(ck['current_version']) }
202
+ downgrade = data.select do |_, ck|
203
+ # Do not try to validate downgrade on non-sementic versions (e.g. git revision)
204
+ ck['target_version'] =~ VERSION_REGEX && ck['current_version'] =~ VERSION_REGEX &&
205
+ ::Gem::Version.new(ck['target_version']) < ::Gem::Version.new(ck['current_version'])
206
+ end
182
207
 
183
208
  return if downgrade.empty?
184
209
 
@@ -214,7 +214,7 @@ RSpec.describe PolicyChangelog do
214
214
  allow(changelog).to receive(:git_ref).with('1.0.0', any_args).and_return('v1.0.0')
215
215
  allow(changelog).to receive(:git_ref).with('1.0.1', any_args).and_return('v1.0.1')
216
216
  allow(changelog).to receive(:correct_tags)
217
- allow(git_repo).to receive_message_chain(:log, :between)
217
+ allow(git_repo).to receive_message_chain(:log, :path, :between)
218
218
  .with('v1.0.0', 'v1.0.1')
219
219
  .and_return([git_commit])
220
220
 
@@ -238,11 +238,16 @@ RSpec.describe PolicyChangelog do
238
238
 
239
239
  context 'when tag invalid and able to correct' do
240
240
  it 'returns correct git tag' do
241
- allow(repo).to receive(:checkout).with(/v1.0/).and_raise(::Git::GitExecuteError)
242
241
  allow(repo).to receive(:checkout).with('1.0.0').and_raise(::Git::GitExecuteError)
243
- allow(repo).to receive(:checkout).with('1.0').and_return(true)
244
242
 
245
- expect(changelog.git_ref('1.0.0', repo)).to eq('1.0')
243
+ tags = %w[v1.0.0 1.0 v1.0 cookbook_name-1.0.0 cookbook_name-1.0 cookbook_name-v1.0.0 cookbook_name-v1.0]
244
+ tags.each do |valid_result|
245
+ allow(repo).to receive(:checkout).with(valid_result).and_return(true)
246
+ tags.reject { |v| v == valid_result }.each do |invalid_result|
247
+ allow(repo).to receive(:checkout).with(invalid_result).and_raise(::Git::GitExecuteError)
248
+ end
249
+ expect(changelog.git_ref('1.0.0', repo, 'cookbook_name')).to eq valid_result
250
+ end
246
251
  end
247
252
  end
248
253
 
@@ -308,7 +313,7 @@ RSpec.describe PolicyChangelog do
308
313
  }
309
314
 
310
315
  allow(changelog).to receive(:git_changelog)
311
- .with(instance_of(String), '4.0.0', '5.0.0')
316
+ .with(instance_of(String), '4.0.0', '5.0.0', 'users')
312
317
  .and_return('e1b971a Add test commit message')
313
318
 
314
319
  output = <<~COMMIT.chomp
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-changelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregoire Seux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
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.6'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.6'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: pry
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -199,9 +185,10 @@ executables: []
199
185
  extensions: []
200
186
  extra_rdoc_files: []
201
187
  files:
188
+ - ".github/workflows/ci.yml"
189
+ - ".github/workflows/release.yml"
202
190
  - ".gitignore"
203
191
  - ".rubocop.yml"
204
- - ".travis.yml"
205
192
  - Gemfile
206
193
  - LICENSE.txt
207
194
  - README.md
@@ -211,6 +198,7 @@ files:
211
198
  - lib/knife/changelog/berksfile.rb
212
199
  - lib/knife/changelog/changelog.rb
213
200
  - lib/knife/changelog/git.rb
201
+ - lib/knife/changelog/git_submodule.rb
214
202
  - lib/knife/changelog/policyfile.rb
215
203
  - resources/Berksfile
216
204
  - resources/Berksfile.lock
@@ -243,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
231
  - !ruby/object:Gem::Version
244
232
  version: '0'
245
233
  requirements: []
246
- rubygems_version: 3.0.3
234
+ rubygems_version: 3.1.6
247
235
  signing_key:
248
236
  specification_version: 4
249
237
  summary: Facilitate access to cookbooks changelog
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4
4
- deploy:
5
- provider: rubygems
6
- api_key:
7
- secure: LAM8qxTQa6oxzKiQpWrqRlcE1czmGFj16NSj1FVgZYJLZIfXKdvSpth+DfuCk8mxG1tvDXa3ckfERrzexG3lYGNPGyZH2sjnyt900Evd3Bn8vhv0LXE7cEZb3x/uJ3RHRvKpEDnMsy4gqoVByDLWXWnI9Q/8B4AtzFeTVsTr48g=
8
- gem: knife-changelog
9
- on:
10
- tags: true
11
- repo: criteo/knife-changelog
12
- sudo: false # use docker based infra