split version checking out from preflight
[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;
190976f8 7use Getopt::Long qw(:config gnu_getopt);
be032607 8
190976f8 9GetOptions(
10 "branch=s" => \(my $branch = 'master'),
9b920c5c 11 "changelog=s" => \(my $changelog = 'Changes'),
190976f8 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
be032607 24for (scalar `"$make" manifest 2>&1 >$null`) {
25 $_ && die "$make manifest changed:\n$_ Go check it and retry";
26}
27
28for (scalar `git status`) {
190976f8 29 /^(?:# )?On branch \Q$branch\E/ || die "Not on $branch. EEEK";
be032607 30 /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream";
31}
32
33for (scalar `git diff`) {
34 length && die "Outstanding changes";
35}
36my $ymd = sprintf(
37 "%i-%02i-%02i", (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3]
38);
39my $changes_line = "$version - $ymd\n";
40my @cached = grep /^\+/, `git diff --cached -U0`;
9b920c5c 41@cached > 0 or die "Please add:\n\n$changes_line\nto $changelog and stage $changelog (git add $changelog)";
42@cached == 2 or die "All '$changelog' changes must be committed aside from version heading";
43$cached[0] =~ /^\+\+\+ .\/\Q$changelog\E\n/ or die "$changelog not changed";
44$cached[1] eq "+$changes_line" or die "$changelog new line should be: \n\n$changes_line ";
be032607 45
46{ no warnings 'exec'; `cpan-upload -h`; }
47$? and die "cpan-upload not available";