This repository was archived by the owner on Sep 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathRakefile
More file actions
132 lines (115 loc) · 4.85 KB
/
Rakefile
File metadata and controls
132 lines (115 loc) · 4.85 KB
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
require 'open3'
OPENVOX_AGENT_VERSION = "8.22.1"
RED = "\033[31m".freeze
GREEN = "\033[32m".freeze
RESET = "\033[0m".freeze
# Let's ignore rubocop here until such a time as we either muzzle it
# or get these helpers more centralized and tested.
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
def run_command(cmd, silent: true, print_command: false, report_status: false)
cmd_string = cmd.is_a?(String) ? cmd : cmd.join(' ')
puts "#{GREEN}Running #{cmd_string}#{RESET}" if print_command
output = ''
Open3.popen2e(*Array(cmd)) do |_stdin, stdout_stderr, thread|
stdout_stderr.each do |line|
puts line unless silent
output += line
end
exitcode = thread.value.exitstatus
unless exitcode.zero?
err = "#{RED}Command failed! Command: #{cmd_string}, Exit code: #{exitcode}"
# Print details if we were running silent
err += "\nOutput:\n#{output}" if silent
err += RESET
abort err
end
puts "#{GREEN}Command finished with status #{exitcode}#{RESET}" if report_status
end
output.chomp
end
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
Dir.glob(File.join('tasks/**/*.rake')).each { |file| load file }
### Puppetlabs stuff ###
require 'packaging'
load './ext/release-lead.rake'
Pkg::Util::RakeUtils.load_packaging_tasks
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |task|
# These make the rubocop experience maybe slightly less terrible
task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']
# Use Rubocop's Github Actions formatter if possible
task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true'
end
desc "verify that commit messages match CONTRIBUTING.md requirements"
task(:commits) do
# 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.
github_base_ref = ENV.fetch('GITHUB_BASE_REF', 'main')
github_base_ref = 'main' if github_base_ref.empty?
# There's still something odd here. After action/checkout, 'main' by itself raises
# objections from git like: `fatal: Not a valid object name main`.
# but 'origin/main' works. However, if github_base_ref were a sha,
# origin/SHA would fail as a reference...
git_merge_base_cmd = ['git', 'merge-base', 'HEAD', "origin/#{github_base_ref}"]
baseref = run_command(git_merge_base_cmd)
commits = "#{baseref}..HEAD"
git_log_cmd = ['git', 'log', '--no-merges', '--pretty=%s', commits]
commit_lines = run_command(git_log_cmd, silent: false, print_command: true)
commit_lines.each_line do |commit_summary|
error_message = <<~HEREDOC
\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:
\n\t\t#{commit_summary}
\tThe commit summary (i.e. the first line of the commit message) should start with one of:
\t\t(docs)
\t\t(maint)
\t\t(packaging)
\t\t(<gh-#>) (An existing github ticket ref)
\n\tThis test for the commit summary is case-insensitive.\n
HEREDOC
commit_format_regex = /
^\((?:maint|doc|docs|packaging|(([[:alpha:]]+)-(\d+)))\)|
revert|bumping|merge|promoting
/xi
match = commit_summary.match(commit_format_regex)
raise error_message if match.nil?
ticket = match[1]
next if ticket.nil?
project = match[2]
# Could be an old PUP- or other Jira, and while there is still a
# https://puppet.atlassian.net archive, determining that a
# particular ticket does not exist is more involved that getting a
# 200 on a call like https://puppet.atlassian.net/browse/PUP-1234
next if project != 'gh'
ticket_number = match[3]
require 'net/http'
require 'uri'
uri = URI.parse("https://github.com/openvoxproject/openvox-agent/issues/#{ticket_number}")
response = Net::HTTP.get_response(uri)
if response.code != "200"
ticket_error = "\t#{RED}Did not find a ticket matching #{ticket} at #{uri}#{RESET}\n\n"
raise error_message + ticket_error
end
end
puts "#{GREEN}All commit messages match the guidelines!#{RESET}"
end
begin
require "github_changelog_generator/task"
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.header = <<~HEADER.chomp
# Changelog
All notable changes to this project will be documented in this file.
HEADER
config.user = "openvoxproject"
config.project = "openvox-agent"
config.exclude_labels = %w[dependencies duplicate question invalid wontfix wont-fix modulesync skip-changelog]
config.future_release = OPENVOX_AGENT_VERSION
config.exclude_tags_regex = /\A7\./
end
rescue LoadError
task :changelog do
abort("Run `bundle install --with release` to install the `github_changelog_generator` gem.")
end
end
desc 'Prepare for a release'
task 'release:prepare' => [:changelog]