Module: Hoe::Halostatue

Defined in:
lib/hoe/halostatue.rb,
lib/hoe/halostatue/version.rb

Overview

This module is a Hoe plugin. You can set its options in your Rakefile Hoe spec, like this:

Hoe.plugin :git

Hoe.spec "myproj" do
  self.checklist = nil if ENV["rubygems_release_gem"] == "true"
  self.git_release_tag_prefix = "REL_"
  self.git_remotes << "myremote"
end

Tasks

git:changelog

Print the current changelog.

git:manifest

Update the manifest with Git’s file list.

git:tag

Create and push a tag.

Options

  • checklist: An array of reminder questions that should be asked before a release, in the form, “Did you… [question]?” You can see the defaults by running rake checklist. If the checklist is nil or empty, the checklist will not shown during release. This is originally from hoe-doofus and called doofus_checklist.

  • git_release_tag_prefix: What do you want at the front of your release tags? The default is "v".

  • git_remotes: Which remotes do you want to push tags, etc. to? The default is %w[origin]

  • git_tag_enabled: Whether a git tag should be created on release. The default is true.

Defined Under Namespace

Modules: ParseUrls

Constant Summary collapse

VERSION =
"2.1.1"
/\[(?<name>.+?)\](?:\(.+?\)|\[.+?\])/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#checklistObject

An array of reminder questions that should be asked before a release, in the form, “Did you… [question]?” You can see the defaults by running rake checklist.

If the checklist is nil or empty, the checklist will not shown during release.



51
52
53
# File 'lib/hoe/halostatue.rb', line 51

def checklist
  @checklist
end

#git_release_tag_prefixObject

What do you want at the front of your release tags?

default: "v"


55
56
57
# File 'lib/hoe/halostatue.rb', line 55

def git_release_tag_prefix
  @git_release_tag_prefix
end

#git_remotesObject

Which remotes do you want to push tags, etc. to?

default: %w[origin]


59
60
61
# File 'lib/hoe/halostatue.rb', line 59

def git_remotes
  @git_remotes
end

#git_tag_enabledObject

Should git tags be created on release? [default: true]



62
63
64
# File 'lib/hoe/halostatue.rb', line 62

def git_tag_enabled
  @git_tag_enabled
end

#trusted_releaseObject

Indicates that this release is being run as part of a trusted release workflow.

default: false


45
46
47
# File 'lib/hoe/halostatue.rb', line 45

def trusted_release
  @trusted_release
end

Instance Method Details

#__git(command, *params) ⇒ Object



181
182
183
# File 'lib/hoe/halostatue.rb', line 181

def __git(command, *params)
  "git #{command.shellescape} #{params.compact.shelljoin}"
end

#__run_git(command, *params) ⇒ Object



185
186
187
# File 'lib/hoe/halostatue.rb', line 185

def __run_git(command, *params)
  `#{__git(command, *params)}`.strip.chomp
end

#define_halostatue_tasksObject

:nodoc:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/hoe/halostatue.rb', line 100

def define_halostatue_tasks # :nodoc:
  desc "Show a reminder for steps I frequently forget"
  task :checklist do
    if checklist.nil? || checklist.empty?
      puts "Checklist is empty."
    else
      puts "\n### HEY! Did you...\n\n"

      checklist.each do |question|
        question = question[0..0].upcase + question[1..]
        question = "#{question}?" unless question.end_with?("?")
        puts "  * #{question}"
      end

      puts
    end
  end

  task :release_sanity do
    unless checklist.nil? || checklist.empty? || trusted_release
      Rake::Task[:checklist].invoke
      puts "Hit return if you're sure, Ctrl-C if you forgot something."
      $stdin.gets
    end
  end

  task :spec_clean_markdown_links do
    spec.description = spec.description.gsub(LINKS, '\k<name>').gsub(/\r?\n/, " ")
    spec.summary = spec.summary.gsub(LINKS, '\k<name>').gsub(/\r?\n/, " ")
  end

  task "#{spec.name}.gemspec" => :spec_clean_markdown_links

  if trusted_release
    task :trusted_release do
      vm = %r{^(?<version>\d+(?:\.\d+)+)(?:\.(?<pre>[a-z]\w+(?:\.\d+)+))?}
        .match(spec.version.to_s)

      ENV["VERSION"] = vm[:version]
      ENV["PRERELEASE"] = vm[:pre]
    end

    task release_sanity: :trusted_release
  end

  return unless __run_git("rev-parse", "--is-inside-work-tree") == "true"

  desc "Update the manifest with Git's file list. Use Hoe's excludes."
  task "git:manifest" do
    with_config do |config, _|
      files = __run_git("ls-files").split($/)
      files.reject! { |f| f =~ config["exclude"] }

      File.open "Manifest.txt", "w" do |f|
        f.puts files.sort.join("\n")
      end
    end
  end

  desc "Create and push a TAG (default #{git_release_tag_prefix}#{version})."
  task "git:tag" do
    if git_tag_enabled
      tag = ENV["TAG"]
      ver = ENV["VERSION"] || version
      pre = ENV["PRERELEASE"] || ENV["PRE"]
      ver += ".#{pre}" if pre
      tag ||= "#{git_release_tag_prefix}#{ver}"

      git_tag_and_push tag
    end
  end

  task :release_sanity do
    unless __run_git("status", "--porcelain").empty?
      abort "Won't release: Dirty index or untracked files present!"
    end
  end

  task release_to: "git:tag"
end

#git_svn?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/hoe/halostatue.rb', line 189

def git_svn?
  File.exist?(File.join(__run_git("rev-parse", "--show-toplevel"), ".git/svn"))
end

#git_tag_and_push(tag) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/hoe/halostatue.rb', line 193

def git_tag_and_push tag
  msg = "Tagging #{tag}."

  if git_svn?
    sh __git("svn", "tag", tag, "-m", msg)
  else
    flags =
      if __run_git("config", "--get", "user.signingkey").empty?
        nil
      else
        "-s"
      end

    sh __git("tag", flags, "-f", tag, "-m", msg)
    git_remotes.each { |remote| sh __git("push", "-f", remote, "tag", tag) }
  end
end

#initialize_halostatueObject

:nodoc:



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

def initialize_halostatue # :nodoc:
  Hoe::URLS_TO_META_MAP.update({
    "bugs" => "bug_tracker_uri",
    "changelog" => "changelog_uri",
    "changes" => "changelog_uri",
    "clog" => "changelog_uri",
    "code" => "source_code_uri",
    "doco" => "documentation_uri",
    "docs" => "documentation_uri",
    "documentation" => "documentation_uri",
    "history" => "changelog_uri",
    "home" => "homepage_uri",
    "issues" => "bug_tracker_uri",
    "mail" => "mailing_list_uri",
    "tickets" => "bug_tracker_uri",
    "wiki" => "wiki_uri"
  })
  Hoe.prepend Hoe::Halostatue::ParseUrls

  self.checklist = [
    "bump the version",
    "check everything in",
    "review the manifest",
    "update the README and RDocs",
    "update the changelog",
    "regenerate the gemspec"
  ]

  self.git_release_tag_prefix = "v"
  self.git_remotes = %w[origin]
  self.git_tag_enabled = true
  self.trusted_release = false
end