-
Notifications
You must be signed in to change notification settings - Fork 5
/
steps_cookbook_metadata_check.yml
55 lines (45 loc) · 1.84 KB
/
steps_cookbook_metadata_check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
steps:
- task: CmdLine@2
displayName: 'Write Metadata Check Script'
inputs:
script: |
cat << EOF > $(Agent.TempDirectory)/metadata_check.rb
#!/bin/env ruby
require 'chef/cookbook/metadata'
metadata = Chef::Cookbook::Metadata.new
metadata.from_file('metadata.rb')
cookbook = metadata.name
version = metadata.version
Chef::Log.info "Checking cookbook #{cookbook} version #{version}"
permitted_operators = %w(~> =)
pass = true
Chef::Log.info "Platforms: #{metadata.platforms}"
if metadata.platforms.empty?
Chef::Log.error "Cookbook #{cookbook} does not specify any platforms!"
pass = false
end
Chef::Log.info "Chef Versions: #{metadata.chef_versions}"
if metadata.chef_versions.empty?
Chef::Log.error "Cookbook #{cookbook} does not specify a chef_version!"
pass = false
end
metadata.dependencies.each do |dependency, constraint|
Chef::Log.info "Cookbook #{cookbook} depends on #{dependency} with constraint #{constraint}."
operator, version = constraint.split
if version == '0.0.0'
Chef::Log.error "Cookbook #{cookbook} does not pin to a version for #{dependency} cookbook!"
pass = false
next # skip as this is likely a depends without a version constraint
end
unless permitted_operators.include?(operator)
Chef::Log.error "Cookbook #{cookbook} does not use a permitted version constraint (#{permitted_operators}) for #{dependency} cookbook!"
pass = false
end
end
raise 'Cookbook metadata not valid' unless pass
EOF
- task: chef-software.chef-azdo.execute.component@3
displayName: 'Cookbook Metadata Check'
inputs:
component: 'chef'
arguments: 'exec knife exec $(Agent.TempDirectory)/metadata_check.rb -V'