| File: | bin/deploy-workflows |
| Coverage: | 94.6% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/env perl | |||||
| 2 | ||||||
| 3 | 12 12 12 | 19595 10 144 | use strict; | |||
| 4 | 12 12 12 | 12 9 184 | use warnings; | |||
| 5 | 12 12 12 | 1663 72594 14 | use autodie qw(:all); | |||
| 6 | ||||||
| 7 | 12 12 12 | 87802 2693 250 | use Data::Section::Simple qw(get_data_section); | |||
| 8 | 12 12 12 | 22 5 227 | use File::Path qw(make_path); | |||
| 9 | 12 12 12 | 13 6 78 | use File::Spec; | |||
| 10 | 12 12 12 | 3091 40133 20 | use Getopt::Long qw(GetOptions); | |||
| 11 | 12 12 12 | 2750 230351 2112 | use Pod::Usage; | |||
| 12 | ||||||
| 13 | 12 | 627781 | our $VERSION = '0.52'; | |||
| 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 | 9 | my ($target, $force, $dry_run, $help, $version); | |||
| 78 | ||||||
| 79 | 12 | 27 | Getopt::Long::Configure('bundling'); | |||
| 80 | 12 | 199 | 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 | 3872 | pod2usage(-exitval => 0, -verbose => 1) if $help; | |||
| 89 | ||||||
| 90 | 11 | 25 | if($version) { | |||
| 91 | 1 | 4 | print $VERSION, "\n"; | |||
| 92 | 1 | 0 | exit 0; | |||
| 93 | } | |||||
| 94 | ||||||
| 95 | 10 | 11 | $target //= File::Spec->curdir(); | |||
| 96 | 10 | 100 | $target = File::Spec->rel2abs($target); | |||
| 97 | ||||||
| 98 | 10 | 63 | die "deploy-workflows: target directory '$target' does not exist\n" unless -d $target; | |||
| 99 | ||||||
| 100 | 9 | 31 | my $wf_dir = File::Spec->catdir($target, '.github', 'workflows'); | |||
| 101 | ||||||
| 102 | 9 | 20 | 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 | 2623 | unless($force || $dry_run) { | |||
| 109 | 7 | 11 | for my $name (sort keys %files) { | |||
| 110 | 13 | 37 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 111 | 13 | 102 | if(-e $dest) { | |||
| 112 | 1 | 0 | die "deploy-workflows: '$dest' already exists; use --force to overwrite\n"; | |||
| 113 | } | |||||
| 114 | } | |||||
| 115 | } | |||||
| 116 | ||||||
| 117 | 8 | 8 | if($dry_run) { | |||
| 118 | 1 | 18 | print "Would create: $wf_dir/\n" unless -d $wf_dir; | |||
| 119 | 1 | 1 | for my $name (sort keys %files) { | |||
| 120 | 2 | 7 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 121 | 2 | 5 | print -e $dest ? "Would overwrite: $dest\n" : "Would write: $dest\n"; | |||
| 122 | } | |||||
| 123 | 1 | 0 | exit 0; | |||
| 124 | } | |||||
| 125 | ||||||
| 126 | 7 | 974 | make_path($wf_dir) unless -d $wf_dir; | |||
| 127 | ||||||
| 128 | 7 | 13 | for my $name (sort keys %files) { | |||
| 129 | 14 | 56 | my $dest = File::Spec->catfile($wf_dir, $name); | |||
| 130 | 14 | 24 | open my $fh, '>', $dest; | |||
| 131 | 14 | 4482 | print $fh $files{$name}; | |||
| 132 | 14 | 31 | close $fh; | |||
| 133 | 14 | 2202 | print "Wrote: $dest\n"; | |||
| 134 | } | |||||
| 135 | ||||||
| 136 | 7 | 7 | print "\nNext steps:\n"; | |||
| 137 | 7 | 6 | print " git add .github/workflows/dashboard.yml .github/workflows/mutate.yml\n"; | |||
| 138 | 7 | 11 | print " git commit -m 'Add ATG GitHub Actions workflows'\n"; | |||
| 139 | 7 | 0 | print " git push\n"; | |||
| 140 | ||||||