diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..57d6d5c --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,30 @@ +stages: + - test + +default: + before_script: + - apt-get -qq update + - apt-get install -y gnupg2 gettext git subversion util-linux + - gem update --system --quiet + - gem update bundler + - bundle install + - gem install minitest-junit simplecov-cobertura + script: + - rake test + artifacts: + reports: + junit: report.xml + cobertura: coverage/coverage.xml + +variables: + TESTOPT: '--junit --pride' + LANG: 'C.UTF-8' # container has no LANG by default which messes with ruby's utf8 support + +test:2.4: + image: ruby:2.4 +test:2.5: + image: ruby:2.5 +test:2.6: + image: ruby:2.6 +test:2.7: + image: ruby:2.7 diff --git a/releaseme.gemspec b/releaseme.gemspec index e24c95a..2168874 100644 --- a/releaseme.gemspec +++ b/releaseme.gemspec @@ -1,58 +1,57 @@ # coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) Gem::Specification.new do |spec| spec.name = 'releaseme' spec.version = '0.0' spec.authors = ['Harald Sitter'] spec.email = ['sitter@kde.org'] spec.summary = 'KDE tarball release tool' spec.description = 'Helps with releasing KDE software as source code tarballs' spec.homepage = 'https://phabricator.kde.org/source/releaseme/' # Prevent pushing this gem to RubyGems.org. To allow pushes either set the # 'allowed_push_host' to allow pushing to a single host or delete this section # to allow pushing to any host. if spec.respond_to?(:metadata) spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'" else raise 'RubyGems 2.0 or newer is required to protect against ' \ 'public gem pushes.' end spec.files = `git ls-files -z`.split("\x0") rejected_files = spec.files.find_all do |f| f.match(%r{^(test|spec|features)/}) || (f.match(%r{^lib/[^/]+.rb}) && !f.match(%r{^lib/releaseme.rb})) end spec.files -= rejected_files # When run through bundler AND in a Gem search path mangle the working # directory. if File.basename($PROGRAM_NAME).include?('bundle') && (Gem.path.any? { |x| Dir.pwd.start_with?(x) } || Dir.pwd.include?('.bundler/') || Dir.pwd.include?('.bundle/')) warn "Mangling releaseme gem as it is in a gem search path #{Dir.pwd}" FileUtils.rm_rf(rejected_files, verbose: true) end spec.require_paths = ['lib'] spec.add_development_dependency 'bundler' # Development spec.add_development_dependency 'rake', '~> 10.0' # Documentation spec.add_development_dependency 'rdoc' spec.add_development_dependency 'yard' # Testing spec.add_development_dependency 'minitest' spec.add_development_dependency 'mocha' spec.add_development_dependency 'webmock' # Coverage - spec.add_development_dependency 'coveralls_reborn' spec.add_development_dependency 'simplecov', '>= 0.11' # Quality spec.add_development_dependency 'rubocop' end diff --git a/test/lib/testme.rb b/test/lib/testme.rb index 7b7f557..296649f 100644 --- a/test/lib/testme.rb +++ b/test/lib/testme.rb @@ -1,114 +1,114 @@ require 'tmpdir' require 'fileutils' require_relative '../test_helper' require 'minitest/unit' begin require 'mocha/minitest' rescue LoadError # 1.0 changed the name, try older name as well for good measure require 'mocha/mini_test' end require 'webmock/minitest' module TestMeExtension attr_reader :tmpdir attr_reader :testdir attr_reader :datadir def initialize(*args) @dir = nil @git_config_name = nil @git_config_email = nil super end def setup_git if `git config --global user.email`.strip.empty? @git_config_email = true `git config --global user.email "you@example.com"` end if `git config --global user.name`.strip.empty? @git_config_name = true `git config --global user.name "Your Name"` end end def teardown_git `git config --global --unset user.email` unless @git_config_email.nil? `git config --global --unset user.name` unless @git_config_name.nil? end def setup_env ENV['GNUPGHOME'] = data('keyring') end def before_setup @orig_env = ENV.to_h # to_h causes a full deserialization ENV['RELEASEME_SHUTUP'] = 'true' ENV['SANITIZED_PREFIX_SUFFIX'] = '1' @tmpdir = Dir.mktmpdir("testme-#{self.class.to_s.tr(':', '_')}") ENV['TEST_SETUP'] = nil @testdir = File.expand_path(File.dirname(File.dirname(__FILE__))).to_s @datadir = "#{@testdir}/data" @pwdir = Dir.pwd Dir.chdir(@tmpdir) setup_git setup_env super end def after_teardown - teardown_git Dir.chdir(@pwdir) FileUtils.rm_rf(@tmpdir) # Restore original env ## Explicitly clear to be on the safe side. Sometimes restoring the env ## may bug out slightly (on windows). ENV.clear ENV.replace(@orig_env) + teardown_git super end def data(path) path = path.partition('data/').last if path.start_with?('data/') "#{@datadir}/#{path}" end def assert_path_exist(path, msg = nil) msg = message(msg) { "Expected path '#{path}' to exist" } assert File.exist?(path), msg end def refute_path_exist(path, msg = nil) msg = message(msg) { "Expected path '#{path}' to NOT exist" } refute File.exist?(path), msg end end class Testme < Minitest::Test prepend TestMeExtension # WARNING: with minitest one should extend through a prepend otherwise hooks # such as mocha may not get properly applied and cause test malfunctions! end # Only set SANITIZED_PREFIX_SUFFIX in tests. Actual lib code mustn't ever # set it as that'd bypass the test. module MkTmpDirOverlay def mktmpdir(*) return super if ENV['SANITIZED_PREFIX_SUFFIX'] raise 'Dir.mktmpdir must not be used! Use Releaseme.mktmpdir!' ensure ENV['SANITIZED_PREFIX_SUFFIX'] = nil end end # Prevent tests from using mktmpdir directly and instead expect them to go # through our mktmpdir such that the prefix_suffix gets cleaned up. # https://bugs.kde.org/show_bug.cgi?id=393011 class Dir class << self prepend MkTmpDirOverlay end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 71aea5b..9f9f39c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,26 +1,26 @@ require 'simplecov' formatters = [] begin - require 'coveralls' - formatters << Coveralls::SimpleCov::Formatter + require 'simplecov-cobertura' + formatters << SimpleCov::Formatter::CoberturaFormatter rescue LoadError - warn 'coveralls reporter not available, not sending reports to server' + warn 'simplecov-cobertura reporter not available' end # HTML formatter. formatters << SimpleCov::Formatter::HTMLFormatter SimpleCov.start do formatter SimpleCov::Formatter::MultiFormatter.new(formatters) add_filter do |src| # Special compat file for testing the compat code itself. next false if File.basename(src.filename) == 'compat_compat.rb' next false if File.basename(src.filename) == 'releaseme.rb' src.filename.match(%r{.+/lib/[^/]+.rb}) end end # $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'minitest/autorun'