shipnotes 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +265 -0
- data/app/controllers/shipnotes/releases_controller.rb +61 -0
- data/app/helpers/shipnotes/releases_helper.rb +38 -0
- data/app/views/layouts/shipnotes/application.html.erb +24 -0
- data/app/views/shipnotes/releases/index.atom.builder +20 -0
- data/app/views/shipnotes/releases/index.html.erb +51 -0
- data/config/routes.rb +7 -0
- data/exe/shipnotes +7 -0
- data/lib/shipnotes/check.rb +218 -0
- data/lib/shipnotes/cli.rb +312 -0
- data/lib/shipnotes/config.rb +278 -0
- data/lib/shipnotes/differs/json_schema.rb +45 -0
- data/lib/shipnotes/differs/mcp_tools.rb +50 -0
- data/lib/shipnotes/differs/openapi.rb +55 -0
- data/lib/shipnotes/differs.rb +33 -0
- data/lib/shipnotes/engine.rb +44 -0
- data/lib/shipnotes/engine_configuration.rb +21 -0
- data/lib/shipnotes/entry.rb +18 -0
- data/lib/shipnotes/entry_writer.rb +116 -0
- data/lib/shipnotes/field.rb +55 -0
- data/lib/shipnotes/finding.rb +7 -0
- data/lib/shipnotes/git_diff.rb +65 -0
- data/lib/shipnotes/github_labels.rb +28 -0
- data/lib/shipnotes/init.rb +69 -0
- data/lib/shipnotes/publication.rb +46 -0
- data/lib/shipnotes/release.rb +32 -0
- data/lib/shipnotes/releaser.rb +128 -0
- data/lib/shipnotes/renderer.rb +92 -0
- data/lib/shipnotes/repository.rb +100 -0
- data/lib/shipnotes/schema.rb +82 -0
- data/lib/shipnotes/semver.rb +83 -0
- data/lib/shipnotes/source.rb +47 -0
- data/lib/shipnotes/surface.rb +32 -0
- data/lib/shipnotes/templates/changelog.md.erb +11 -0
- data/lib/shipnotes/templates/release_notes.md.erb +1 -0
- data/lib/shipnotes/version.rb +5 -0
- data/lib/shipnotes/version_bump.rb +34 -0
- data/lib/shipnotes/version_targets.rb +70 -0
- data/lib/shipnotes/yaml_file.rb +22 -0
- data/lib/shipnotes.rb +52 -0
- metadata +91 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Shipnotes
|
|
4
|
+
# The pull request gate: entries are valid, the diff carries the entries its
|
|
5
|
+
# changes need, versions move only through a release, and a breaking
|
|
6
|
+
# contract change is declared as one.
|
|
7
|
+
class Check
|
|
8
|
+
Result = Data.define(:errors, :notes) do
|
|
9
|
+
def passed? = errors.empty?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(config, base:, entry_required: true, oasdiff: nil)
|
|
13
|
+
@config = config
|
|
14
|
+
@diff = GitDiff.new(config.root, base)
|
|
15
|
+
@entry_required = entry_required
|
|
16
|
+
@oasdiff = oasdiff
|
|
17
|
+
@targets = VersionTargets.new(config)
|
|
18
|
+
@errors = []
|
|
19
|
+
@notes = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def call
|
|
23
|
+
check_schema
|
|
24
|
+
check_uncommitted
|
|
25
|
+
release = check_versions
|
|
26
|
+
check_entry_required unless release
|
|
27
|
+
check_breaking
|
|
28
|
+
Result.new(errors: @errors, notes: @notes)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def head = @head ||= Repository.new(@config, source: @diff.head_source)
|
|
34
|
+
def base = @base ||= Repository.new(@config, source: @diff.base_source)
|
|
35
|
+
|
|
36
|
+
def check_schema
|
|
37
|
+
head.problems.each { |problem| @errors << "schema: #{problem}" }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def check_uncommitted
|
|
41
|
+
@diff.uncommitted(@config.directory).each do |path|
|
|
42
|
+
@notes << "#{path} is not committed, so this check does not see it"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def entry_changes(*statuses)
|
|
47
|
+
@diff.changes.filter_map do |change|
|
|
48
|
+
next unless statuses.include?(change.status) && File.dirname(change.path) == @config.unreleased_dir
|
|
49
|
+
next unless change.path.end_with?(".yml")
|
|
50
|
+
|
|
51
|
+
change
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def added_entries
|
|
56
|
+
@added_entries ||= begin
|
|
57
|
+
ids = entry_changes("A").map { |change| File.basename(change.path, ".yml") }
|
|
58
|
+
head.entries.select { |entry| ids.include?(entry.id) }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def release_changes = @diff.changes.select { |change| File.dirname(change.path) == @config.releases_dir }
|
|
63
|
+
|
|
64
|
+
def check_versions
|
|
65
|
+
base_versions = @targets.read { |path| @diff.base_source.read(path) }
|
|
66
|
+
head_versions = @targets.read { |path| @diff.head_source.read(path) }
|
|
67
|
+
edited = head_versions.select { |label, value| base_versions.key?(label) && base_versions[label] != value }.keys
|
|
68
|
+
return false if edited.empty? && release_changes.empty?
|
|
69
|
+
|
|
70
|
+
errors = verify_release(base_versions, head_versions)
|
|
71
|
+
if errors.empty?
|
|
72
|
+
@notes << "release PR verified"
|
|
73
|
+
return true
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
@errors << "versions: #{(edited + release_changes.map(&:path)).uniq.join(', ')} changed, but this diff is not a valid " \
|
|
77
|
+
"release; versions and release files come only from `shipnotes release`"
|
|
78
|
+
errors.each { |error| @errors << "versions: #{error}" }
|
|
79
|
+
false
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def verify_release(base_versions, head_versions)
|
|
83
|
+
changes = release_changes
|
|
84
|
+
added = changes.select { |change| change.status == "A" }
|
|
85
|
+
return [ "a release adds exactly one release file and changes no other" ] unless added.size == 1 && changes.size == 1
|
|
86
|
+
return [ "a release PR adds no unreleased entries" ] if added_entries.any?
|
|
87
|
+
|
|
88
|
+
path = added.first.path
|
|
89
|
+
data = YamlFile.parse(@diff.head_source.read(path).to_s)
|
|
90
|
+
return [ "#{path} is not a release file" ] unless data.is_a?(Hash) && data["entries"].is_a?(Array) && data["release"]
|
|
91
|
+
|
|
92
|
+
release = Release.from_h(data)
|
|
93
|
+
moved = entry_changes("D").filter_map do |change|
|
|
94
|
+
entry = YamlFile.parse(@diff.base_source.read(change.path).to_s)
|
|
95
|
+
Entry.new(id: File.basename(change.path, ".yml"), data: entry) if entry.is_a?(Hash)
|
|
96
|
+
end
|
|
97
|
+
errors = []
|
|
98
|
+
errors << "the release entries must be exactly the unreleased files it deletes" unless sort(release.entries) == sort(moved)
|
|
99
|
+
errors.concat(release_version_errors(release, moved, base_versions, head_versions))
|
|
100
|
+
errors.concat(stray_file_errors(path, moved))
|
|
101
|
+
errors
|
|
102
|
+
rescue Psych::Exception, KeyError, NoMethodError => error
|
|
103
|
+
[ "#{path} could not be read as a release: #{error.message}" ]
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def release_version_errors(release, moved, base_versions, head_versions)
|
|
107
|
+
return [] unless @config.versioning.semver?
|
|
108
|
+
|
|
109
|
+
current = Releaser.current_version(@config, base, base_versions)
|
|
110
|
+
computed = VersionBump.new(@config.versioning).next_version(current, moved)
|
|
111
|
+
errors = []
|
|
112
|
+
if release.version.nil?
|
|
113
|
+
errors << "the release has no version"
|
|
114
|
+
elsif !(computed.nil? && release.version == current)
|
|
115
|
+
errors.concat(Releaser.version_errors(config: @config, current: current, computed: computed, chosen: release.version,
|
|
116
|
+
first_release: base.releases.empty?))
|
|
117
|
+
end
|
|
118
|
+
errors << "release id must be #{release.version}" if @config.versioning.version_ids? && release.id != release.version
|
|
119
|
+
head_versions.each do |label, value|
|
|
120
|
+
errors << "#{label} is #{value}, expected #{release.version}" unless value == release.version
|
|
121
|
+
end
|
|
122
|
+
errors
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def stray_file_errors(release_path, moved)
|
|
126
|
+
allowed = [ release_path, @config.render.output, *@targets.paths ] +
|
|
127
|
+
moved.map { |entry| File.join(@config.unreleased_dir, "#{entry.id}.yml") }
|
|
128
|
+
stray = @diff.changes.map(&:path) - allowed.compact
|
|
129
|
+
stray.empty? ? [] : [ "a release PR changes only the release, its entries, version files and the changelog; also changed: #{stray.join(', ')}" ]
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def sort(entries) = entries.map(&:to_h).sort_by { |entry| entry["id"].to_s }
|
|
133
|
+
|
|
134
|
+
def check_entry_required
|
|
135
|
+
required, any_entry = required_surfaces
|
|
136
|
+
return if required.empty? && !any_entry
|
|
137
|
+
|
|
138
|
+
needs = required.any? ? "surfaces: #{required.join(', ')}" : "any entry"
|
|
139
|
+
unless @entry_required
|
|
140
|
+
@notes << "entry rule skipped (this diff would need: #{needs})"
|
|
141
|
+
return
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
if added_entries.empty?
|
|
145
|
+
@errors << "entry: this diff needs a changelog entry (#{needs}); add one with `shipnotes new`"
|
|
146
|
+
return
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
provided = added_entries.flat_map(&:surfaces).uniq
|
|
150
|
+
(required - provided).each do |surface|
|
|
151
|
+
@errors << "entry: this diff changes the #{surface} surface; add an entry whose surfaces include #{surface}"
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Returns the surfaces the diff touches and whether it needs some entry
|
|
156
|
+
# even when it touches none.
|
|
157
|
+
def required_surfaces
|
|
158
|
+
paths = @diff.changes.map(&:path).reject { |path| path.start_with?("#{@config.directory}/") }
|
|
159
|
+
required = @config.surfaces.values.select { |surface| paths.any? { |path| surface.match?(path) } }.map(&:key)
|
|
160
|
+
any_entry = @config.check.require_entry == "always" &&
|
|
161
|
+
paths.any? { |path| @config.check.ignore.none? { |pattern| Surface.glob_match?(pattern, path) } }
|
|
162
|
+
triggered.each do |trigger|
|
|
163
|
+
if trigger.surface
|
|
164
|
+
required << trigger.surface
|
|
165
|
+
else
|
|
166
|
+
any_entry = true
|
|
167
|
+
end
|
|
168
|
+
@notes << "trigger: #{trigger.name}"
|
|
169
|
+
end
|
|
170
|
+
[ required.uniq, any_entry ]
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def triggered
|
|
174
|
+
@config.triggers.select do |trigger|
|
|
175
|
+
@diff.changed_lines.any? do |path, lines|
|
|
176
|
+
trigger.path_match?(path) && lines.any? { |line| line[1..].match?(trigger.pattern) }
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def check_breaking
|
|
182
|
+
@config.contract_surfaces.each do |surface|
|
|
183
|
+
findings = contract_findings(surface)
|
|
184
|
+
breaking = findings.select(&:breaking)
|
|
185
|
+
next if breaking.empty?
|
|
186
|
+
next if added_entries.any? { |entry| declares_breaking?(entry, surface) }
|
|
187
|
+
|
|
188
|
+
@errors << "breaking: #{surface.key} has #{breaking.size} breaking change(s); add an entry with surfaces " \
|
|
189
|
+
"[#{surface.key}] that bumps the major version, or undo the change"
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def declares_breaking?(entry, surface)
|
|
194
|
+
(!@config.surfaces? || entry.surfaces.include?(surface.key)) &&
|
|
195
|
+
VersionBump.new(@config.versioning).level_for(entry) == :major
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def contract_findings(surface)
|
|
199
|
+
base_text = @diff.base_source.read(surface.contract.file)
|
|
200
|
+
head_text = @diff.head_source.read(surface.contract.file)
|
|
201
|
+
return [ contract_removed(surface) ] if base_text && head_text.nil?
|
|
202
|
+
return [] unless base_text && head_text && base_text != head_text
|
|
203
|
+
|
|
204
|
+
findings = Differs.resolve(surface.contract.differ, @config).call(base_text, head_text, { oasdiff: @oasdiff })
|
|
205
|
+
findings.each { |finding| @notes << "#{surface.key}: #{finding}" }
|
|
206
|
+
findings
|
|
207
|
+
rescue Differs::Skipped => error
|
|
208
|
+
@notes << "#{surface.key}: breaking-change diff skipped: #{error.message}"
|
|
209
|
+
[]
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def contract_removed(surface)
|
|
213
|
+
finding = Finding.new(subject: surface.contract.file, breaking: true, internal: false, message: "contract file removed")
|
|
214
|
+
@notes << "#{surface.key}: #{finding}"
|
|
215
|
+
finding
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
|
|
5
|
+
module Shipnotes
|
|
6
|
+
class Cli
|
|
7
|
+
COMMANDS = {
|
|
8
|
+
"init" => "Write .shipnotes.yml and the entry folders",
|
|
9
|
+
"new" => "Add an unreleased entry",
|
|
10
|
+
"status" => "Show unreleased entries and the next version",
|
|
11
|
+
"lint" => "Validate every entry and release file",
|
|
12
|
+
"check" => "Check a branch against its base (for CI)",
|
|
13
|
+
"release" => "Move unreleased entries into a release and bump versions",
|
|
14
|
+
"render" => "Write the changelog file from the releases",
|
|
15
|
+
"notes" => "Print one release as Markdown (for a GitHub release)",
|
|
16
|
+
"current" => "Print the current version",
|
|
17
|
+
"next" => "Print the version the unreleased entries lead to"
|
|
18
|
+
}.freeze
|
|
19
|
+
|
|
20
|
+
def self.start(argv, out: $stdout, err: $stderr, input: $stdin, env: ENV, cwd: Dir.pwd)
|
|
21
|
+
new(argv, out: out, err: err, input: input, env: env, cwd: cwd).run
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def initialize(argv, out:, err:, input:, env:, cwd:)
|
|
25
|
+
@argv = argv.dup
|
|
26
|
+
@out = out
|
|
27
|
+
@err = err
|
|
28
|
+
@input = input
|
|
29
|
+
@env = env
|
|
30
|
+
@cwd = cwd
|
|
31
|
+
@root = nil
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def run
|
|
35
|
+
command = @argv.shift
|
|
36
|
+
case command
|
|
37
|
+
when nil, "help", "-h", "--help" then help
|
|
38
|
+
when "-v", "--version", "version" then @out.puts(VERSION) || 0
|
|
39
|
+
when *COMMANDS.keys then send("run_#{command}")
|
|
40
|
+
else usage_error("unknown command #{command.inspect}")
|
|
41
|
+
end
|
|
42
|
+
rescue OptionParser::ParseError => error
|
|
43
|
+
usage_error(error.message)
|
|
44
|
+
rescue Shipnotes::Error => error
|
|
45
|
+
@err.puts("shipnotes: #{error.message}")
|
|
46
|
+
1
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def help
|
|
52
|
+
@out.puts("Usage: shipnotes COMMAND [options] (shipnotes COMMAND --help for its options)\n\nCommands:")
|
|
53
|
+
COMMANDS.each { |name, summary| @out.puts(format(" %-9s %s", name, summary)) }
|
|
54
|
+
0
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def usage_error(message)
|
|
58
|
+
@err.puts("shipnotes: #{message}")
|
|
59
|
+
@err.puts("Run `shipnotes help` for usage.")
|
|
60
|
+
2
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def parse(banner)
|
|
64
|
+
parser = OptionParser.new
|
|
65
|
+
parser.banner = "Usage: shipnotes #{banner}"
|
|
66
|
+
parser.on("--root DIR", "Project root (default: the nearest folder with #{Config::FILE})") { |dir| @root = File.expand_path(dir, @cwd) }
|
|
67
|
+
yield parser if block_given?
|
|
68
|
+
parser.on("-h", "--help", "Show this help") do
|
|
69
|
+
@out.puts(parser)
|
|
70
|
+
throw :help
|
|
71
|
+
end
|
|
72
|
+
parser.parse!(@argv)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def with_help
|
|
76
|
+
catch(:help) { return yield }
|
|
77
|
+
0
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def config = @config ||= Config.load(root)
|
|
81
|
+
|
|
82
|
+
def root
|
|
83
|
+
@root ||= begin
|
|
84
|
+
dir = @cwd
|
|
85
|
+
dir = File.dirname(dir) until File.exist?(File.join(dir, Config::FILE)) || File.dirname(dir) == dir
|
|
86
|
+
File.exist?(File.join(dir, Config::FILE)) ? dir : git_root || @cwd
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def git_root
|
|
91
|
+
output, _error, status = Open3.capture3("git", "rev-parse", "--show-toplevel", chdir: @cwd)
|
|
92
|
+
status.success? ? output.strip : nil
|
|
93
|
+
rescue SystemCallError
|
|
94
|
+
nil
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def no_arguments!
|
|
98
|
+
raise OptionParser::NeedlessArgument, @argv.join(" ") if @argv.any?
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def run_init
|
|
102
|
+
rails = false
|
|
103
|
+
version_file = nil
|
|
104
|
+
with_help do
|
|
105
|
+
parse("init [--rails] [--version-file PATH]") do |parser|
|
|
106
|
+
parser.on("--rails", "Add an app surface for Rails views and routes") { rails = true }
|
|
107
|
+
parser.on("--version-file PATH", "A Ruby file with VERSION = \"x.y.z\" to bump on release") { |path| version_file = path }
|
|
108
|
+
end
|
|
109
|
+
no_arguments!
|
|
110
|
+
@root ||= @cwd
|
|
111
|
+
Init.new(root, rails: rails, version_file: version_file).call.each { |path| @out.puts("created #{path}") }
|
|
112
|
+
0
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def run_new
|
|
117
|
+
values = {}
|
|
118
|
+
slug = nil
|
|
119
|
+
with_help do
|
|
120
|
+
parse("new [--FIELD VALUE ...] [--slug SLUG]") do |parser|
|
|
121
|
+
# Field flags come from the config, so the config is read first.
|
|
122
|
+
root_index = @argv.index("--root")
|
|
123
|
+
root_value = root_index ? @argv[root_index + 1] : @argv.find { |arg| arg.start_with?("--root=") }&.delete_prefix("--root=")
|
|
124
|
+
@root = File.expand_path(root_value, @cwd) if root_value
|
|
125
|
+
config.fields.each_value do |field|
|
|
126
|
+
flag = "--#{field.name.tr('_', '-')} VALUE"
|
|
127
|
+
parser.on(flag, field.description || "Set #{field.name}") { |value| values[field.name] = value }
|
|
128
|
+
end
|
|
129
|
+
parser.on("--field NAME=VALUE", "Set any field") do |pair|
|
|
130
|
+
name, value = pair.split("=", 2)
|
|
131
|
+
raise OptionParser::InvalidArgument, pair unless value
|
|
132
|
+
|
|
133
|
+
values[name] = value
|
|
134
|
+
end
|
|
135
|
+
parser.on("--slug SLUG", "File name for the entry (default: from the title)") { |value| slug = value }
|
|
136
|
+
end
|
|
137
|
+
no_arguments!
|
|
138
|
+
path = EntryWriter.new(config, input: @input, output: @out).call(values: values, slug: slug)
|
|
139
|
+
@out.puts("created #{path}")
|
|
140
|
+
0
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def run_status
|
|
145
|
+
with_help do
|
|
146
|
+
parse("status")
|
|
147
|
+
no_arguments!
|
|
148
|
+
repository = Repository.new(config)
|
|
149
|
+
entries = repository.entries
|
|
150
|
+
current = current_version(repository)
|
|
151
|
+
@out.puts("current version: #{current}") if current
|
|
152
|
+
if entries.empty?
|
|
153
|
+
@out.puts("no unreleased entries")
|
|
154
|
+
else
|
|
155
|
+
@out.puts("unreleased entries (#{entries.size}):")
|
|
156
|
+
bump = VersionBump.new(config.versioning)
|
|
157
|
+
entries.each do |entry|
|
|
158
|
+
level = config.versioning.semver? ? " [#{bump.level_for(entry) || 'none'}]" : ""
|
|
159
|
+
@out.puts(" #{entry.id}#{level}: #{entry.title}")
|
|
160
|
+
end
|
|
161
|
+
@out.puts("next version: #{next_version(repository) || current}") if config.versioning.semver?
|
|
162
|
+
end
|
|
163
|
+
problems = repository.problems
|
|
164
|
+
@out.puts("#{problems.size} problem(s); run `shipnotes lint`") if problems.any?
|
|
165
|
+
0
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def run_lint
|
|
170
|
+
with_help do
|
|
171
|
+
parse("lint")
|
|
172
|
+
no_arguments!
|
|
173
|
+
problems = Repository.new(config).problems
|
|
174
|
+
problems.each { |problem| @err.puts("✗ #{problem}") }
|
|
175
|
+
next 1 if problems.any?
|
|
176
|
+
|
|
177
|
+
@out.puts("✓ changelog entries are valid")
|
|
178
|
+
0
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def run_check
|
|
183
|
+
entry_required = true
|
|
184
|
+
oasdiff = nil
|
|
185
|
+
skip_label = nil
|
|
186
|
+
with_help do
|
|
187
|
+
parse("check BASE_REF [--skip-entry] [--skip-label NAME] [--oasdiff PATH]") do |parser|
|
|
188
|
+
parser.on("--skip-entry", "--no-entry-required", "Do not require an entry (other checks still run)") { entry_required = false }
|
|
189
|
+
parser.on("--skip-label NAME", "Skip the entry rule when the PR has this label (reads labels with gh)") { |name| skip_label = name }
|
|
190
|
+
parser.on("--oasdiff PATH", "oasdiff binary for OpenAPI contracts") { |path| oasdiff = path }
|
|
191
|
+
end
|
|
192
|
+
base = @argv.shift
|
|
193
|
+
raise OptionParser::MissingArgument, "BASE_REF" unless base
|
|
194
|
+
|
|
195
|
+
no_arguments!
|
|
196
|
+
if entry_required && skip_label && GitHubLabels.new(root, env: @env).include?(skip_label)
|
|
197
|
+
@out.puts(" the #{skip_label} label is set")
|
|
198
|
+
entry_required = false
|
|
199
|
+
end
|
|
200
|
+
result = Check.new(config, base: base, entry_required: entry_required, oasdiff: oasdiff).call
|
|
201
|
+
result.notes.each { |note| @out.puts(" #{note}") }
|
|
202
|
+
result.errors.each { |error| @err.puts("✗ #{error}") }
|
|
203
|
+
next 1 unless result.passed?
|
|
204
|
+
|
|
205
|
+
@out.puts("✓ shipnotes check passed against #{base}")
|
|
206
|
+
0
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def run_release
|
|
211
|
+
version = nil
|
|
212
|
+
date = nil
|
|
213
|
+
dry_run = false
|
|
214
|
+
with_help do
|
|
215
|
+
parse("release [--version X.Y.Z] [--date YYYY-MM-DD] [--dry-run]") do |parser|
|
|
216
|
+
parser.on("--version VERSION", "Use this version instead of the computed one (pre-releases too)") { |value| version = value }
|
|
217
|
+
parser.on("--date DATE", "Release date (default: today)") { |value| date = value }
|
|
218
|
+
parser.on("--dry-run", "Show what would change without writing") { dry_run = true }
|
|
219
|
+
end
|
|
220
|
+
no_arguments!
|
|
221
|
+
result = Releaser.new(config).call(version: version, date: date, dry_run: dry_run)
|
|
222
|
+
unless result
|
|
223
|
+
@out.puts("no unreleased entries; nothing to release")
|
|
224
|
+
next 0
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
prefix = dry_run ? "would release" : "released"
|
|
228
|
+
change = result.version && result.version != result.previous_version ? " (#{result.previous_version} -> #{result.version})" : ""
|
|
229
|
+
@out.puts("#{prefix} #{result.id}#{change} with #{result.entries.join(', ')}")
|
|
230
|
+
result.written.each { |path| @out.puts(" #{dry_run ? 'would write' : 'wrote'} #{path}") }
|
|
231
|
+
result.deleted.each { |path| @out.puts(" #{dry_run ? 'would delete' : 'deleted'} #{path}") }
|
|
232
|
+
0
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def run_render
|
|
237
|
+
output = nil
|
|
238
|
+
unreleased = false
|
|
239
|
+
with_help do
|
|
240
|
+
parse("render [--output PATH|-] [--unreleased]") do |parser|
|
|
241
|
+
parser.on("--output PATH", "Write here instead of render.output; - prints it") { |path| output = path }
|
|
242
|
+
parser.on("--unreleased", "Include an Unreleased section") { unreleased = true }
|
|
243
|
+
end
|
|
244
|
+
no_arguments!
|
|
245
|
+
renderer = Renderer.new(config)
|
|
246
|
+
if output == "-" || (output.nil? && config.render.output.nil?)
|
|
247
|
+
@out.print(renderer.changelog(unreleased: unreleased))
|
|
248
|
+
else
|
|
249
|
+
target = output || config.render.output
|
|
250
|
+
path = File.join(root, target)
|
|
251
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
252
|
+
File.write(path, renderer.changelog(unreleased: unreleased))
|
|
253
|
+
@out.puts("wrote #{target}")
|
|
254
|
+
end
|
|
255
|
+
0
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def run_notes
|
|
260
|
+
with_help do
|
|
261
|
+
parse("notes [RELEASE_ID|VERSION]")
|
|
262
|
+
wanted = @argv.shift
|
|
263
|
+
no_arguments!
|
|
264
|
+
releases = Repository.new(config).releases
|
|
265
|
+
release = wanted ? releases.find { |item| item.id == wanted || item.version == wanted.delete_prefix("v") } : releases.last
|
|
266
|
+
raise Error, wanted ? "no release #{wanted}" : "no releases yet" unless release
|
|
267
|
+
|
|
268
|
+
@out.print(Renderer.new(config).notes(release))
|
|
269
|
+
0
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def run_current
|
|
274
|
+
with_help do
|
|
275
|
+
parse("current")
|
|
276
|
+
no_arguments!
|
|
277
|
+
raise Error, "this project does not version releases" unless config.versioning.semver?
|
|
278
|
+
|
|
279
|
+
@out.puts(current_version(Repository.new(config)))
|
|
280
|
+
0
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def run_next
|
|
285
|
+
with_help do
|
|
286
|
+
parse("next")
|
|
287
|
+
no_arguments!
|
|
288
|
+
raise Error, "this project does not version releases" unless config.versioning.semver?
|
|
289
|
+
|
|
290
|
+
repository = Repository.new(config)
|
|
291
|
+
@out.puts(next_version(repository) || current_version(repository))
|
|
292
|
+
0
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def current_version(repository)
|
|
297
|
+
return nil unless config.versioning.semver?
|
|
298
|
+
|
|
299
|
+
versions = VersionTargets.new(config).read do |path|
|
|
300
|
+
full = File.join(root, path)
|
|
301
|
+
File.file?(full) ? File.read(full) : nil
|
|
302
|
+
end
|
|
303
|
+
Releaser.current_version(config, repository, versions)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def next_version(repository)
|
|
307
|
+
return nil if repository.entries.empty?
|
|
308
|
+
|
|
309
|
+
VersionBump.new(config.versioning).next_version(current_version(repository), repository.entries)
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
end
|