blib/lib/GitHub/Actions.pm

filter: Statementstmt 95.7% 67 / 70 Branchbran 81.2% 13 / 16 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 95.2% 20 / 21 Podpod 100% 13 / 13 totaltotal 94.4% 119 / 126 CC 12 SCAR 8.7
CC
12
Cov
93%
command_on_file
5.0
BEGIN
4.3
set_output
3.0
CRAP 2.4
↑ Summary
1 package GitHub::Actions;
2  
3 6 ▶use Exporter 'import'; # needed to use @EXPORT
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Module implementation here
11 6 our %github;
12 6 our $EXIT_CODE = 0;
13  
14 6 our @EXPORT = qw(
15 %github $EXIT_CODE set_output set_env debug error warning
16 set_failed error_on_file warning_on_file
17 start_group end_group exit_action add_to_job_summary
18 );
19  
20 6 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=14.6
21 6 for my $k ( keys(%ENV) ) {
22 208 ▶ if ( $k =~ /^GITHUB_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^GITHUB_/u) 5 203 208
23 5 my ($nogithub) = ( $k =~ /^GITHUB_(\w+)/ );
24 5 $github{$nogithub} = $ENV{$k} ;
25 }
26 }
27 6 ▶ if ($ENV{'GITHUB_REPOSITORY'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"GITHUB_REPOSITORY"}) 0 6 6
28 0 my @repo_parts = split("/", $ENV{'GITHUB_REPOSITORY'});
29 0 $github{'REPO_NAME'} = pop @repo_parts;
30 }
31 }
32  
33 =head1 NAME
34  
35 GitHub::Actions - Work in GitHub Actions using native Perl
36  
37 =head1 VERSION
38  
39 This document describes GitHub::Actions version 0.3.0
40  
41 =cut
42  
43 6 ▶use version; our $VERSION = qv('0.3.0');
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 5 ▶sub _write_to_github_file {
Subroutine _write_to_github_file: called CC=2 SCAR=7.0
46 5 my ($github_var, $content) = @_;
47 5 ▶ open(my $fh, '>>', $github{$github_var}) or die "Could not open file ". $github{$github_var} ." $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $GitHub::Actions::github{$github_var} or die 'Could not open file ' . $GitHub::Actions::github{$github_var} . " $!" 5 0 5
48 5 say $fh $content;
49 5 close $fh;
50 }
51  
52 2 ▶sub set_output {
Subroutine set_output: called CC=3 SCAR=11.0
Pod documented
53 2 ▶ croak "Need name and value" unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2 2
54 2 my ($output_name, $output_value) = @_;
55 2 ▶ $output_value ||=1;
Condition100%2/2
$output_value ||= 1
l!l
11
MC/DC100%1/1
$output_value ||= 1
$output_value
Truth table100%2/2
A
A= $output_value
Aresult
11
00
56 2 _write_to_github_file( 'OUTPUT', "$output_name=$output_value" );
57 }
58  
59 2 ▶sub set_env {
Subroutine set_env: called CC=2 SCAR=6.9
Pod documented
60 2 my ($env_var_name, $env_var_value) = @_;
61 2 ▶ $env_var_value ||='1';
Condition100%2/2
$env_var_value ||= 1
l!l
11
MC/DC100%1/1
$env_var_value ||= 1
$env_var_value
Truth table100%2/2
A
A= $env_var_value
Aresult
11
00
62 2 _write_to_github_file( 'ENV', "$env_var_name=$env_var_value" );
63 }
64  
65 1 ▶sub debug {
Subroutine debug: called CC=1 SCAR=0.0
Pod documented
66 1 my $debug_message = shift;
67 1 say "::debug::$debug_message";
68 }
69  
70 2 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
71 2 my $error_message = shift;
72 2 $EXIT_CODE = 1;
73 2 say "::error::$error_message"
74 }
75  
76 2 ▶sub warning {
Subroutine warning: called CC=1 SCAR=0.0
Pod documented
77 2 my $warning = shift;
78 2 say "::warning::$warning"
79 }
80  
81 4 ▶sub error_on_file {
Subroutine error_on_file: called CC=1 SCAR=0.0
Pod documented
82 4 $EXIT_CODE= 1;
83 4 command_on_file( "::error", @_ );
84 }
85  
86 2 ▶sub warning_on_file {
Subroutine warning_on_file: called CC=1 SCAR=0.0
Pod documented
87 2 command_on_file( "::warning", @_ );
88 }
89  
90 6 ▶sub command_on_file {
Subroutine command_on_file: called CC=5 SCAR=16.1
Pod documented
91 6 my $command = shift;
92 6 my $message = shift;
93 6 ▶ croak "Need at least a file name" unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 5 6
94 5 my ($file, $line, $title, $col ) = @_;
95 5 my @data;
96 5 push( @data, "file=$file");
97 5 ▶ push( @data, "line=$line") if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 4 1 5
98 5 ▶ if ( $title ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($title) { } 3 2 5
99 3 push( @data, "title=$title"."::$message");
100 } else {
101 2 push( @data, "title=".uc(substr($command,2))."::$message");
102 }
103 5 ▶ push( @data, "col=$col") if $col;
Branch: 1 branch
BranchTrueFalseTotal
if $col 2 3 5
104 5 $command .= " ".join(",", @data );
105 5 say $command;
106 }
107  
108 1 ▶sub start_group {
Subroutine start_group: called CC=1 SCAR=0.0
Pod documented
109 1 say "::group::" . shift;
110 }
111  
112 1 ▶sub end_group {
Subroutine end_group: called CC=1 SCAR=0.0
Pod documented
113 1 say "::endgroup::";
114 }
115  
116 1 ▶sub set_failed {
Subroutine set_failed: called CC=1 SCAR=0.0
Pod documented
117 1 error( @_ );
118 1 exit( 1);
119 }
120  
121 0 ▶sub exit_action {
Subroutine exit_action: not called CC=1 SCAR=6.9
Pod documented
122 0 exit( $EXIT_CODE );
123 }
124  
125 1 ▶sub add_to_job_summary {
Subroutine add_to_job_summary: called CC=1 SCAR=0.0
Pod documented
126 1 my $message = shift;
127 1 _write_to_github_file( 'STEP_SUMMARY', "$message" );
128 }
129  
130 6 "Action!"; # Magic true value required at end of module
131 __END__
↑ Summary