Devel-Cover-Report-Coveralls
view release on metacpan or search on metacpan
lib/Devel/Cover/Report/Coveralls.pm view on Meta::CPAN
$config = YAML::LoadFile($CONFIG_FILE);
}
my $json = {};
$json->{repo_token} = $config->{repo_token} if $config->{repo_token};
$json->{repo_token} = $ENV{COVERALLS_REPO_TOKEN} if $ENV{COVERALLS_REPO_TOKEN};
$json->{flag_name} = $ENV{COVERALLS_FLAG_NAME} if $ENV{COVERALLS_FLAG_NAME};
$json->{parallel} = \1 if $ENV{COVERALLS_PARALLEL};
my $is_travis;
my $endpoint = ($ENV{COVERALLS_ENDPOINT} || $API_ENDPOINT) . $API_ENDPOINT_STEM;
if ($ENV{TRAVIS}) {
$is_travis = 1;
$json->{service_name} = $config->{service_name} || 'travis-ci';
$json->{service_job_id} = $ENV{TRAVIS_JOB_ID};
if($ENV{TRAVIS_PULL_REQUEST} && $ENV{TRAVIS_PULL_REQUEST} ne 'false'){
$json->{service_pull_request} = $ENV{TRAVIS_PULL_REQUEST};
}
} elsif ($ENV{CIRCLECI}) {
$json->{service_name} = 'circleci';
$json->{service_number} = $ENV{CIRCLE_WORKFLOW_ID};
lib/Devel/Cover/Report/Coveralls.pm view on Meta::CPAN
$json->{service_name} = $config->{service_name} || $SERVICE_NAME;
$json->{service_event_type} = 'manual';
}
die "required repo_token in $CONFIG_FILE, make sure the environment var \"COVERALLS_REPO_TOKEN\" is set or launch via Travis" if !$json->{repo_token} && !$is_travis;
if (exists $ENV{COVERALLS_PERL_SERVICE_NAME} && $ENV{COVERALLS_PERL_SERVICE_NAME}) {
$json->{service_name} = $ENV{COVERALLS_PERL_SERVICE_NAME};
}
return ($json, $endpoint);
}
sub _parse_line ($) {
my $c = shift;
return sub {
my $l = $c->location(shift);
return $l unless $l;
lib/Devel/Cover/Report/Coveralls.pm view on Meta::CPAN
my @sfs;
for my $file (@{$options->{file}}) {
my $f = $cover->file($file);
my $c = $f->statement();
push @sfs, get_source( $file, _parse_line $c );
}
my ($json, $endpoint) = get_config();
$json->{git} = eval { get_git_info() } || {};
$json->{source_files} = \@sfs;
my $coder = JSON::PP->new->ascii;
my $response = HTTP::Tiny->new( verify_SSL => 1 )
->post_form( $endpoint, { json => $coder->encode($json) } );
my $res = eval { decode_json $response->{content} };
print("- Report::Coveralls --------\n");
if(exists($json->{service_number})){
print "My build number: ". $json->{service_number} ."\n";
}
if ($@) {
print "error: " . $response->{content};
t/01_basic.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Test::More;
use FindBin;
use Devel::Cover::Report::Coveralls;
my $normal_endpoint = 'https://coveralls.io/api/v1/jobs';
my $endpoint_stem = '/api/v1/jobs';
subtest 'get_config (travis)' => sub {
local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
local $ENV{TRAVIS} = 'true';
local $ENV{TRAVIS_JOB_ID} = 100000;
local $ENV{GITHUB_TOKEN} = undef;
local $ENV{TRAVIS_PULL_REQUEST} = 'false';
my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
is $got->{service_job_id}, 100000, 'config service_job_id';
is $got->{service_name}, 'travis-ci', 'config service_name';
ok !exists $got->{service_pull_request},'not a pull request';
local $ENV{TRAVIS_PULL_REQUEST} = '456';
($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
is $got->{service_pull_request},'456','config pull request';
is $endpoint, $normal_endpoint, 'config endpoint';
};
subtest 'get_config extra env (travis)' => sub {
local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
local $ENV{TRAVIS} = 'true';
local $ENV{TRAVIS_JOB_ID} = 100000;
my $diff_endpoint = 'http://localhost';
local $ENV{COVERALLS_ENDPOINT} = $diff_endpoint;
local $ENV{COVERALLS_FLAG_NAME} = 'Unit';
local $ENV{GITHUB_TOKEN} = undef;
my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
is $got->{service_job_id}, 100000, 'config service_job_id';
is $got->{service_name}, 'travis-ci', 'config service_name';
is $got->{flag_name}, 'Unit', 'config flag_name';
is $endpoint, $diff_endpoint . $endpoint_stem, 'new endpoint';
};
subtest 'get_config github' => sub {
local $ENV{TRAVIS} = undef; # reset on travis
local $ENV{DRONE} = undef; # reset on drone
local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
local $ENV{GITHUB_ACTIONS} = 1;
local $ENV{GITHUB_SHA} = '123456789';
local $ENV{GITHUB_TOKEN} = undef;
my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
is $got->{service_name}, 'github-actions', 'config service_name';
is $got->{service_number}, '123456789', 'config service_number';
is $endpoint, $normal_endpoint;
};
subtest 'get_config github actions improved' => sub {
local $ENV{TRAVIS} = undef;
local $ENV{DRONE} = undef; # reset on drone
local $ENV{COVERALLS_REPO_TOKEN} = undef;
local $ENV{GITHUB_TOKEN} = 'abcdef';
local $ENV{GITHUB_RUN_ID} = '123456789';
my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
is $got->{service_name}, 'github', 'config service_name';
is $got->{service_job_id}, '123456789', 'config service_job_id';
};
subtest 'get_config azure' => sub {
local $ENV{TRAVIS} = undef; # reset on travis
local $ENV{GITHUB_ACTIONS} = undef; # reset on github
local $ENV{GITHUB_REF} = undef; # reset on github
local $ENV{DRONE} = undef; # reset on drone
local $ENV{SYSTEM_TEAMFOUNDATIONSERVERURI} = 1;
local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
local $ENV{BUILD_SOURCEBRANCHNAME} = 'feature';
local $ENV{BUILD_BUILDID} = '123456789';
local $ENV{GITHUB_TOKEN} = undef;
my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
is $got->{service_name}, 'azure-pipelines', 'config service_name';
is $got->{service_number}, '123456789', 'config service_number';
is $endpoint, $normal_endpoint;
$got = Devel::Cover::Report::Coveralls::get_git_info();
is $got->{branch}, 'feature', 'git branch';
};
subtest 'get_config drone' => sub {
local $ENV{TRAVIS} = undef; # reset on travis
local $ENV{GITHUB_ACTIONS} = undef; # reset on github
local $ENV{GITHUB_REF} = undef; # reset on github
local $ENV{CIRCLECI} = undef;
local $ENV{DRONE_PULL_REQUEST} = '666';
local $ENV{DRONE_BUILD_NUMBER} = '123';
local $ENV{DRONE} = "drone";
local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
is $got->{service_name}, 'drone', 'config service_name';
is $got->{service_number}, '123', 'config service_number';
is $got->{service_pull_request}, '666', 'config service_pull_request';
is $endpoint, $normal_endpoint;
};
subtest 'get_config local' => sub {
local $ENV{TRAVIS} = undef; # reset on travis
local $ENV{GITHUB_ACTIONS} = undef; # reset on github
local $ENV{DRONE} = undef; # reset on drone
local $ENV{COVERALLS_REPO_TOKEN} = 'abcdef';
local $ENV{GITHUB_TOKEN} = undef;
my ($got, $endpoint) = Devel::Cover::Report::Coveralls::get_config();
is $got->{service_name}, 'coveralls-perl', 'config service_name';
is $got->{service_event_type}, 'manual', 'config service_event_type';
is $endpoint, $normal_endpoint;
};
subtest 'get_source' => sub {
my $source = {
name => "$FindBin::Bin/example.pl",
source => <<EOS,
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
( run in 0.309 second using v1.01-cache-2.11-cpan-a5abf4f5562 )