Gemspec-generation tasks
Pattern for splitting parsed authors list items into name and email
Environment variable for overriding the name of the user packaging up a release.
A message to be displayed after the gem is installed.
The path to the file used to sign released gems
Define gemspec tasks
# File lib/rake/deveiate/gemspec.rb, line 52
def define_tasks
super if defined?( super )
gemspec_file = "#{self.name}.gemspec"
if self.has_manifest?
file( self.manifest_file )
file( gemspec_file => self.manifest_file )
else
file( gemspec_file )
end
task( gemspec_file ) do |task|
self.prompt.say "Updating gemspec"
spec = self.make_prerelease_gemspec
File.open( task.name, 'w' ) do |fh|
fh.write( spec.to_ruby )
end
end
desc "(Re)Generate the gemspec file"
task :gemspec => gemspec_file
CLEAN.include( gemspec_file.to_s )
task :precheckin => :gemspec
task( :gemspec_debug, &method(:do_gemspec_debug) )
task :debug => :gemspec_debug
end
Task function – output debugging for gemspec tasks.
# File lib/rake/deveiate/gemspec.rb, line 87
def do_gemspec_debug( task, args )
gemspec = self.gemspec
gemspec_src = gemspec.to_yaml
if self.post_install_message
self.prompt.say( "Post-install message:", color: :bright_green )
self.prompt.say( self.indent(self.post_install_message, 4) )
self.prompt.say( "\n" )
end
self.prompt.say( "Gemspec:", color: :bright_green )
self.prompt.say( self.indent(gemspec_src, 4) )
self.prompt.say( "\n" )
end
Extract the documentation URI from the `docs` item of the first NOTE-type list in the README. Returns nil
if no such URI could be found.
# File lib/rake/deveiate/gemspec.rb, line 221
def extract_documentation_uri
return fail_extraction( :documentation, "no README" ) unless self.readme
list = self.readme.parts.find {|part| RDoc::Markup::List === part && part.type == :NOTE } or
return fail_extraction(:documentation, "No NOTE list")
item = list.items.find {|item| item.label.include?('docs') } or
return fail_extraction(:documentation, "No `docs` item")
return URI( item.parts.first.text )
end
Extract the source URI from the `docs` item of the first NOTE-type list in the README. Returns nil
if no such URI could be found.
# File lib/rake/deveiate/gemspec.rb, line 235
def extract_source_uri
return fail_extraction( :source, "no README" ) unless self.readme
list = self.readme.parts.find {|part| RDoc::Markup::List === part && part.type == :NOTE } or
return fail_extraction(:code, "No NOTE list")
item = list.items.find {|item| item.label.include?('code') } or
return fail_extraction(:code, "No `code` item")
return URI( item.parts.first.text )
end
Return the path to the cert belonging to the user packaging up the release. Returns nil if no such cert exists.
# File lib/rake/deveiate/gemspec.rb, line 263
def find_signing_cert
current_user = ENV[ RELEASE_USER_ENV ] || Etc.getlogin
certfile = self.cert_files.find {|fn| fn.end_with?("#{current_user}.pem") } or
return nil
return File.expand_path( certfile )
end
Return the project's Gem::Specification, creating it if necessary.
# File lib/rake/deveiate/gemspec.rb, line 104
def gemspec
return @gemspec ||= self.make_gemspec
end
Build the hash of metadata that should be attached to the gem.
# File lib/rake/deveiate/gemspec.rb, line 177
def make_gem_metadata
# "bug_tracker_uri" => "https://example.com/user/bestgemever/issues",
# "changelog_uri" => "https://example.com/user/bestgemever/CHANGELOG.md",
# "documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1",
# "homepage_uri" => "https://bestgemever.example.io",
# "mailing_list_uri" => "https://groups.example.com/bestgemever",
# "source_code_uri" => "https://example.com/user/bestgemever",
# "wiki_uri" => "https://example.com/user/bestgemever/wiki"
metadata = {
"homepage_uri" => self.homepage
}
if docs_uri = self.extract_documentation_uri
metadata['documentation_uri'] = docs_uri.to_s
if docs_uri.path.end_with?( '/', self.name )
cl_uri = docs_uri.dup
cl_uri.path = File.join( cl_uri.path, 'History_md.html' )
metadata['changelog_uri'] = cl_uri.to_s
end
end
if source_uri = self.extract_source_uri
metadata['source_uri'] = source_uri.to_s
case source_uri.host
when /\.sr\.ht/
bt_uri = source_uri.dup
bt_uri.host = 'todo.sr.ht'
metadata['bug_tracker_uri'] = bt_uri.to_s
when /\.gitlab\.com/
bt_uri = source_uri.dup
bt_uri.path += '-/issues'
metadata['bug_tracker_uri'] = bt_uri.to_s
else
self.trace "No idea what bug tracker URIs for %s look like!" % [ source_uri.host ]
end
end
return metadata
end
Return a Gem::Specification created from the project's metadata.
# File lib/rake/deveiate/gemspec.rb, line 117
def make_gemspec
spec = Gem::Specification.new
spec.name = self.name
spec.description = self.description
spec.homepage = self.homepage
spec.summary = self.summary || self.extract_summary
spec.files = self.project_files
spec.executables = self.executables
spec.extensions = self.extensions.to_a
spec.signing_key = self.resolve_signing_key.to_s
spec.cert_chain = [ self.find_signing_cert ].compact
spec.version = self.version
spec.licenses = self.licenses
spec.date = Date.today
spec.metadata = self.make_gem_metadata
spec.required_ruby_version = self.required_ruby_version if
self.required_ruby_version
spec.metadata['allowed_push_host'] = self.allowed_push_host if self.allowed_push_host
spec.post_install_message = self.post_install_message
self.authors.each do |author|
if ( m = author.match(AUTHOR_PATTERN) )
spec.authors ||= []
spec.authors << m[:name]
spec.email ||= []
spec.email << m[:email] if m[:email]
else
self.prompt.warn "Couldn't extract author name + email from %p" % [ author ]
end
end
self.dependencies.each do |dep|
if dep.runtime?
spec.add_runtime_dependency( dep )
else
spec.add_development_dependency( dep )
end
end
return spec
end
Return a Gem::Specification with its properties modified to be suitable for a pre-release gem.
# File lib/rake/deveiate/gemspec.rb, line 165
def make_prerelease_gemspec
spec = self.make_gemspec
spec.version = self.prerelease_version
spec.signing_key = nil
spec.cert_chain = []
return spec
end
Return a version string
# File lib/rake/deveiate/gemspec.rb, line 248
def prerelease_version
return "#{self.version.bump}.0.pre.#{Time.now.strftime("%Y%m%d%H%M%S")}"
end
Reset any cached data when project attributes change.
# File lib/rake/deveiate/gemspec.rb, line 44
def reset
super if defined?( super )
@gemspec = nil
@post_install_message = nil
end
Resolve the path of the signing key
# File lib/rake/deveiate/gemspec.rb, line 254
def resolve_signing_key
path = Pathname( self.signing_key ).expand_path
path = path.readlink if path.symlink?
return path
end
Set some defaults when the task lib is set up.
# File lib/rake/deveiate/gemspec.rb, line 28
def setup( _name, **options )
super if defined?( super )
@signing_key = options[:signing_key] || Gem.default_key_path
@post_install_message = options[:post_install_message]
@gemspec = nil
end
Validate the gemspec, raising a Gem::InvalidSpecificationException if it's not valid.
# File lib/rake/deveiate/gemspec.rb, line 111
def validate_gemspec( packaging=true, strict=false )
return self.gemspec.validate( packaging, strict )
end