Module: Hoe::Package

Includes:
Rake::DSL
Defined in:
lib/hoe/package.rb

Overview

Package plugin for hoe.

Tasks Provided:

install_gem

Install the package as a gem.

prerelease

Hook for pre-release actions like sanity checks.

postrelease

Hook for post-release actions like release announcements.

release

Package and upload the release.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#need_tarObject

Optional: Should package create a tarball? [default: true]



28
29
30
# File 'lib/hoe/package.rb', line 28

def need_tar
  @need_tar
end

#need_zipObject

Optional: Should package create a zipfile? [default: false]



33
34
35
# File 'lib/hoe/package.rb', line 33

def need_zip
  @need_zip
end

Instance Method Details

#define_package_tasksObject

Define tasks for plugin.



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
# File 'lib/hoe/package.rb', line 46

def define_package_tasks
  prerelease_version

  Gem::PackageTask.new spec do |pkg|
    pkg.need_tar = @need_tar
    pkg.need_zip = @need_zip
  end

  task(:gem).prerequisites.prepend :clean

  desc "Install the package as a gem. (opt. NOSUDO=1)"
  task :install_gem => [:clean, :package, :check_extra_deps] do
    install_gem Dir["pkg/*.gem"].first
  end

  desc "Package and upload; Requires VERSION=x.y.z (optional PRE=a.1)"
  task :release => [:prerelease, :release_to, :postrelease]

  # no doco, invisible hook
  task :prerelease do
    abort "Fix your version before you release" if spec.version.to_s =~ /borked/
  end

  # no doco, invisible hook
  task :release_to

  # no doco, invisible hook
  task :postrelease

  desc "Sanity checks for release"
  task :release_sanity do
    v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"

    pre = ENV["PRERELEASE"] || ENV["PRE"]
    v += ".#{pre}" if pre

    c = changes[/\d\S+/]

    abort "Versions don't match: %s vs %s" % [v, version] if v != version
    abort "Versions don't match %s: %s vs %s" % [history_file, v, c] if v != c
  end

  desc "Push gem to package."
  task :release_to_rubygems => [:clean, :package, :release_sanity] do
    pkg   = "pkg/#{spec.name}-#{spec.version}"
    gems  = Dir["#{pkg}*.gem"]

    gem_push gems
  end

  task :release_to => :release_to_rubygems
end

#gem_push(gems) ⇒ Object

Push gems to server.



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/hoe/package.rb', line 142

def gem_push gems
  with_config do |config, _|
    otp_command = config["otp_command"]

    ENV["GEM_HOST_OTP_CODE"] = `#{otp_command}`.chomp if otp_command
  end

  gems.each do |g|
    sh Gem.ruby, "-S", "gem", "push", g
  end
end

#initialize_packageObject

Initialize variables for plugin.



38
39
40
41
# File 'lib/hoe/package.rb', line 38

def initialize_package
  self.need_tar ||= false
  self.need_zip ||= false
end

#install_gem(name, version = nil, rdoc = true) ⇒ Object

Install the named gem.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/hoe/package.rb', line 110

def install_gem name, version = nil, rdoc = true
  should_not_sudo = Hoe::WINDOZE || ENV["NOSUDO"] || File.writable?(Gem.dir)
  null_dev = Hoe::WINDOZE ? "> NUL 2>&1" : "> /dev/null 2>&1"

  sudo    = "sudo "                  unless should_not_sudo
  local   = "--local"                unless version
  version = "--version '#{version}'" if     version

  cmd  = "#{sudo}gem install #{local} #{name} #{version}"
  cmd += " --no-document" unless rdoc
  cmd += " #{null_dev}" unless Rake.application.options.trace

  result = sh cmd
  Gem::Specification.reset
  result
end

#pkg_pathObject

Returns the path used for packaging. Convenience method for those that need to write a package hook.



103
104
105
# File 'lib/hoe/package.rb', line 103

def pkg_path
  "pkg/#{spec.full_name}"
end

#prerelease_versionObject

:nodoc:



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/hoe/package.rb', line 127

def prerelease_version # :nodoc:
  pre = ENV["PRERELEASE"] || ENV["PRE"]

  return unless pre

  spec.version = "#{spec.version}.#{pre}"

  abort "ERROR: You should format PRE like pre or alpha.1 or something" if
    (Gem::VERSION < "1.4"  and pre !~ /^[a-z]+(\.\d+)?$/) or
    (Gem::VERSION >= "1.4" and pre !~ /^[a-z]+(\.?\d+)?$/)
end