# encoding: utf-8 $LOAD_PATH.unshift File.expand_path('../lib', __FILE__) windows = RUBY_PLATFORM =~ /mswin|mingw/ desc "run specs" task(:spec) { ruby "-S rspec spec#{" -c" unless windows}" } desc "generate gemspec, update readme" task :update => :completion do require 'travis/version' content = File.read('travis.gemspec') # fetch data fields = { :authors => `git shortlog -sn`.b.scan(/[^\d\s].*/).map { |a| a == 'petems' ? 'Peter Souter' : a }, :email => `git shortlog -sne`.b.scan(/[^<]+@[^>]+/), :files => `git ls-files`.b.split("\n").reject { |f| f =~ /^(\.|Gemfile)/ } } # :( fields[:email].delete("konstantin.haase@gmail.com") fields[:authors] # insert data fields.each do |field, values| updated = " s.#{field} = [" updated << values.map { |v| "\n %p" % v }.join(',') updated << "\n ]" content.sub!(/ s\.#{field} = \[\n( .*\n)* \]/, updated) end # set version content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Travis::VERSION}\"" # escape unicode content.gsub!(/./) { |c| c.bytesize > 1 ? "\\u{#{c.codepoints.first.to_s(16)}}" : c } File.open('travis.gemspec', 'w') { |f| f << content } readme = File.read('README.md').b readme.gsub! /^(\s+\$ travis version\n\s+).*$/, "\\1#{Travis::VERSION}" readme.gsub! /(gem install travis -v )\S+/, "\\1#{Travis::VERSION}" File.write('README.md', readme) end task :completion do require 'travis/cli' commands = Travis::CLI.commands.sort_by { |c| c.command_name } names = commands.map(&:command_name).join("\n") options = commands.map do |command| flags = command.new.parser.candidate("-").flat_map do |option| next option unless option.start_with?('--[no-]') [option.sub('[no-]', ''), option.sub('[no-]', 'no-')] end.join("\n") case command.command_name when "setup" completions = command.public_instance_methods. select { |m| m.to_s.start_with? "setup_" }. map { |m| m.to_s.sub('setup_', '') + "\n" }.join << flags when "help" completions = "#{names}\n#{flags}" else completions = flags end <<-SHELL #{command.command_name}) completions="#{completions}" ;; SHELL end.join("\n") zsh = <<-SHELL _travis_complete() { local words completions read -cA words if [ "${#words}" -eq 2 ]; then completions="#{names}" else case "${words[2]}" in #{options} esac fi reply=("${(ps:\n:)completions}") } compctl -K _travis_complete travis SHELL bash = <<-SHELL _travis_complete() { COMPREPLY=() local completions if [ "$COMP_CWORD" -eq 1 ]; then completions="#{names}" else case "${COMP_WORDS[1]}" in #{options} esac fi COMPREPLY=( $(compgen -W "$completions" -- "${COMP_WORDS[COMP_CWORD]}") ) } complete -F _travis_complete travis SHELL File.write('completion/travis.sh', <<-SHELL.gsub(/^\s+/, '')) # This file is generated by `rake completion` if [ -n "$BASH_VERSION" ]; then #{bash} fi if [ -n "$ZSH_VERSION" ]; then #{zsh} fi SHELL end task 'travis.gemspec' => :update task 'README.md' => :update task :gemspec => :update task :default => :spec task :default => :gemspec unless windows or ENV['CI'] task :test => :spec