allow option to release from a different branch
[p5sagit/Distar.git] / helpers / preflight
1 #!/usr/bin/env perl
2 use strict;
3 use warnings FATAL => 'all';
4 use Config;
5 use File::Spec;
6 use File::Find;
7 use ExtUtils::MakeMaker ();
8 use Getopt::Long qw(:config gnu_getopt);
9
10 GetOptions(
11   "branch=s"     => \(my $branch = 'master'),
12 ) or die("Error in command line arguments\n");
13
14 my $version = shift or die "version required!";
15
16 my $make = $Config{make};
17 my $null = File::Spec->devnull;
18
19 system("git fetch");
20 if (system("git rev-parse --quiet --verify v$version >$null") == 0) {
21   die "Tag v$version already exists!";
22 }
23
24 File::Find::find({ no_chdir => 1, wanted => sub {
25   return
26     unless -f && /\.pm$/;
27   my $file_version = MM->parse_version($_);
28   die "Module $_ version $file_version doesn't match dist version $version"
29     unless $file_version eq 'undef' || $file_version eq $version;
30 }}, 'lib');
31
32 for (scalar `"$make" manifest 2>&1 >$null`) {
33   $_ && die "$make manifest changed:\n$_ Go check it and retry";
34 }
35
36 for (scalar `git status`) {
37   /^(?:# )?On branch \Q$branch\E/ || die "Not on $branch. EEEK";
38   /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream";
39 }
40
41 for (scalar `git diff`) {
42   length && die "Outstanding changes";
43 }
44 my $ymd = sprintf(
45   "%i-%02i-%02i", (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3]
46 );
47 my $changes_line = "$version - $ymd\n";
48 my @cached = grep /^\+/, `git diff --cached -U0`;
49 @cached > 0 or die "Please add:\n\n$changes_line\nto Changes stage Changes (git add Changes)";
50 @cached == 2 or die "Pre-commit Changes not just Changes line";
51 $cached[0] =~ /^\+\+\+ .\/Changes\n/ or die "Changes not changed";
52 $cached[1] eq "+$changes_line" or die "Changes new line should be: \n\n$changes_line ";
53
54 { no warnings 'exec'; `cpan-upload -h`; }
55 $? and die "cpan-upload not available";