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