require_relative 'app' task default: 'lint_and_test' desc 'Run tests' task :test do puts "\nMINITEST:" Dir.glob('./test/test_*.rb') { |f| require f } end desc 'Run linters' task :lint do puts "RUBOCOP:\n" sh 'bundle exec rubocop' puts "\nSHELLCHECK:\n" sh "shellcheck --exclude=SC2016 #{Dir.glob('../**/*.sh').join(' ')}" puts "\nPYLINT:\n" sh "pylint --rcfile=.pylintrc #{Dir.glob('../**/*.py').join(' ')}" end task :lint_and_test do Rake::Task['lint'].invoke Rake::Task['test'].invoke end namespace :db do task :migrate do Sequel.extension :migration Sequel::Migrator.run(DB, 'db/migrations') end desc 'Clear the packages database' task :clear_packages do clear_packages end desc 'Update the build database with logfiles from ci-logs/' task :update_build do update_build('ci-logs/*/*/builds/*') end desc 'Clear the build database' task :clear_build do clear_build end desc 'Update the repoman database with logfiles from repo-logs/' task :update_repoman do update_repoman('ci-logs/*/*/repomans/*') end desc 'Clear the repoman database' task :clear_repoman do clear_repoman end end namespace :docker do num_of_packages = ENV['NUM_OF_PACKAGES'] begin num_of_packages = Integer(num_of_packages) rescue 'Do not suppress exceptions' end desc 'Build a docker image to use with subsequent tasks' task :setup do Docker.options[:read_timeout] = 36_000 Docker.options[:write_timeout] = 36_000 @volume_image = Docker::Image.build('FROM busybox') @volume_container = Docker::Container.create( Image: @volume_image.id, Volumes: { '/usr/portage/packages' => { '/usr/portage/packages' => 'rw' } } ) @volume_container.start @volume_container.wait(36_000) if ENV['CI_IMAGE'].nil? docker_path = File.dirname(File.expand_path(File.dirname(__FILE__))) @ci_image = Docker::Image.build_from_dir(docker_path) else @ci_image = Docker::Image.get(ENV['CI_IMAGE']) end end desc 'Remove a previously built docker image' task :teardown do @ci_image.delete if ENV['CI_IMAGE'].nil? @volume_container.delete(v: 1) @volume_image.delete end desc 'Update the packages database with new versions and targets' task :update_packages do update_packages(@ci_image) end desc 'Build test packages ( NUM_OF_PACKAGES={5,all,untested} )' task :run_build do run_ci(@volume_container, @ci_image, 'build', num_of_packages) end desc 'QA test packages ( NUM_OF_PACKAGES={5,all} )' task :run_repoman do run_ci(@volume_container, @ci_image, 'repoman', num_of_packages) end end