| File: | bin/deploy-workflows |
| Coverage: | 94.6% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/env perl | |||||
| 2 | ||||||
| 3 | 12 12 12 | 26924 12 221 | use strict; | |||
| 4 | 12 12 12 | 23 5 268 | use warnings; | |||
| 5 | 12 12 12 | 2165 96902 21 | use autodie qw(:all); | |||
| 6 | ||||||
| 7 | 12 12 12 | 117677 3558 338 | use Data::Section::Simple qw(get_data_section); | |||
| 8 | 12 12 12 | 29 11 309 | use File::Path qw(make_path); | |||
| 9 | 12 12 12 | 20 7 119 | use File::Spec; | |||
| 10 | 12 12 12 | 4131 53356 26 | use Getopt::Long qw(GetOptions); | |||
| 11 | 12 12 12 | 3887 307561 3033 | use Pod::Usage; | |||
| 12 | ||||||
| 13 | 12 | 804192 | 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 | 22 | my ($target, $force, $dry_run, $help, $version); | |||
| 78 | ||||||
| 79 | 12 | 48 | Getopt::Long::Configure('bundling'); | |||
| 80 | 12 | 286 | 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 | 5375 | pod2usage(-exitval => 0, -verbose => 1) if $help; | |||
| 89 | ||||||
| 90 | 11 | 20 | if($version) { | |||
| 91 | 1 | 5 | print $VERSION, "\n"; | |||
| 92 | 1 | 0 | exit 0; | |||
| 93 | } | |||||
| 94 | ||||||
| 95 | 10 | 17 | $target //= File::Spec->curdir(); | |||
| 96 | 10 | 177 | $target = File::Spec->rel2abs($target); | |||
| 97 | ||||||
| 98 | 10 | 117 | die "deploy-workflows: target directory '$target' does not exist\n" unless -d $target; | |||
| 99 | ||||||
| 100 | 9 | 73 | my $wf_dir = File::Spec->catdir($target, '.github', 'workflows'); | |||
| 101 | ||||||
| 102 | 9 | 37 | 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 | 3215 | unless($force || $dry_run) { | |||
| 109 | 7 | 14 | for my $name (sort keys %files) { | |||
| 110 | 13 | 55 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 111 | 13 | 138 | if(-e $dest) { | |||
| 112 | 1 | 0 | die "deploy-workflows: '$dest' already exists; use --force to overwrite\n"; | |||
| 113 | } | |||||
| 114 | } | |||||
| 115 | } | |||||
| 116 | ||||||
| 117 | 8 | 16 | if($dry_run) { | |||
| 118 | 1 | 21 | print "Would create: $wf_dir/\n" unless -d $wf_dir; | |||
| 119 | 1 | 2 | for my $name (sort keys %files) { | |||
| 120 | 2 | 9 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 121 | 2 | 9 | print -e $dest ? "Would overwrite: $dest\n" : "Would write: $dest\n"; | |||
| 122 | } | |||||
| 123 | 1 | 0 | exit 0; | |||
| 124 | } | |||||
| 125 | ||||||
| 126 | 7 | 1267 | make_path($wf_dir) unless -d $wf_dir; | |||
| 127 | ||||||
| 128 | 7 | 19 | for my $name (sort keys %files) { | |||
| 129 | 14 | 89 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 130 | 14 | 47 | open my $fh, '>', $dest; | |||
| 131 | 14 | 6219 | print $fh $files{$name}; | |||
| 132 | 14 | 40 | close $fh; | |||
| 133 | 14 | 2913 | print "Wrote: $dest\n"; | |||
| 134 | } | |||||
| 135 | ||||||
| 136 | 7 | 14 | print "\nNext steps:\n"; | |||
| 137 | 7 | 9 | print " git add .github/workflows/dashboard.yml .github/workflows/mutate.yml\n"; | |||
| 138 | 7 | 8 | print " git commit -m 'Add ATG GitHub Actions workflows'\n"; | |||
| 139 | 7 | 0 | print " git push\n"; | |||
| 140 | ||||||