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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +10 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +265 -0
  5. data/app/controllers/shipnotes/releases_controller.rb +61 -0
  6. data/app/helpers/shipnotes/releases_helper.rb +38 -0
  7. data/app/views/layouts/shipnotes/application.html.erb +24 -0
  8. data/app/views/shipnotes/releases/index.atom.builder +20 -0
  9. data/app/views/shipnotes/releases/index.html.erb +51 -0
  10. data/config/routes.rb +7 -0
  11. data/exe/shipnotes +7 -0
  12. data/lib/shipnotes/check.rb +218 -0
  13. data/lib/shipnotes/cli.rb +312 -0
  14. data/lib/shipnotes/config.rb +278 -0
  15. data/lib/shipnotes/differs/json_schema.rb +45 -0
  16. data/lib/shipnotes/differs/mcp_tools.rb +50 -0
  17. data/lib/shipnotes/differs/openapi.rb +55 -0
  18. data/lib/shipnotes/differs.rb +33 -0
  19. data/lib/shipnotes/engine.rb +44 -0
  20. data/lib/shipnotes/engine_configuration.rb +21 -0
  21. data/lib/shipnotes/entry.rb +18 -0
  22. data/lib/shipnotes/entry_writer.rb +116 -0
  23. data/lib/shipnotes/field.rb +55 -0
  24. data/lib/shipnotes/finding.rb +7 -0
  25. data/lib/shipnotes/git_diff.rb +65 -0
  26. data/lib/shipnotes/github_labels.rb +28 -0
  27. data/lib/shipnotes/init.rb +69 -0
  28. data/lib/shipnotes/publication.rb +46 -0
  29. data/lib/shipnotes/release.rb +32 -0
  30. data/lib/shipnotes/releaser.rb +128 -0
  31. data/lib/shipnotes/renderer.rb +92 -0
  32. data/lib/shipnotes/repository.rb +100 -0
  33. data/lib/shipnotes/schema.rb +82 -0
  34. data/lib/shipnotes/semver.rb +83 -0
  35. data/lib/shipnotes/source.rb +47 -0
  36. data/lib/shipnotes/surface.rb +32 -0
  37. data/lib/shipnotes/templates/changelog.md.erb +11 -0
  38. data/lib/shipnotes/templates/release_notes.md.erb +1 -0
  39. data/lib/shipnotes/version.rb +5 -0
  40. data/lib/shipnotes/version_bump.rb +34 -0
  41. data/lib/shipnotes/version_targets.rb +70 -0
  42. data/lib/shipnotes/yaml_file.rb +22 -0
  43. data/lib/shipnotes.rb +52 -0
  44. metadata +91 -0
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipnotes
4
+ class Schema
5
+ RELEASE_KEYS = %w[release date version entries].freeze
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def entry_errors(data)
12
+ return [ "must be a mapping" ] unless data.is_a?(Hash)
13
+
14
+ fields = @config.fields
15
+ errors = []
16
+ unknown = data.keys - fields.keys
17
+ errors << "unknown fields: #{unknown.join(', ')}" if unknown.any?
18
+ fields.each_value do |field|
19
+ value = data[field.name]
20
+ if Field.blank?(value)
21
+ errors << "#{field.name} is required" if field.required
22
+ else
23
+ errors.concat(field.errors(value))
24
+ end
25
+ end
26
+ errors.concat(rule_errors(data))
27
+ end
28
+
29
+ def release_errors(data, file_name)
30
+ return [ "must be a mapping" ] unless data.is_a?(Hash)
31
+
32
+ errors = []
33
+ unknown = data.keys - RELEASE_KEYS
34
+ errors << "unknown fields: #{unknown.join(', ')}" if unknown.any?
35
+ id = data["release"].to_s
36
+ errors << "release id is missing" if id.empty?
37
+ errors << "release #{id} does not match its file name" unless file_name == "#{id}.yml"
38
+ errors << "date must be a YYYY-MM-DD date" unless Field.date?(data["date"])
39
+ errors.concat(release_id_errors(data, id))
40
+ entries = data["entries"]
41
+ return errors << "entries must be a non-empty list" unless entries.is_a?(Array) && entries.any?
42
+
43
+ entries.each_with_index do |entry, index|
44
+ unless entry.is_a?(Hash) && entry["id"].to_s.match?(Entry::SLUG)
45
+ errors << "entries[#{index}] needs a slug id"
46
+ next
47
+ end
48
+ entry_errors(entry.except("id")).each { |error| errors << "entries[#{index}] (#{entry['id']}): #{error}" }
49
+ end
50
+ errors
51
+ end
52
+
53
+ private
54
+
55
+ def release_id_errors(data, id)
56
+ errors = []
57
+ version = data["version"]
58
+ errors << "version must be a MAJOR.MINOR.PATCH version" if version && !Semver.valid?(version)
59
+ if (match = id.match(Release::DATE_ID))
60
+ errors << "date #{data['date']} does not match release #{id}" unless data["date"].to_s == match.captures.first(3).join("-")
61
+ elsif Semver.valid?(id)
62
+ errors << "version #{version.inspect} does not match release #{id}" unless version == id
63
+ else
64
+ errors << "release must be a version or a YYYY.MM.DD.N id"
65
+ end
66
+ errors
67
+ end
68
+
69
+ def rule_errors(data)
70
+ @config.rules.flat_map do |rule|
71
+ next [] unless rule.when.all? { |name, values| (Array(data[name]).map(&:to_s) & values).any? }
72
+
73
+ condition = rule.when.map { |name, values| "#{name} #{values.join('/')}" }.join(", ")
74
+ missing = rule.require.select { |name| Field.blank?(data[name]) }
75
+ rejected = rule.reject.select { |name, values| values.include?(data[name].to_s.strip) }.keys
76
+ problems = missing.map { |name| "#{name} is required when #{condition}" } +
77
+ rejected.map { |name| "#{name} cannot be #{data[name].to_s.strip.inspect} when #{condition}" }
78
+ rule.message && problems.any? ? [ rule.message ] : problems
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipnotes
4
+ Semver = Data.define(:major, :minor, :patch, :pre)
5
+
6
+ class Semver
7
+ include Comparable
8
+
9
+ PRE_ID = /(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)/
10
+ PATTERN = /\A(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(#{PRE_ID}(?:\.#{PRE_ID})*))?\z/
11
+ LEVELS = %i[major minor patch].freeze
12
+
13
+ def self.parse(value)
14
+ match = value.to_s.match(PATTERN)
15
+ raise Error, "#{value.inspect} is not a MAJOR.MINOR.PATCH version" unless match
16
+
17
+ new(major: match[1].to_i, minor: match[2].to_i, patch: match[3].to_i, pre: match[4])
18
+ end
19
+
20
+ def self.valid?(value) = value.to_s.match?(PATTERN)
21
+
22
+ # A pre-release lands on its core when the core already carries the level
23
+ # (2.0.0-rc.1 -> 2.0.0 for major), else bumps as usual (1.1.0-rc.1 -> 2.0.0).
24
+ def bump(level)
25
+ return nil unless level
26
+ return core if pre? && core_carries?(level)
27
+
28
+ case level
29
+ when :major then with(major: major + 1, minor: 0, patch: 0, pre: nil)
30
+ when :minor then with(minor: minor + 1, patch: 0, pre: nil)
31
+ when :patch then with(patch: patch + 1, pre: nil)
32
+ else raise ArgumentError, "unknown bump level: #{level.inspect}"
33
+ end
34
+ end
35
+
36
+ def pre? = !pre.nil?
37
+ def core = with(pre: nil)
38
+
39
+ def <=>(other)
40
+ return nil unless other.is_a?(Semver)
41
+
42
+ result = [ major, minor, patch ] <=> [ other.major, other.minor, other.patch ]
43
+ return result unless result.zero?
44
+ return 0 if pre == other.pre
45
+ return 1 if pre.nil?
46
+ return -1 if other.pre.nil?
47
+
48
+ compare_pre(pre.split("."), other.pre.split("."))
49
+ end
50
+
51
+ def to_s = pre ? "#{major}.#{minor}.#{patch}-#{pre}" : "#{major}.#{minor}.#{patch}"
52
+
53
+ private
54
+
55
+ def core_carries?(level)
56
+ case level
57
+ when :major then minor.zero? && patch.zero?
58
+ when :minor then patch.zero?
59
+ else true
60
+ end
61
+ end
62
+
63
+ def compare_pre(left, right)
64
+ left.zip(right).each do |a, b|
65
+ return 1 if b.nil?
66
+
67
+ result = identifier_order(a, b)
68
+ return result unless result.zero?
69
+ end
70
+ left.size <=> right.size
71
+ end
72
+
73
+ def identifier_order(a, b)
74
+ numeric_a = a.match?(/\A\d+\z/)
75
+ numeric_b = b.match?(/\A\d+\z/)
76
+ return a.to_i <=> b.to_i if numeric_a && numeric_b
77
+ return -1 if numeric_a
78
+ return 1 if numeric_b
79
+
80
+ a <=> b
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipnotes
4
+ # Where changelog files are read from: the working tree, or one git revision
5
+ # so the PR check can read the base and head side by side.
6
+ module Source
7
+ class Filesystem
8
+ attr_reader :root
9
+
10
+ def initialize(root)
11
+ @root = File.expand_path(root.to_s)
12
+ end
13
+
14
+ def list(directory)
15
+ base = File.join(root, directory)
16
+ Dir.glob(File.join(base, "**", "*"), File::FNM_DOTMATCH)
17
+ .reject { |path| File.directory?(path) }
18
+ .map { |path| path.delete_prefix("#{root}/") }
19
+ .sort
20
+ end
21
+
22
+ def read(path)
23
+ full = File.join(root, path)
24
+ File.file?(full) ? File.read(full) : nil
25
+ end
26
+ end
27
+
28
+ class GitRevision
29
+ attr_reader :root, :revision
30
+
31
+ def initialize(root, revision)
32
+ @root = File.expand_path(root.to_s)
33
+ @revision = revision
34
+ end
35
+
36
+ def list(directory)
37
+ output, _error, status = Open3.capture3("git", "ls-tree", "-r", "--name-only", revision, "--", "#{directory}/", chdir: root)
38
+ status.success? ? output.lines.map(&:chomp).sort : []
39
+ end
40
+
41
+ def read(path)
42
+ output, _error, status = Open3.capture3("git", "show", "#{revision}:#{path}", chdir: root)
43
+ status.success? ? output : nil
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipnotes
4
+ Surface = Data.define(:key, :title, :description, :paths, :exclude, :contract)
5
+
6
+ class Surface
7
+ Contract = Data.define(:file, :differ)
8
+ GLOB = /[*?\[{]/
9
+ FLAGS = File::FNM_PATHNAME | File::FNM_EXTGLOB | File::FNM_DOTMATCH
10
+
11
+ # A glob ending in "/**" means everything below, and a plain path means
12
+ # the file itself or anything under that directory.
13
+ def self.glob_match?(pattern, path)
14
+ pattern = pattern.delete_prefix("./")
15
+ return path == pattern || path.start_with?("#{pattern.chomp('/')}/") unless pattern.match?(GLOB)
16
+
17
+ pattern = "#{pattern}/*" if pattern.end_with?("/**")
18
+ File.fnmatch?(pattern, path, FLAGS)
19
+ end
20
+
21
+ def match?(path)
22
+ return true if contract && contract.file == path
23
+ return false if exclude.any? { |pattern| self.class.glob_match?(pattern, path) }
24
+
25
+ paths.any? { |pattern| self.class.glob_match?(pattern, path) }
26
+ end
27
+ end
28
+
29
+ Trigger = Data.define(:name, :pattern, :paths, :surface) do
30
+ def path_match?(path) = paths.empty? || paths.any? { |pattern| Surface.glob_match?(pattern, path) }
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # <%= title %>
2
+ <% if unreleased.any? -%>
3
+
4
+ ## [Unreleased]
5
+ <%= section(unreleased) -%>
6
+ <% end -%>
7
+ <% releases.each do |release| -%>
8
+
9
+ ## <%= release_heading(release) %>
10
+ <%= section(release.entries) -%>
11
+ <% end -%>
@@ -0,0 +1 @@
1
+ <%= section(release.entries, level: 2) -%>
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipnotes
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipnotes
4
+ class VersionBump
5
+ def initialize(versioning)
6
+ @versioning = versioning
7
+ end
8
+
9
+ # An explicit `bump` on the entry wins over the field mapping and over the
10
+ # surface filter.
11
+ def level_for(entry)
12
+ explicit = entry["bump"]
13
+ return explicit == "none" ? nil : explicit.to_sym if explicit
14
+ return nil if @versioning.bump_surfaces && (entry.surfaces & @versioning.bump_surfaces).empty?
15
+ return nil unless @versioning.bump_field
16
+
17
+ levels = Array(entry[@versioning.bump_field]).filter_map { |value| @versioning.levels[value.to_s] }
18
+ Semver::LEVELS.find { |level| levels.include?(level.to_s) }
19
+ end
20
+
21
+ def level(entries)
22
+ levels = entries.map { |entry| level_for(entry) }
23
+ Semver::LEVELS.find { |level| levels.include?(level) }
24
+ end
25
+
26
+ # Version-named releases need a new version every time, so they take at
27
+ # least a patch.
28
+ def next_version(current, entries)
29
+ level = level(entries)
30
+ level ||= :patch if @versioning.version_ids?
31
+ Semver.parse(current).bump(level)&.to_s
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipnotes
4
+ class VersionTargets
5
+ Error = Class.new(Shipnotes::Error)
6
+
7
+ def initialize(config)
8
+ @files = config.versioning.files
9
+ end
10
+
11
+ def paths = @files.map(&:path)
12
+ def any? = @files.any?
13
+
14
+ # Yields each relative path for its text, so the same code reads the
15
+ # working tree or a git revision. Missing files are left out.
16
+ def read
17
+ @files.each_with_object({}) do |file, versions|
18
+ text = yield(file.path)
19
+ next unless text
20
+
21
+ versions[file.label] = extract(file, text)
22
+ end
23
+ end
24
+
25
+ # Every file is rewritten in memory first, so one bad file leaves all of them untouched.
26
+ def write(root, version)
27
+ contents = @files.map do |file|
28
+ path = File.join(root, file.path)
29
+ raise Error, "#{file.path} does not exist" unless File.file?(path)
30
+
31
+ [ path, replace(file, File.read(path), version) ]
32
+ end
33
+ contents.each { |path, text| File.write(path, text) }
34
+ end
35
+
36
+ private
37
+
38
+ def extract(file, text)
39
+ if file.json
40
+ JSON.parse(text).dig(*file.json)&.to_s
41
+ else
42
+ match = text.match(file.pattern)
43
+ match && (match.names.include?("version") ? match[:version] : match[1])
44
+ end
45
+ rescue JSON::ParserError => error
46
+ raise Error, "#{file.path} is not valid JSON: #{error.message}"
47
+ end
48
+
49
+ def replace(file, text, version)
50
+ return replace_json(file, text, version) if file.json
51
+
52
+ matches = text.to_enum(:scan, file.pattern).map { Regexp.last_match }
53
+ raise Error, "#{file.path} must match its pattern exactly once (found #{matches.size})" unless matches.size == 1
54
+
55
+ match = matches.first
56
+ group = match.names.include?("version") ? "version" : 1
57
+ text[0...match.begin(group)] + version + text[match.end(group)..]
58
+ end
59
+
60
+ def replace_json(file, text, version)
61
+ document = JSON.parse(text)
62
+ *parents, key = file.json
63
+ target = parents.empty? ? document : document.dig(*parents)
64
+ raise Error, "#{file.path} has no #{file.json.join('.')}" unless target.is_a?(Hash) && target.key?(key)
65
+
66
+ target[key] = version
67
+ "#{JSON.pretty_generate(document)}\n"
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipnotes
4
+ module YamlFile
5
+ module_function
6
+
7
+ def parse(text)
8
+ normalize(YAML.safe_load(text.to_s, permitted_classes: [ Date ], aliases: false))
9
+ end
10
+
11
+ def dump(value) = YAML.dump(value)
12
+
13
+ def normalize(value)
14
+ case value
15
+ when Hash then value.to_h { |key, nested| [ key.to_s, normalize(nested) ] }
16
+ when Array then value.map { |item| normalize(item) }
17
+ when Date then value.iso8601
18
+ else value
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/shipnotes.rb ADDED
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "erb"
5
+ require "fileutils"
6
+ require "json"
7
+ require "open3"
8
+ require "yaml"
9
+
10
+ module Shipnotes
11
+ Error = Class.new(StandardError)
12
+
13
+ class << self
14
+ def configuration
15
+ @configuration ||= EngineConfiguration.new
16
+ end
17
+
18
+ def configure
19
+ yield configuration
20
+ end
21
+ end
22
+ end
23
+
24
+ require_relative "shipnotes/version"
25
+ require_relative "shipnotes/semver"
26
+ require_relative "shipnotes/yaml_file"
27
+ require_relative "shipnotes/surface"
28
+ require_relative "shipnotes/field"
29
+ require_relative "shipnotes/config"
30
+ require_relative "shipnotes/entry"
31
+ require_relative "shipnotes/release"
32
+ require_relative "shipnotes/source"
33
+ require_relative "shipnotes/schema"
34
+ require_relative "shipnotes/repository"
35
+ require_relative "shipnotes/version_bump"
36
+ require_relative "shipnotes/version_targets"
37
+ require_relative "shipnotes/renderer"
38
+ require_relative "shipnotes/releaser"
39
+ require_relative "shipnotes/git_diff"
40
+ require_relative "shipnotes/finding"
41
+ require_relative "shipnotes/differs/json_schema"
42
+ require_relative "shipnotes/differs/mcp_tools"
43
+ require_relative "shipnotes/differs/openapi"
44
+ require_relative "shipnotes/differs"
45
+ require_relative "shipnotes/check"
46
+ require_relative "shipnotes/github_labels"
47
+ require_relative "shipnotes/publication"
48
+ require_relative "shipnotes/entry_writer"
49
+ require_relative "shipnotes/init"
50
+ require_relative "shipnotes/cli"
51
+ require_relative "shipnotes/engine_configuration"
52
+ require_relative "shipnotes/engine" if defined?(Rails::Engine)
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shipnotes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - TechWright Labs
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2026-12-01 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: One YAML file per change, a pull request check that knows which entries
13
+ a diff needs, semantic version bumps computed from the entries, breaking-change
14
+ detection for OpenAPI and MCP contracts, a rendered CHANGELOG.md, and an optional
15
+ Rails engine that publishes the changelog as HTML, JSON and Atom.
16
+ email:
17
+ - engineering@techwright.io
18
+ executables:
19
+ - shipnotes
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - CHANGELOG.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - app/controllers/shipnotes/releases_controller.rb
27
+ - app/helpers/shipnotes/releases_helper.rb
28
+ - app/views/layouts/shipnotes/application.html.erb
29
+ - app/views/shipnotes/releases/index.atom.builder
30
+ - app/views/shipnotes/releases/index.html.erb
31
+ - config/routes.rb
32
+ - exe/shipnotes
33
+ - lib/shipnotes.rb
34
+ - lib/shipnotes/check.rb
35
+ - lib/shipnotes/cli.rb
36
+ - lib/shipnotes/config.rb
37
+ - lib/shipnotes/differs.rb
38
+ - lib/shipnotes/differs/json_schema.rb
39
+ - lib/shipnotes/differs/mcp_tools.rb
40
+ - lib/shipnotes/differs/openapi.rb
41
+ - lib/shipnotes/engine.rb
42
+ - lib/shipnotes/engine_configuration.rb
43
+ - lib/shipnotes/entry.rb
44
+ - lib/shipnotes/entry_writer.rb
45
+ - lib/shipnotes/field.rb
46
+ - lib/shipnotes/finding.rb
47
+ - lib/shipnotes/git_diff.rb
48
+ - lib/shipnotes/github_labels.rb
49
+ - lib/shipnotes/init.rb
50
+ - lib/shipnotes/publication.rb
51
+ - lib/shipnotes/release.rb
52
+ - lib/shipnotes/releaser.rb
53
+ - lib/shipnotes/renderer.rb
54
+ - lib/shipnotes/repository.rb
55
+ - lib/shipnotes/schema.rb
56
+ - lib/shipnotes/semver.rb
57
+ - lib/shipnotes/source.rb
58
+ - lib/shipnotes/surface.rb
59
+ - lib/shipnotes/templates/changelog.md.erb
60
+ - lib/shipnotes/templates/release_notes.md.erb
61
+ - lib/shipnotes/version.rb
62
+ - lib/shipnotes/version_bump.rb
63
+ - lib/shipnotes/version_targets.rb
64
+ - lib/shipnotes/yaml_file.rb
65
+ homepage: https://github.com/techwright-lab/shipnotes
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ rubygems_mfa_required: 'true'
70
+ source_code_uri: https://github.com/techwright-lab/shipnotes
71
+ documentation_uri: https://techwright-lab.github.io/shipnotes/
72
+ changelog_uri: https://techwright-lab.github.io/shipnotes/changelog/
73
+ bug_tracker_uri: https://github.com/techwright-lab/shipnotes/issues
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '3.2'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 4.0.20
89
+ specification_version: 4
90
+ summary: Changelog entries as files, checked in CI, released with a computed version
91
+ test_files: []