| File: | bin/deploy-workflows |
| Coverage: | 94.6% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/env perl | |||||
| 2 | ||||||
| 3 | 12 12 12 | 23730 11 220 | use strict; | |||
| 4 | 12 12 12 | 23 8 228 | use warnings; | |||
| 5 | 12 12 12 | 2014 96745 21 | use autodie qw(:all); | |||
| 6 | ||||||
| 7 | 12 12 12 | 116116 3383 333 | use Data::Section::Simple qw(get_data_section); | |||
| 8 | 12 12 12 | 29 6 291 | use File::Path qw(make_path); | |||
| 9 | 12 12 12 | 17 11 130 | use File::Spec; | |||
| 10 | 12 12 12 | 3742 54891 19 | use Getopt::Long qw(GetOptions); | |||
| 11 | 12 12 12 | 3425 312665 2729 | use Pod::Usage; | |||
| 12 | ||||||
| 13 | 12 | 792837 | our $VERSION = '0.46'; | |||
| 14 | ||||||
| 15 - 75 | =head1 NAME deploy-workflows - Deploy ATG GitHub Actions workflows to a CPAN module repository =head1 SYNOPSIS deploy-workflows deploy-workflows --target /path/to/my-module deploy-workflows --force deploy-workflows --dry-run =head1 DESCRIPTION Copies the two L<App::Test::Generator> GitHub Actions workflow files into the C<.github/workflows/> directory of the target repository: =over 4 =item * C<dashboard.yml> â generates the HTML test dashboard on every push and after each mutation run; deploys to GitHub Pages. =item * C<mutate.yml> â runs mutation testing on a monthly schedule and on manual dispatch. =back Both files are embedded in this script verbatim from the ATG distribution and work without any sibling files or additional configuration. After deploying, commit the two new files and push to your repository. The workflows will activate on the next push to C<main> or C<master>. =head1 OPTIONS =over 4 =item B<--target|-t> DIR Root directory of the target module repository. Defaults to the current working directory. =item B<--force|-f> Overwrite existing workflow files. Without this flag the script exits with an error if either file already exists. =item B<--dry-run|-n> Show what would be written without creating any files. =item B<--version|-V> Print the version of L<App::Test::Generator> and exit. =item B<--help|-h> Show this help and exit. =back =cut | |||||
| 76 | ||||||
| 77 | 12 | 12 | my ($target, $force, $dry_run, $help, $version); | |||
| 78 | ||||||
| 79 | 12 | 24 | Getopt::Long::Configure('bundling'); | |||
| 80 | 12 | 203 | GetOptions( | |||
| 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 | 4599 | pod2usage(-exitval => 0, -verbose => 1) if $help; | |||
| 89 | ||||||
| 90 | 11 | 12 | if($version) { | |||
| 91 | 1 | 3 | print $VERSION, "\n"; | |||
| 92 | 1 | 0 | exit 0; | |||
| 93 | } | |||||
| 94 | ||||||
| 95 | 10 | 14 | $target //= File::Spec->curdir(); | |||
| 96 | 10 | 103 | $target = File::Spec->rel2abs($target); | |||
| 97 | ||||||
| 98 | 10 | 90 | die "deploy-workflows: target directory '$target' does not exist\n" unless -d $target; | |||
| 99 | ||||||
| 100 | 9 | 39 | my $wf_dir = File::Spec->catdir($target, '.github', 'workflows'); | |||
| 101 | ||||||
| 102 | 9 | 40 | 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 | 2935 | unless($force || $dry_run) { | |||
| 109 | 7 | 14 | for my $name (sort keys %files) { | |||
| 110 | 13 | 52 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 111 | 13 | 123 | if(-e $dest) { | |||
| 112 | 1 | 0 | die "deploy-workflows: '$dest' already exists; use --force to overwrite\n"; | |||
| 113 | } | |||||
| 114 | } | |||||
| 115 | } | |||||
| 116 | ||||||
| 117 | 8 | 12 | if($dry_run) { | |||
| 118 | 1 | 14 | print "Would create: $wf_dir/\n" unless -d $wf_dir; | |||
| 119 | 1 | 2 | for my $name (sort keys %files) { | |||
| 120 | 2 | 8 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 121 | 2 | 7 | print -e $dest ? "Would overwrite: $dest\n" : "Would write: $dest\n"; | |||
| 122 | } | |||||
| 123 | 1 | 0 | exit 0; | |||
| 124 | } | |||||
| 125 | ||||||
| 126 | 7 | 1065 | make_path($wf_dir) unless -d $wf_dir; | |||
| 127 | ||||||
| 128 | 7 | 43 | for my $name (sort keys %files) { | |||
| 129 | 14 | 78 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 130 | 14 | 34 | open my $fh, '>', $dest; | |||
| 131 | 14 | 5613 | print $fh $files{$name}; | |||
| 132 | 14 | 33 | close $fh; | |||
| 133 | 14 | 2869 | print "Wrote: $dest\n"; | |||
| 134 | } | |||||
| 135 | ||||||
| 136 | 7 | 10 | print "\nNext steps:\n"; | |||
| 137 | 7 | 7 | print " git add .github/workflows/dashboard.yml .github/workflows/mutate.yml\n"; | |||
| 138 | 7 | 4 | print " git commit -m 'Add ATG GitHub Actions workflows'\n"; | |||
| 139 | 7 | 0 | print " git push\n"; | |||
| 140 | ||||||