#!/usr/bin/env ratch # make a release annoucement # The announce task generates release announcement and # optionally emails it via your email provider. (Note # that TLS is not yet supported as of Ruby 1.8.4.) # Announcements can also have layouts defined by simple # templates. # # Make a release announcement. Generates and can email a release # announcements. These are nicely formated message and can # email the message to the specified address(es). # # The following settings apply: # # title Project title. # subtitle Brief one-line description. # version Project version. # description Long description of project. # homepage Project homepage web address. # slogan Motto for you project. # memo File that contains announcement message. # template Custom announcement template file. # mail_to Email address(es) to send announcemnt. # # If mail_to is set then these also apply: # # from Message FROM address [email]. # subject Subject of email message ([ANN] title verison). # server Email server to route message. # port Email server's port. # domain Email server's domain name. # account Email account name [email]. # login Login type: plain, cram_md5 or login. # secure Uses TLS security, true or false? # # A template file can be specified that uses "$setting" as # substitutes for poject information. # Default layout of release announcement. DEFAULT_ANNOUNCE_TEMPLATE = <<-END $title $version $subtitle $homepage $summary $description $memo $slogan END config = config_load('announce', 'mail') if projectinfo config['from'] ||= projectinfo.email config['name'] ||= projectinfo.name config['version'] ||= projectinfo.version config['title'] ||= projectinfo.title config['subtitle'] ||= projectinfo.subtitle config['description'] ||= projectinfo.description config['homepage'] ||= projectinfo.homepage config['download'] ||= projectinfo.download config['slogan'] ||= projectinfo.slogan end config['subject'] ||= "ANN: #{config['title']}, v#{config['version']}" config['account'] ||= config['mail_from'] #config['mail_to'] = nil if keys['mail_to'].empty? # Generate announcement message. title = config['title'] version = config['version'] template = config['template'] memo = config['memo'] # Announce template unless template files = Dir.glob("{ANN,doc/[aA]nn,doc/ANN}{,.txt}") template = files.first end template = File.read(template) if template template = template || DEFAULT_ANNOUNCE_TEMPLATE # Announce Memo unless memo files = Dir.glob("{MEMO,doc/[mM]emo,doc/MEMO}{,.txt}") memo = files.first end memo = File.read(memo).fold(true) if memo # Validate raise ArgumentError, "missing title" unless title raise ArgumentError, "missing version" unless version # Strip tiny version zero. #if keys['version'] =~ /[.].*?[.]/ # keys['version'] = keys['version'].chomp('.0') #end # Make announcement message message = template.dup message.gsub!('$memo',memo) if memo # insert memo #message.gsub!('$stamp',stamp.to_s) # insert stamp template.scan(/[$].*?\s/m) do |key| key = key.strip name = key[1..-1] value = info.send(name) message.gsub!(key, value.to_s.strip) end message.gsub!(/(^|[ ])[$].*?(?=[ ]|$)/,'') # remove unused vars message.gsub!("\n\n\n","\n") # remove any triple blank lines message.rstrip! message = release_announcement(config) puts "\n#{message}\n\n" return unless keys['to'] ans = ask("Would you like to email this announcement?", "yN") case ans.downcase when 'y', 'yes' email(message, config) end # keys = {} # keys['from'] = info.email # keys.update info.gather('mail') # keys.update info.gather('announce') # keys.update info.select( # :project, :version, :title, :subtitle, :description, # :homepage, :download, :slogan # ) # keys.update override if override # # Get password. # # def password( account ) # @password || ENV['PASSWORD'] || ask("Password for #{account}: ") # end =begin # Name of project (ie. unix name). attr_accessor :project # Title of project. attr_accessor :title # Subtitle of project. attr_accessor :subtitle # Version number of project release. attr_accessor :version # Description of project. attr_accessor :description # Project's homepage. attr_accessor :homepage # URL to download. attr_accessor :download # Project slogan. attr_accessor :slogan # To email address(es). If this is not set then # the announcement is not emailed and instead # is only sent to stdout. attr_accessor :mail_to # From email address. attr_accessor :mail_from # Memo (personalized message for this release) attr_accessor :memo # User defined announcement template. attr_accessor :template # Subject line (default is "ANN: project version"). attr_accessor :subject # Email server attr_accessor :server # Emails server port (default is usually correct). attr_accessor :port # Email account name (defaults to mail_from). attr_accessor :account # User domain (not sure why SMTP requires this?) attr_accessor :domain # Login type (plain, login) attr_accessor :login_type # Use TLS/SSL true or false? attr_accessor :secure # Password (deafults to ENV['PASSWORD'] attr_accessor :password =end