-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
151 lines (135 loc) · 5.13 KB
/
Rakefile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# frozen_string_literal: true
# The MIT License
#
# Copyright (c) 2019-2022 Yurii Dubinka
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
require "rubygems"
require "rake"
require "date"
require "rdoc"
require "colorize"
require "rake/clean"
require "concurrent"
# @todo #/DEV Investigate the possibility of using migrations from active_record
# - Rake tasks https://gist.github.com/schickling/6762581
# - Gem for rake tasks https://github.com/thuss/standalone-migrations
# - basic example of active_record https://gist.github.com/unnitallman/944011
# For now standalone-migrations looks complex and needs
# - complex files structure
# - manual specification of version(?) thus no auto-apply available
def name
@name ||= File.basename(Dir["*.gemspec"].first, ".*")
end
def version
Gem::Specification.load(Dir["*.gemspec"].first).version
end
task default: %i[init_hooks clean rubocop test sqlint docker]
# @todo #/DEV Update copyright to 2023, so far lets disable this task for separate PR
# task default: %i[init_hooks clean rubocop test sqlint copyright docker]
task :init_hooks do
next if File.file?(".git/hooks/commit-msg")
FileUtils.copy(".githooks/commit-msg", ".git/hooks/commit-msg")
FileUtils.chmod("+x", ".git/hooks/commit-msg")
end
require "rake/testtask"
desc "Run all unit tests"
Rake::TestTask.new(:test) do |t|
ENV["MT_CPU"] = Concurrent.processor_count.to_s
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.verbose = true
t.warning = false
end
require "rdoc/task"
desc "Build RDoc documentation"
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = "rdoc"
rdoc.title = "#{name} #{version}"
rdoc.rdoc_files.include("README*")
rdoc.rdoc_files.include("lib/**/*.rb")
end
require "rubocop/rake_task"
desc "Run RuboCop on all directories"
RuboCop::RakeTask.new(:rubocop) do |task|
task.fail_on_error = true
task.requires << "rubocop-rspec"
end
task :copyright do
# @todo #/DEV Update copyright to 2022 for sql files as current changes of structure may lead
# to manual actions during installation.
sh "grep -q -r \"2019-#{Date.today.strftime('%Y')}\" \
--include \"*.rb\" \
--include \"*.txt\" \
--include \"Rakefile\" \
."
end
# @todo #/DEV Enable xcop when xml/html files will be added to the project. So far there is no
# profit.
#
# require "xcop/rake_task"
# desc "Validate all XML/XSL/XSD/HTML files for formatting"
# Xcop::RakeTask.new :xcop do |task|
# task.license = "license.txt"
# task.includes = %w[**/*.xml **/*.xsl **/*.xsd **/*.html]
# task.excludes = %w[target/**/* coverage/**/* wp/**/* test/resources/*]
# end
# @todo #/DEV Enable rule "Checks SQL against the ANSI syntax" fully.
# Right now all violations related to PRAGMA https://www.sqlite.org/pragma.html
# are suppressed as PRAGMA is sqlite specific option.
# Potential fix is to move this option into vcs4sql lib and remove from our
# sql files.
task :sqlint do
puts "Running sqlint..."
require "sqlint"
src = Dir.glob("upgrades/**/*.sql")
puts "Inspecting #{src.size} files"
total = 0
src.each do |f|
violations = SQLint::Linter.new(f, File.open(f, "r"))
.run
.first(1000)
.reject { |v| v.message.include? '"PRAGMA"' }
violations.each do |v|
msg_lines = v.message.split("\n")
p [v.filename, v.line, v.column, "#{v.type} #{msg_lines.shift}"].join ":"
end
total += violations.count { |lint| lint.type == :error }
end
if total.positive?
abort "#{total.colorize(:red)} SQL violations found."
else
puts "#{src.size} files inspected, #{'no offenses'.colorize(:green)} detected"
end
end
task :clean do
Dir.glob("test/resources/**/*.db").each { |f| File.delete(f) }
end
task :docker do
puts "Building docker image..."
system <<~CMD
docker-compose -f .docker/docker-compose.yml build \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg version=1.0
CMD
system "docker-compose -f .docker/docker-compose.yml rm --force -s lazylead"
system "docker-compose -f .docker/docker-compose.yml up"
end