diff --git a/CHANGELOG.md b/CHANGELOG.md index 39e6d18..195e3f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### `0.5.2` +- #141 Add Cirrus CI support + ### `0.5.1` - #138 Update pass_ci_if_error flag diff --git a/codecov.gemspec b/codecov.gemspec index 989a413..7deec29 100644 --- a/codecov.gemspec +++ b/codecov.gemspec @@ -33,7 +33,6 @@ Gem::Specification.new do |s| s.add_dependency 'simplecov', '>= 0.15', '< 0.22' s.add_development_dependency 'minitest', '~> 5.0' - s.add_development_dependency 'minitest-ci', '~> 3.0' s.add_development_dependency 'mocha', '~> 1.0' s.add_development_dependency 'rake', '~> 13.0' s.add_development_dependency 'rubocop', '~> 1.0' diff --git a/lib/codecov/formatter.rb b/lib/codecov/formatter.rb index 47cf791..4caee62 100644 --- a/lib/codecov/formatter.rb +++ b/lib/codecov/formatter.rb @@ -59,7 +59,6 @@ def file_network invalid_directories = [ 'node_modules/', - 'public/', 'storage/', 'tmp/', 'vendor/' diff --git a/lib/codecov/uploader.rb b/lib/codecov/uploader.rb index 24d6cdb..47d9057 100644 --- a/lib/codecov/uploader.rb +++ b/lib/codecov/uploader.rb @@ -17,6 +17,7 @@ class Codecov::Uploader BITRISE = 'Bitrise CI', BUILDKITE = 'Buildkite CI', CIRCLE = 'Circle CI', + CIRRUS = 'Cirrus CI', CODEBUILD = 'Codebuild CI', CODESHIP = 'Codeship CI', DRONEIO = 'Drone CI', @@ -41,8 +42,8 @@ def self.upload(report, disable_net_blockers = true) begin response = upload_to_codecov(ci, report) rescue StandardError => e - puts `#{e.message}` - puts `#{e.backtrace.join("\n")}` + puts e.message + puts e.backtrace.join("\n") raise e unless ::Codecov.pass_ci_if_error response = false @@ -87,6 +88,8 @@ def self.detect_ci BUILDKITE elsif (ENV['CI'] == 'true') && (ENV['CIRCLECI'] == 'true') CIRCLE + elsif !ENV['CIRRUS_CI'].nil? + CIRRUS elsif ENV['CODEBUILD_CI'] == 'true' CODEBUILD elsif (ENV['CI'] == 'true') && (ENV['CI_NAME'] == 'codeship') @@ -188,6 +191,16 @@ def self.build_params(ci) params[:pr] = ENV['CIRCLE_PR_NUMBER'] params[:branch] = ENV['CIRCLE_BRANCH'] params[:commit] = ENV['CIRCLE_SHA1'] + when CIRRUS + # https://cirrus-ci.org/guide/writing-tasks/#environment-variables + params[:branch] = ENV['CIRRUS_BRANCH'] + params[:build] = ENV['CIRRUS_BUILD_ID'] + params[:build_url] = "https://cirrus-ci.com/tasks/#{ENV['CIRRUS_TASK_ID']}" + params[:commit] = ENV['CIRRUS_CHANGE_IN_REPO'] + params[:job] = ENV['CIRRUS_TASK_NAME'] + params[:pr] = ENV['CIRRUS_PR'] + params[:service] = 'cirrus-ci' + params[:slug] = ENV['CIRRUS_REPO_FULL_NAME'] when CODEBUILD # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html # To use CodePipeline as CodeBuild source which sets no branch and slug variable: diff --git a/lib/codecov/version.rb b/lib/codecov/version.rb index cc888c2..d08c4b8 100644 --- a/lib/codecov/version.rb +++ b/lib/codecov/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Codecov - VERSION = '0.5.1' + VERSION = '0.5.2' end diff --git a/test/helper.rb b/test/helper.rb index 1459c1f..57d6da1 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -14,6 +14,3 @@ require 'minitest/autorun' require 'mocha/minitest' require 'webmock/minitest' - -require 'minitest/ci' -Minitest::Ci.report_dir = '.' if ENV['CIRCLECI'] diff --git a/test/test_codecov.rb b/test/test_codecov.rb index 68a56b7..edc740c 100644 --- a/test/test_codecov.rb +++ b/test/test_codecov.rb @@ -6,7 +6,8 @@ class TestCodecov < Minitest::Test CI = Codecov::Uploader.detect_ci REALENV = - if CI == Codecov::Uploader::CIRCLE + case CI + when Codecov::Uploader::CIRCLE { 'CIRCLECI' => ENV['CIRCLECI'], 'CIRCLE_BUILD_NUM' => ENV['CIRCLE_BUILD_NUM'], @@ -18,7 +19,7 @@ class TestCodecov < Minitest::Test 'CIRCLE_BRANCH' => ENV['CIRCLE_BRANCH'], 'CIRCLE_SHA1' => ENV['CIRCLE_SHA1'] } - elsif CI == Codecov::Uploader::GITHUB + when Codecov::Uploader::GITHUB { 'GITHUB_ACTIONS' => ENV['GITHUB_ACTIONS'], 'GITHUB_HEAD_REF' => ENV['GITHUB_HEAD_REF'], @@ -27,7 +28,7 @@ class TestCodecov < Minitest::Test 'GITHUB_RUN_ID' => ENV['GITHUB_RUN_ID'], 'GITHUB_SHA' => ENV['GITHUB_SHA'] } - elsif CI == Codecov::Uploader::TRAVIS + when Codecov::Uploader::TRAVIS { 'TRAVIS' => ENV['TRAVIS'], 'TRAVIS_BRANCH' => ENV['TRAVIS_BRANCH'], @@ -167,6 +168,14 @@ def teardown ENV['CIRCLE_PROJECT_USERNAME'] = nil ENV['CIRCLE_SHA1'] = nil ENV['CIRCLECI'] = nil + ENV['CIRRUS_CI'] = nil + ENV['CIRRUS_BRANCH'] = nil + ENV['CIRRUS_BUILD_ID'] = nil + ENV['CIRRUS_TASK_ID'] = nil + ENV['CIRRUS_CHANGE_IN_REPO'] = nil + ENV['CIRRUS_TASK_NAME'] = nil + ENV['CIRRUS_PR'] = nil + ENV['CIRRUS_REPO_FULL_NAME'] = nil ENV['CODEBUILD_CI'] = nil ENV['CODEBUILD_BUILD_ID'] = nil ENV['CODEBUILD_BUILD_URL'] = nil @@ -240,7 +249,7 @@ def test_git end def test_enterprise - stub = stub_request(:post, %r{https:\/\/example.com\/upload\/v2}) + stub_request(:post, %r{https://example.com/upload/v2}) .to_return( status: 200, body: "{\"id\": \"12345678-1234-abcd-ef12-1234567890ab\", \"message\": \"Coverage reports upload successfully\", \"meta\": { \"status\": 200 }, \"queued\": true, \"uploaded\": true, \"url\": \"https://example.com/github/codecov/codecov-bash/commit/2f6b51562b93e72c610671644fe2a303c5c0e8e5\"}" @@ -687,10 +696,29 @@ def test_codebuild_source_version_is_other_than_pr_number assert_equal('git-commit-hash-12345', result['params'][:pr]) assert_equal('owner/repo', result['params'][:slug]) assert_equal('master', result['params'][:branch]) - assert_equal('git-commit-hash-12345', result['params'][:pr]) assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token']) end + def test_cirrus_ci + ENV['CIRRUS_CI'] = 'true' + ENV['CIRRUS_BRANCH'] = 'master' + ENV['CIRRUS_BUILD_ID'] = '12345' + ENV['CIRRUS_TASK_ID'] = '54321' + ENV['CIRRUS_CHANGE_IN_REPO'] = 'd653b934ed59c1a785cc1cc79d08c9aaa4eba73b' + ENV['CIRRUS_TASK_NAME'] = 'test' + ENV['CIRRUS_PR'] = '10' + ENV['CIRRUS_REPO_FULL_NAME'] = 'owner/repo' + + result = upload + + assert_equal('cirrus-ci', result['params'][:service]) + assert_equal('d653b934ed59c1a785cc1cc79d08c9aaa4eba73b', result['params'][:commit]) + assert_equal('12345', result['params'][:build]) + assert_equal('10', result['params'][:pr]) + assert_equal('owner/repo', result['params'][:slug]) + assert_equal('master', result['params'][:branch]) + end + def test_filenames_are_shortened_correctly ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'