Class: Harbor::CLI::Promote

Inherits:
Object
  • Object
show all
Defined in:
lib/harbor/cli/promote.rb

Overview

harbor promote — build + push the current gem version to RubyGems. The channel (stable vs edge) is inferred from the gem version string, not passed as a flag: RubyGems already treats pre-release versions (‘1.0.1.pre1`, `1.0.1.beta`, `1.0.1.rc1`) as separate from stable versions by default. Daemons on `HARBOR_AGENT_CHANNEL=edge` opt into pre-release versions via `gem update –pre`; stable daemons use `gem update` which skips pre-release by default.

Workflow:

1. Edit lib/harbor/version.rb to bump VERSION (pre for edge, clean semver for stable)
2. Commit + tag
3. harbor promote --dry-run   # verify
4. harbor promote              # publish

Constant Summary collapse

PRE_RELEASE_RE =
/\.(pre|beta|rc|alpha)\d*\z/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Promote

Returns a new instance of Promote.



27
28
29
# File 'lib/harbor/cli/promote.rb', line 27

def initialize(options = {})
  @options = options
end

Class Method Details

.infer_channel(version) ⇒ Object



23
24
25
# File 'lib/harbor/cli/promote.rb', line 23

def self.infer_channel(version)
  version.match?(PRE_RELEASE_RE) ? "edge" : "stable"
end

Instance Method Details

#runObject



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
# File 'lib/harbor/cli/promote.rb', line 31

def run
  version = Harbor::VERSION
  channel = self.class.infer_channel(version)

  puts "harbor-deploy v#{version}"
  puts "Detected channel: #{channel}"
  puts "  (pre-release versions → edge; clean semver → stable)"
  puts ""

  if @options[:dry_run]
    puts "DRY RUN — would run:"
    puts "  gem build harbor.gemspec"
    puts "  gem push harbor-deploy-#{version}.gem"
    puts ""
    puts "Hosts with HARBOR_AGENT_CHANNEL=#{channel} (or equivalent) would pick this up"
    puts "on the next hourly auto-upgrade poll."
    return 0
  end

  unless @options[:yes]
    print "Push harbor-deploy-#{version}.gem to RubyGems (#{channel} channel)? [y/N] "
    answer = $stdin.gets&.strip&.downcase
    unless answer == "y" || answer == "yes"
      puts "Aborted."
      return 1
    end
  end

  puts "Building gem..."
  build_out, build_err, build_status = Open3.capture3("gem", "build", "harbor.gemspec")
  unless build_status.success?
    warn "Build failed:"
    warn build_err
    return 1
  end
  puts build_out.strip

  gem_file = "harbor-deploy-#{version}.gem"
  unless File.exist?(gem_file)
    warn "Built gem not found at expected path: #{gem_file}"
    return 1
  end

  puts "Pushing to RubyGems..."
  push_out, push_err, push_status = Open3.capture3("gem", "push", gem_file)
  if push_status.success?
    puts push_out
    puts ""
    puts "Done. Pushed harbor-deploy-#{version} to the #{channel} channel."
    File.delete(gem_file)
    0
  else
    warn "Push failed:"
    warn push_err
    warn ""
    warn "Built gem left at #{gem_file} for manual retry."
    1
  end
end