File: default.rake

package info (click to toggle)
ruby-launchy 3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 304 kB
  • sloc: ruby: 1,051; makefile: 6
file content (279 lines) | stat: -rw-r--r-- 8,435 bytes parent folder | download
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# frozen_string_literal: true

# vim: syntax=ruby
require "rake/clean"
require "digest"
#------------------------------------------------------------------------------
# Minitest - standard TestTask
#------------------------------------------------------------------------------
begin
  require "minitest/test_task"
  Minitest::TestTask.create(:test) do |t|
    t.libs << "spec"
    t.warning = true
    t.test_globs = "{test,spec}/**/{test_*,*_spec}.rb"
  end

  desc "Run the requirements for the tests"
  task "test:requirements"

  desc "and the requirements"
  task test: "test:requirements"
  task default: :test
rescue LoadError
  This.task_warning("test")
end

#------------------------------------------------------------------------------
# Coverage - integrated with minitest
#------------------------------------------------------------------------------
begin
  require "simplecov"
  desc "Run tests with code coverage"
  Minitest::TestTask.create(:coverage) do |t|
    t.test_prelude = 'require "simplecov"; SimpleCov.start;'
    t.libs << "spec"
    t.warning = true
    t.test_globs = "{test,spec}/**/{test_*,*_spec}.rb"
  end
  CLOBBER << "coverage" if File.directory?("coverage")
rescue LoadError
  This.task_warning("simplecov")
end

#------------------------------------------------------------------------------
# RDoc - standard rdoc rake task, although we must make sure to use a more
#        recent version of rdoc since it is the one that has 'tomdoc' markup
#------------------------------------------------------------------------------
begin
  gem "rdoc" # otherwise we get the wrong task from stdlib
  require "rdoc/task"
  RDoc::Task.new do |t|
    t.markup   = "tomdoc"
    t.rdoc_dir = "doc"
    t.main     = "README.md"
    t.title    = "#{This.name} #{This.version}"
    t.rdoc_files.include(FileList["*.{rdoc,md,txt}"], FileList["ext/**/*.c"],
                         FileList["lib/**/*.rb"])
  end
rescue StandardError, LoadError
  This.task_warning("rdoc")
end

#------------------------------------------------------------------------------
# Reek - static code analysis
#------------------------------------------------------------------------------
begin
  require "reek/rake/task"
  Reek::Rake::Task.new
rescue LoadError
  This.task_warning("reek")
end

#------------------------------------------------------------------------------
# Rubocop - static code analysis
#------------------------------------------------------------------------------
begin
  require "rubocop/rake_task"
  RuboCop::RakeTask.new
rescue LoadError
  This.task_warning("rubocop")
end

def git_files
  IO.popen(%w[git ls-files -z], chdir: This.project_root, err: IO::NULL) do |ls|
    ls.readlines("\x0", chomp: true)
  end
end

#------------------------------------------------------------------------------
# Manifest - We want an explicit list of thos files that are to be packaged in
#            the gem. Most of this is from Hoe.
#------------------------------------------------------------------------------
namespace "manifest" do
  desc "Check the manifest"
  task check: :clean do
    files = FileList["**/*", ".*"].to_a.sort
    files = files.select { |f| (f =~ This.include_in_manifest) && File.file?(f) }

    tmp = "Manifest.tmp"
    File.open(tmp, "w") do |f|
      f.puts files.join("\n")
    end

    begin
      sh "diff -du Manifest.txt #{tmp}"
    ensure
      rm tmp
    end
    puts "Manifest looks good"
  end

  desc "Generate the manifest"
  task generate: :clean do
    files = git_files.grep(This.include_in_manifest)
    files.sort!
    File.open("Manifest.txt", "w") do |f|
      f.puts files.join("\n")
    end
  end
end

#------------------------------------------------------------------------------
# Fixme - look for fixmes and report them
#------------------------------------------------------------------------------
def fixme_project_root
  This.project_path("../fixme")
end

def fixme_project_path(subtree)
  fixme_project_root.join(subtree)
end

def local_fixme_files
  local_files = Dir.glob("tasks/**/*")
  local_files.concat(Dir.glob(".semaphore/*"))
  local_files.concat(Dir.glob(".rubocop.yml"))
  local_files.concat(Dir.glob("bin/*"))
end

