bin/deploy-workflows

filter: Statementstmt 100% 59 / 59 Branchbran 85.0% 17 / 20 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 92.7% 90 / 97 CC 1 SCAR 0.0
CC
1
Cov
94%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« bin/benchmark-generator ↑ Summary
1 #!/usr/bin/env perl
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use autodie qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use Data::Section::Simple qw(get_data_section);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 12 our $VERSION = '0.50';
14  
15 =head1 NAME
16  
17 deploy-workflows - Deploy ATG GitHub Actions workflows to a CPAN module repository
18  
19 =head1 SYNOPSIS
20  
21 deploy-workflows
22 deploy-workflows --target /path/to/my-module
23 deploy-workflows --force
24 deploy-workflows --dry-run
25  
26 =head1 DESCRIPTION
27  
28 Copies the two L<App::Test::Generator> GitHub Actions workflow files into
29 the C<.github/workflows/> directory of the target repository:
30  
31 =over 4
32  
33 =item * C<dashboard.yml> - generates the HTML test dashboard on every push
34 and after each mutation run; deploys to GitHub Pages.
35  
36 =item * C<mutate.yml> - runs mutation testing on a monthly schedule and on
37 manual dispatch.
38  
39 =back
40  
41 Both files are embedded in this script verbatim from the ATG distribution
42 and work without any sibling files or additional configuration.
43  
44 After deploying, commit the two new files and push to your repository.
45 The workflows will activate on the next push to C<main> or C<master>.
46  
47 =head1 OPTIONS
48  
49 =over 4
50  
51 =item B<--target|-t> DIR
52  
53 Root directory of the target module repository. Defaults to the current
54 working directory.
55  
56 =item B<--force|-f>
57  
58 Overwrite existing workflow files. Without this flag the script exits with
59 an error if either file already exists.
60  
61 =item B<--dry-run|-n>
62  
63 Show what would be written without creating any files.
64  
65 =item B<--version|-V>
66  
67 Print the version of L<App::Test::Generator> and exit.
68  
69 =item B<--help|-h>
70  
71 Show this help and exit.
72  
73 =back
74  
75 =cut
76  
77 12 my ($target, $force, $dry_run, $help, $version);
78  
79 12 Getopt::Long::Configure('bundling');
80 12 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("target|t=s", \$target, "force|f", \$force, "dry-run|n", \$dry_run, "version|V", \$version, "help|h", \$help) or pod2usage(2) 12 0 12
81 'target|t=s' => \$target,
82 'force|f' => \$force,
83 'dry-run|n' => \$dry_run,
84 'version|V' => \$version,
85 'help|h' => \$help,
86 ) or pod2usage(2);
87  
88 12 ▶pod2usage(-exitval => 0, -verbose => 1) if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 1 11 12
89  
90 11 ▶if($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 1 10 11
91 1 print $VERSION, "\n";
92 1 exit 0;
93 }
94  
95 10 ▶$target //= File::Spec->curdir();
Condition33%1/3
$target //= "File::Spec"->curdir
l!l&&r!l&&!r
1000
MC/DC0%0/2
$target //= "File::Spec"->curdir
$target "File::Spec"->curdir
Truth table33%1/3
A //= B
A= $targetB= "File::Spec"->curdir
ABresult
1X1
011
000
96 10 $target = File::Spec->rel2abs($target);
97  
98 10 ▶die "deploy-workflows: target directory '$target' does not exist\n" unless -d $target;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $target 1 9 10
99  
100 9 my $wf_dir = File::Spec->catdir($target, '.github', 'workflows');
101  
102 9 my %files = (
103 'dashboard.yml' => get_data_section('dashboard.yml'),
104 'mutate.yml' => get_data_section('mutate.yml'),
105 );
106  
107 # Pre-flight: check for existing files before writing anything
108 9 ▶unless($force || $dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($force or $dry_run) 7 2 9
Condition100%3/3
$force or $dry_run
l!l&&r!l&&!r
117
MC/DC100%2/2
$force or $dry_run
$force $dry_run
Truth table100%3/3
A or B
A= $forceB= $dry_run
ABresult
1X1
011
000
109 7 for my $name (sort keys %files) {
110 13 my $dest = File::Spec->catfile($wf_dir, $name);
111 13 ▶ if(-e $dest) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $dest) 1 12 13
112 1 die "deploy-workflows: '$dest' already exists; use --force to overwrite\n";
113 }
114 }
115 }
116  
117 8 ▶if($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) 1 7 8
118 1 ▶ print "Would create: $wf_dir/\n" unless -d $wf_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $wf_dir 1 0 1
119 1 for my $name (sort keys %files) {
120 2 my $dest = File::Spec->catfile($wf_dir, $name);
121 2 ▶ print -e $dest ? "Would overwrite: $dest\n" : "Would write: $dest\n";
Branch: 1 branch
BranchTrueFalseTotal
-e $dest ? : 0 2 2
122 }
123 1 exit 0;
124 }
125  
126 7 ▶make_path($wf_dir) unless -d $wf_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $wf_dir 6 1 7
127  
128 7 for my $name (sort keys %files) {
129 14 my $dest = File::Spec->catfile($wf_dir, $name);
130 14 open my $fh, '>', $dest;
131 14 print $fh $files{$name};
132 14 close $fh;
133 14 print "Wrote: $dest\n";
134 }
135  
136 7 print "\nNext steps:\n";
137 7 print " git add .github/workflows/dashboard.yml .github/workflows/mutate.yml\n";
138 7 print " git commit -m 'Add ATG GitHub Actions workflows'\n";
139 7 print " git push\n";
140  
141 __DATA__
« bin/benchmark-generator ↑ Summary