Rakefile (2375B) - raw
1 require 'rake/testtask'
2 require "bundler/gem_tasks"
3
4 # Manifest.txt file in same folder as this Rakefile
5 manifest_filename = "#{File.dirname(__FILE__)}/Manifest.txt"
6 git_ls_files_command = "git ls-files | LC_ALL=C sort"
7
8 Rake::TestTask.new(:test) do |test|
9 test.libs << 'test'
10 test.test_files = FileList.new('test/**/test_*.rb')
11 test.verbose = true
12 end
13 task :default => :test
14
15 task :build => [:man]
16 task :ci => [:test, :rubocop_packaging, :check_manifest, :build]
17
18 def test_pandoc
19 return system("pandoc -v > /dev/null 2>&1")
20 end
21
22 task :man do
23 puts "building manpages from wiki.."
24 unless test_pandoc
25 puts "no pandoc installed, needed for manpage generation."
26 return
27 end
28
29 # test if wiki is cloned
30 unless Dir.exist? 'doc/wiki/man'
31 puts "wiki git repository is not cloned in doc/wiki, try: git submodule update --init."
32 return
33 end
34
35 unless Dir.exist? 'man'
36 Dir.mkdir 'man'
37 end
38
39 Dir.glob("doc/wiki/man/*.md").each do |md|
40 m = /^.*\/(?<manpage>[^\/]*)\.md$/.match(md)[:manpage]
41 puts "generating manpage for: #{m}.."
42 r = system "pandoc -s -f markdown -t man #{md} -o man/#{m}"
43
44 unless r
45 puts "failed to generate manpage: #{m}."
46 return
47 end
48 end
49 end
50
51 task :clean do
52 ['man', 'pkg'].each do |d|
53 puts "cleaning #{d}.."
54 FileUtils.rm_r d if Dir.exist? d
55 end
56 end
57
58 task :manifest do
59 manifest = `#{git_ls_files_command}`
60 if $?.success? then
61 puts "Writing `git ls-files` output to #{manifest_filename}"
62 File.write(manifest_filename, manifest, mode: 'w')
63 else
64 abort "Failed to generate Manifest.txt (with `git ls-files`)"
65 end
66 end
67
68 task :check_manifest do
69 manifest = `#{git_ls_files_command}`
70 manifest_file_contents = File.read(manifest_filename)
71 if manifest == manifest_file_contents
72 puts "Manifest.txt OK"
73 else
74 puts "Manifest from `git ls-files`:\n#{manifest}"
75 STDERR.puts "Manifest.txt outdated. Please commit an updated Manifest.txt"
76 STDERR.puts "To generate Manifest.txt, run: rake manifest"
77 abort "Manifest.txt does not match `git ls-files`"
78 end
79 end
80
81 task :rubocop_packaging do
82 if /^2\.[012]\./ =~ RUBY_VERSION
83 puts "skipping rubocop-packaging checks on unsupported Ruby #{RUBY_VERSION}"
84 next
85 end
86 if system("rubocop --only Packaging")
87 puts "rubocop-packaging checks OK"
88 else
89 abort "rubocop-packaging checks failed"
90 end
91 end