def upstream_fixme_files
  fixme_project_root.glob("{tasks/**/*,.semaphore/*,.rubocop.yml,bin/*}")
end

def outdated_fixme_files
  local_fixme_files.select do |local|
    upstream = fixme_project_path(local)
    if upstream.exist?
      if File.exist?(local)
        (Digest::SHA256.file(local) != Digest::SHA256.file(upstream))
      else
        true
      end
    end
  end
end

def fixme_up_to_date?
  outdated_fixme_files.empty?
end

namespace :fixme do
  task default: "manifest:check" do
    This.manifest.each do |file|
      next if file == __FILE__
      next unless /(txt|rb|md|rdoc|css|html|xml|css)\Z/.match?(file)

      puts "FIXME: Rename #{file}" if /fixme/i.match?(file)
      File.readlines(file).each_with_index do |line, idx|
        prefix = "FIXME: #{file}:#{idx + 1}".ljust(42)
        puts "#{prefix} => #{line.strip}" if /fixme/i.match?(line)
      end
    end
  end

  desc "See the local fixme files"
  task :local_files do
    local_fixme_files.each do |f|
      puts f
    end
  end

  desc "See the upstream fixme files"
  task :upstream_files do
    upstream_fixme_files.each do |f|
      puts f
    end
  end

  desc "See if the fixme tools are outdated"
  task :outdated do
    if fixme_up_to_date?
      puts "Fixme files are up to date."
    else
      outdated_fixme_files.each do |f|
        puts "#{f} is outdated"
      end
    end
  end

  desc "Show the diff between the local and upstream fixme files"
  task :diff do
    outdated_fixme_files.each do |f|
      upstream = fixme_project_path(f)
      puts "===> Start Diff for #{f}"
      output = `diff -du #{upstream} #{f}`
      puts output unless output.empty?
      puts "===> End Diff for #{f}"
      puts
    end
  end

  desc "Update outdated fixme files"
  task :update do
    if fixme_up_to_date?
      puts "Fixme files are already up to date."
    else
      puts "Updating fixme files:"
      outdated_fixme_files.each do |local|
        upstream = fixme_project_path(local)
        puts "  * #{local}"
        FileUtils.cp(upstream, local)
      end
      puts "Use your git commands as appropriate."
    end
  end
end
desc "Look for fixmes and report them"
task fixme: "fixme:default"

#------------------------------------------------------------------------------
# Gem Specification
#------------------------------------------------------------------------------
# Really this is only here to support those who use bundler
desc "Build the #{This.name}.gemspec file"
task :gemspec do
  File.open(This.gemspec_file, "wb+") do |f|
    f.puts "# DO NOT EDIT - This file is automatically generated"
    f.puts "# Make changes to Manifest.txt and/or Rakefile and regenerate"
    f.write This.platform_gemspec.to_ruby
  end
end

# .rbc files from ruby 2.0
CLOBBER << "**/*.rbc"

# The standard gem packaging task, everyone has it.
require "rubygems/package_task"
Gem::PackageTask.new(This.platform_gemspec) do
  # nothing
end

#------------------------------------------------------------------------------
# Release - the steps we go through to do a final release, this is pulled from
#           a compbination of mojombo's rakegem, hoe and hoe-git
#
# 1) make sure we are on the main branch
# 2) make sure there are no uncommitted items
# 3) check the manifest and make sure all looks good
# 4) build the gem
# 5) do an empty commit to have the commit message of the version
# 6) tag that commit as the version
# 7) push main
# 8) push the tag
# 7) pus the gem
#------------------------------------------------------------------------------
desc "Check to make sure we are ready to release"
task :release_check do
  abort "You must be on the main branch to release!" unless /^\* main/.match?(`git branch`)
  abort "Nope, sorry, you have unfinished business" unless /^nothing to commit/m.match?(`git status`)
end

desc "Create tag v#{This.version}, build and push #{This.platform_gemspec.full_name} to rubygems.org"
task release: [:release_check, "manifest:check", :gem] do
  sh "git commit --allow-empty -a -m 'Release #{This.version}'"
  sh "git tag -a -m 'v#{This.version}' v#{This.version}"
  sh "git push origin main"
  sh "git push origin v#{This.version}"
  sh "gem push pkg/#{This.platform_gemspec.full_name}.gem"
end