allow option to release from a different branch
[p5sagit/Distar.git] / helpers / preflight
CommitLineData
be032607 1#!/usr/bin/env perl
2use strict;
3use warnings FATAL => 'all';
4use Config;
5use File::Spec;
6use File::Find;
7use ExtUtils::MakeMaker ();
190976f8 8use Getopt::Long qw(:config gnu_getopt);
be032607 9
190976f8 10GetOptions(
11 "branch=s" => \(my $branch = 'master'),
12) or die("Error in command line arguments\n");
13
14my $version = shift or die "version required!";
be032607 15
16my $make = $Config{make};
17my $null = File::Spec->devnull;
18
19system("git fetch");
20if (system("git rev-parse --quiet --verify v$version >$null") == 0) {
21 die "Tag v$version already exists!";
22}
23
24File::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
32for (scalar `"$make" manifest 2>&1 >$null`) {
33 $_ && die "$make manifest changed:\n$_ Go check it and retry";
34}
35
36for (scalar `git status`) {
190976f8 37 /^(?:# )?On branch \Q$branch\E/ || die "Not on $branch. EEEK";
be032607 38 /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream";
39}
40
41for (scalar `git diff`) {
42 length && die "Outstanding changes";
43}
44my $ymd = sprintf(
45 "%i-%02i-%02i", (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3]
46);
47my $changes_line = "$version - $ymd\n";
48my @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";