-
Notifications
You must be signed in to change notification settings - Fork 145
/
Rakefile
67 lines (61 loc) · 2.39 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
require 'packaging'
load './ext/release-lead.rake'
Pkg::Util::RakeUtils.load_packaging_tasks
namespace :package do
task :bootstrap do
puts 'Bootstrap is no longer needed, using packaging-as-a-gem'
end
task :implode do
puts 'Implode is no longer needed, using packaging-as-a-gem'
end
end
desc 'run static analysis with rubocop'
task(:rubocop) do
require 'rubocop'
cli = RuboCop::CLI.new
exit_code = cli.run(%w(--display-cop-names --format simple))
raise "RuboCop detected offenses" if exit_code != 0
end
desc "verify that commit messages match CONTRIBUTING.md requirements"
task(:commits) do
# This rake task looks at the summary from every commit from this branch not
# in the branch targeted for a PR. This is accomplished by using the
# TRAVIS_COMMIT_RANGE environment variable, which is present in travis CI and
# populated with the range of commits the PR contains. If not available, this
# falls back to `main..HEAD` as a next best bet as `main` is unlikely to
# ever be absent.
#
# When we move to GH actions, use `GITHUB_BASE_REF` to resolve the merge base
# ref, which is the common ancestor between the base branch and PR. Then do
# git log for all of the commits in `HEAD` that are not in the base ref
#
# baseref = %x{git merge-base HEAD $GITHUB_BASE_REF}
# commits = "#{baseref}..HEAD"
commits = ENV['TRAVIS_COMMIT_RANGE'].nil? ? 'main..HEAD' : ENV['TRAVIS_COMMIT_RANGE'].sub(/\.\.\./, '..')
%x{git log --no-merges --pretty=%s #{commits}}.each_line do |commit_summary|
error_message=<<-HEREDOC
\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n \
\n\t\t#{commit_summary}\n \
\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n \
\t\t(docs)\n \
\t\t(maint)\n \
\t\t(packaging)\n \
\t\t(<ANY PUBLIC JIRA TICKET>)\n \
\n\tThis test for the commit summary is case-insensitive.\n\n\n
HEREDOC
if /^\((maint|doc|docs|packaging|pa-\d+)\)|revert|bumping|merge|promoting/i.match(commit_summary).nil?
ticket = commit_summary.match(/^\(([[:alpha:]]+-[[:digit:]]+)\).*/)
if ticket.nil?
raise error_message
else
require 'net/http'
require 'uri'
uri = URI.parse("https://tickets.puppetlabs.com/browse/#{ticket[1]}")
response = Net::HTTP.get_response(uri)
if response.code != "200"
raise error_message
end
end
end
end
end