diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2019-03-06 23:59:50 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2019-03-07 00:46:56 -0700 |
| commit | e53b7536d7df8d3cefcf14b0d6dd774d1315e42c (patch) | |
| tree | fd8c2212d23ef15e9b015eea51593edf77152936 | |
| parent | 49e1c7f4aa589c726d9aa69d3cd1813ee96eed7b (diff) | |
organize rake build by moving tasks into task files
| -rw-r--r-- | Rakefile | 115 | ||||
| -rw-r--r-- | tasks/bundler.rake | 6 | ||||
| -rw-r--r-- | tasks/console.rake | 5 | ||||
| -rw-r--r-- | tasks/coverage.rake | 5 | ||||
| -rw-r--r-- | tasks/cucumber.rake | 10 | ||||
| -rw-r--r-- | tasks/dependents.rake | 56 | ||||
| -rw-r--r-- | tasks/test.rake | 30 |
7 files changed, 114 insertions, 113 deletions
@@ -1,115 +1,4 @@ # frozen_string_literal: true -def prepare_test_env - # rather than hardcoding gc settings in test task, - # could use https://gist.github.com/benders/788695 - ENV['RUBY_GC_MALLOC_LIMIT'] = 128_000_000.to_s - ENV['RUBY_GC_OLDMALLOC_LIMIT'] = 128_000_000.to_s - if RUBY_VERSION >= '2.1' - ENV['RUBY_GC_HEAP_INIT_SLOTS'] = 800_000.to_s - ENV['RUBY_GC_HEAP_FREE_SLOTS'] = 800_000.to_s - ENV['RUBY_GC_HEAP_GROWTH_MAX_SLOTS'] = 250_000.to_s - ENV['RUBY_GC_HEAP_GROWTH_FACTOR'] = 1.25.to_s - else - ENV['RUBY_FREE_MIN'] = 800_000.to_s - end -end +Dir.glob('tasks/*.rake').each {|file| load file } -begin - require 'rake/testtask' - Rake::TestTask.new(:test) do |t| - prepare_test_env - puts %(LANG: #{ENV['LANG']}) if ENV.key? 'TRAVIS_BUILD_ID' - t.libs << 'test' - t.pattern = 'test/**/*_test.rb' - t.verbose = true - t.warning = true - end - task :default => 'test:all' -rescue LoadError -end - -begin - require 'cucumber/rake/task' - Cucumber::Rake::Task.new(:features) do |t| - t.cucumber_opts = %w(-f progress) - t.cucumber_opts << '--no-color' if ENV['CI'] - end -rescue LoadError -end - -desc 'Activates coverage' -task :coverage do - ENV['COVERAGE'] = 'true' if RUBY_VERSION >= '1.9.3' -end - -namespace :test do - desc 'Run unit and feature tests' - task :all => [:test, :features] -end - -begin - require 'bundler/gem_tasks' -rescue LoadError -end - -desc 'Open an irb session preloaded with this library' -task :console do - sh 'bundle console', :verbose => false -end - -namespace :build do -desc 'Trigger builds for all dependent projects on Travis CI' - task :dependents do - if ENV['TRAVIS'].to_s == 'true' - next unless ENV['TRAVIS_PULL_REQUEST'].to_s == 'false' && - ENV['TRAVIS_TAG'].to_s.empty? && - (ENV['TRAVIS_JOB_NUMBER'].to_s.end_with? '.1') - end - # NOTE The TRAVIS_TOKEN env var must be defined in Travis interface. - # Retrieve this token using the `travis token` command. - # The GitHub user corresponding to the Travis user must have write access to the repository. - # After granting permission, sign into Travis and resync the repositories. - next unless (token = ENV['TRAVIS_TOKEN']) - require 'json' - require 'net/http' - require 'open-uri' - require 'yaml' - %w( - asciidoctor/asciidoctor.js - asciidoctor/asciidoctorj - asciidoctor/asciidoctorj/asciidoctorj-1.5.x - asciidoctor/asciidoctor-diagram - asciidoctor/asciidoctor-reveal.js - ).each do |project| - org, name, branch = project.split '/', 3 - branch ||= 'master' - project = [org, name, branch] * '/' - header = { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - 'Travis-API-Version' => '3', - 'Authorization' => %(token #{token}) - } - if (commit_hash = ENV['TRAVIS_COMMIT']) - commit_memo = %( (#{commit_hash.slice 0, 8})\n\nhttps://github.com/#{ENV['TRAVIS_REPO_SLUG'] || 'asciidoctor/asciidoctor'}/commit/#{commit_hash}) - end - config = YAML.load open(%(https://raw.githubusercontent.com/#{project}/.travis-upstream-only.yml)) {|fd| fd.read } rescue {} - payload = { - 'request' => { - 'branch' => branch, - 'message' => %(Build triggered by Asciidoctor#{commit_memo}), - 'config' => config - } - }.to_json - (http = Net::HTTP.new 'api.travis-ci.org', 443).use_ssl = true - request = Net::HTTP::Post.new %(/repo/#{org}%2F#{name}/requests), header - request.body = payload - response = http.request request - if response.code == '202' - puts %(Successfully triggered build on #{project} repository) - else - warn %(Unable to trigger build on #{project} repository: #{response.code} - #{response.message}) - end - end - end -end +task default: %w(test:all) diff --git a/tasks/bundler.rake b/tasks/bundler.rake new file mode 100644 index 00000000..47f3ef1a --- /dev/null +++ b/tasks/bundler.rake @@ -0,0 +1,6 @@ +# frozen_string_literal: true +begin + require 'bundler/gem_tasks' +rescue LoadError => e + warn e.message +end diff --git a/tasks/console.rake b/tasks/console.rake new file mode 100644 index 00000000..a6f6856a --- /dev/null +++ b/tasks/console.rake @@ -0,0 +1,5 @@ +# frozen_string_literal: true +desc 'Open an irb session preloaded with this library' +task :console do + sh 'bundle console', :verbose => false +end diff --git a/tasks/coverage.rake b/tasks/coverage.rake new file mode 100644 index 00000000..217e5a94 --- /dev/null +++ b/tasks/coverage.rake @@ -0,0 +1,5 @@ +# frozen_string_literal: true +desc 'Activates coverage' +task :coverage do + ENV['COVERAGE'] = 'true' +end diff --git a/tasks/cucumber.rake b/tasks/cucumber.rake new file mode 100644 index 00000000..9b49ce22 --- /dev/null +++ b/tasks/cucumber.rake @@ -0,0 +1,10 @@ +# frozen_string_literal: true +begin + require 'cucumber/rake/task' + Cucumber::Rake::Task.new :features do |t| + t.cucumber_opts = %w(-f progress) + t.cucumber_opts << '--no-color' if ENV['CI'] + end +rescue LoadError => e + warn e.message +end diff --git a/tasks/dependents.rake b/tasks/dependents.rake new file mode 100644 index 00000000..2c185ca6 --- /dev/null +++ b/tasks/dependents.rake @@ -0,0 +1,56 @@ +# frozen_string_literal: true +namespace :build do + desc 'Trigger builds for all dependent projects on Travis CI' + task :dependents do + if ENV['TRAVIS'].to_s == 'true' + next unless ENV['TRAVIS_PULL_REQUEST'].to_s == 'false' && + ENV['TRAVIS_TAG'].to_s.empty? && + (ENV['TRAVIS_JOB_NUMBER'].to_s.end_with? '.1') + end + # NOTE The TRAVIS_TOKEN env var must be defined in Travis interface. + # Retrieve this token using the `travis token` command. + # The GitHub user corresponding to the Travis user must have write access to the repository. + # After granting permission, sign into Travis and resync the repositories. + next unless (token = ENV['TRAVIS_TOKEN']) + require 'json' + require 'net/http' + require 'open-uri' + require 'yaml' + %w( + asciidoctor/asciidoctor.js + asciidoctor/asciidoctorj + asciidoctor/asciidoctor-diagram + asciidoctor/asciidoctor-reveal.js + ).each do |project| + org, name, branch = project.split '/', 3 + branch ||= 'master' + project = [org, name, branch] * '/' + header = { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'Travis-API-Version' => '3', + 'Authorization' => %(token #{token}) + } + if (commit_hash = ENV['TRAVIS_COMMIT']) + commit_memo = %( (#{commit_hash.slice 0, 8})\n\nhttps://github.com/#{ENV['TRAVIS_REPO_SLUG'] || 'asciidoctor/asciidoctor'}/commit/#{commit_hash}) + end + config = YAML.load open(%(https://raw.githubusercontent.com/#{project}/.travis-upstream-only.yml)) {|fd| fd.read } rescue {} + payload = { + 'request' => { + 'branch' => branch, + 'message' => %(Build triggered by Asciidoctor#{commit_memo}), + 'config' => config + } + }.to_json + (http = Net::HTTP.new 'api.travis-ci.org', 443).use_ssl = true + request = Net::HTTP::Post.new %(/repo/#{org}%2F#{name}/requests), header + request.body = payload + response = http.request request + if response.code == '202' + puts %(Successfully triggered build on #{project} repository) + else + warn %(Unable to trigger build on #{project} repository: #{response.code} - #{response.message}) + end + end + end +end diff --git a/tasks/test.rake b/tasks/test.rake new file mode 100644 index 00000000..3a3615b8 --- /dev/null +++ b/tasks/test.rake @@ -0,0 +1,30 @@ +# frozen_string_literal: true +def prepare_test_env + # rather than hardcoding gc settings in test task, + # could use https://gist.github.com/benders/788695 + ENV['RUBY_GC_MALLOC_LIMIT'] = 128_000_000.to_s + ENV['RUBY_GC_OLDMALLOC_LIMIT'] = 128_000_000.to_s + ENV['RUBY_GC_HEAP_INIT_SLOTS'] = 750_000.to_s + ENV['RUBY_GC_HEAP_FREE_SLOTS'] = 750_000.to_s + ENV['RUBY_GC_HEAP_GROWTH_MAX_SLOTS'] = 50_000.to_s + ENV['RUBY_GC_HEAP_GROWTH_FACTOR'] = 2.to_s +end + +begin + require 'rake/testtask' + Rake::TestTask.new :test do |t| + prepare_test_env + puts %(LANG: #{ENV['LANG']}) if ENV.key? 'TRAVIS_BUILD_ID' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = true + t.warning = true + end +rescue LoadError => e + warn e.message +end + +namespace :test do + desc 'Run unit and feature tests' + task :all => [:test, :features] +end |
