Class: Inquirex::Tools::Versions

Inherits:
Object
  • Object
show all
Defined in:
lib/inquirex/tools/versions.rb

Overview

Reports and enforces version parity across the lockstep packages.

Examples:

Check for drift

Inquirex::Tools::Versions.new.check   # => false when versions differ

Instance Method Summary collapse

Constructor Details

#initialize(workspace: Workspace.new, out: $stdout) ⇒ Versions

Returns a new instance of Versions.

Parameters:

  • workspace (Workspace) (defaults to: Workspace.new)
  • out (IO) (defaults to: $stdout)

    where report output goes



15
16
17
18
# File 'lib/inquirex/tools/versions.rb', line 15

def initialize(workspace: Workspace.new, out: $stdout)
  @workspace = workspace
  @out = out
end

Instance Method Details

#checkBoolean

Prints the current state of every lockstep package.

Returns:

  • (Boolean)

    true when all packages agree on one version



23
24
25
26
27
# File 'lib/inquirex/tools/versions.rb', line 23

def check
  versions = @workspace.versions
  print_table(versions)
  verdict(versions)
end

#preflightBoolean

Parity plus git readiness: clean tree, on main, tagged at the version.

Returns:

  • (Boolean)

    true when every package could be published now



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/inquirex/tools/versions.rb', line 62

def preflight
  ok = check
  target = @workspace.versions.values.compact.uniq.first
  @out.puts
  @out.puts "Release readiness:"

  Workspace::LOCKSTEP.each_key do |name|
    problems = readiness_problems(name, target)
    @out.puts format("  %<name>-16s %<state>s", name: name, state: problems.empty? ? "ready" : problems.join(", "))
    ok &&= problems.empty?
  end

  @out.puts
  @out.puts ok ? "ALL READY — publish with `gem push` / `npm publish`" : "NOT READY — resolve the above"
  ok
end

#set(version) ⇒ Boolean

Moves every lockstep package to one version.

Refuses to move backwards: a version already published cannot be reissued, so the target must exceed every current value.

Parameters:

  • version (String)

    target, MAJOR.MINOR.PATCH

Returns:

  • (Boolean)

    true when written



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/inquirex/tools/versions.rb', line 36

def set(version)
  unless /\A\d+\.\d+\.\d+\z/.match?(version.to_s)
    @out.puts "ERROR: #{version.inspect} is not MAJOR.MINOR.PATCH"
    return false
  end

  current = @workspace.versions.values.compact
  highest = current.max_by { Gem::Version.new(_1) }
  if highest && Gem::Version.new(highest) > Gem::Version.new(version)
    @out.puts "ERROR: #{version} is below the highest existing version (#{highest}) — versions only go forward"
    return false
  end

  @out.puts "Setting all lockstep packages to #{version}:"
  @workspace.versions.each do |name, was|
    @workspace.write_version(name, version)
    @out.puts format("  %-16s %s -> %s", name, was || "?", version)
  end
  @out.puts
  @out.puts "Unchanged (excluded): #{Workspace::EXCLUDED.join(", ")}"
  true
end