Skip to content

Commit d14a1b0

Browse files
committed
Implement a strings:validate:reference task
This task can validate whether REFERENCE.md is still in sync.
1 parent 5955970 commit d14a1b0

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/puppet-strings/tasks.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ module PuppetStrings
88
module Tasks
99
require 'puppet-strings/tasks/generate.rb'
1010
require 'puppet-strings/tasks/gh_pages.rb'
11+
require 'puppet-strings/tasks/validate.rb'
1112
end
1213
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require 'puppet-strings'
4+
require 'tempfile'
5+
6+
namespace :strings do
7+
namespace :validate do
8+
desc 'Validate the reference is up to date'
9+
task :reference, [:patterns, :debug, :backtrace] do |t, args|
10+
filename = 'REFERENCE.md'
11+
12+
unless File.exist?(filename)
13+
STDERR.puts "#{filename} does not exist"
14+
exit 1
15+
end
16+
17+
patterns = args[:patterns]
18+
patterns = patterns.split if patterns
19+
patterns ||= PuppetStrings::DEFAULT_SEARCH_PATTERNS
20+
21+
generated = Tempfile.create do |file|
22+
options = {
23+
debug: args[:debug] == 'true',
24+
backtrace: args[:backtrace] == 'true',
25+
json: false,
26+
markdown: true,
27+
path: file,
28+
}
29+
PuppetStrings.generate(patterns, options)
30+
31+
file.read
32+
end
33+
34+
existing = File.read(filename)
35+
36+
if generated != existing
37+
STDERR.puts "#{filename} is outdated"
38+
exit 1
39+
end
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)