make sure all declared versions match
[p5sagit/Distar.git] / lib / Distar.pm
CommitLineData
42e08a83 1package Distar;
2
3use strictures 1;
4use base qw(Exporter);
5
ca313d5a 6use Config;
28268771 7use File::Spec;
ca313d5a 8
42e08a83 9our @EXPORT = qw(
5154970c 10 author manifest_include run_preflight
42e08a83 11);
12
13sub import {
14 strictures->import;
15 shift->export_to_level(1,@_);
16}
17
18sub author { our $Author = shift }
19
d7998bfa 20our $Ran_Preflight;
21
42e08a83 22our @Manifest = (
23 'lib' => '.pm',
24 't' => '.t',
25 't/lib' => '.pm',
26 'xt' => '.t',
27 'xt/lib' => '.pm',
1d950b4a 28 '' => qr{[^/]*\.PL},
42e08a83 29 '' => qr{Changes|MANIFEST|README|META\.yml},
42e08a83 30 'maint' => qr{[^.].*},
31);
32
33sub manifest_include {
34 push @Manifest, @_;
35}
36
37sub write_manifest_skip {
38 use autodie;
39 my @files = @Manifest;
40 my @parts;
41 while (my ($dir, $spec) = splice(@files, 0, 2)) {
42 my $re = ($dir ? $dir.'/' : '').
43 ((ref($spec) eq 'Regexp')
44 ? $spec
45 : !ref($spec)
46 ? ".*\Q${spec}\E"
a3e39afd 47 # print ref as well as stringification in case of overload ""
42e08a83 48 : die "spec must be string or regexp, was: ${spec} (${\ref $spec})");
49 push @parts, $re;
50 }
51 my $final = '^(?!'.join('|', map "${_}\$", @parts).')';
52 open my $skip, '>', 'MANIFEST.SKIP';
53 print $skip "${final}\n";
54 close $skip;
55}
56
5154970c 57sub run_preflight {
d7998bfa 58 $Ran_Preflight = 1;
12b4d7c3 59 my $version = $ARGV[0];
d7998bfa 60
5154970c 61 system("git fetch");
62
ca313d5a 63 my $make = $Config{make};
28268771 64 my $null = File::Spec->devnull;
ca313d5a 65
12b4d7c3 66 require ExtUtils::MakeMaker;
67 require File::Find;
68 File::Find::find({ no_chdir => 1, wanted => sub {
69 return
70 unless -f && /\.pm$/;
71 my $file_version = MM->parse_version($_);
72 die "Module $_ version $file_version doesn't match dist version $version"
73 unless $file_version eq 'undef' || $file_version eq $version;
74 }}, 'lib');
75
4df609ef 76 for (scalar `"$make" manifest 2>&1 >$null`) {
ca313d5a 77 $_ && die "$make manifest changed:\n$_ Go check it and retry";
41c39fda 78 }
79
5154970c 80 for (scalar `git status`) {
50d3c4ad 81 /^# On branch master/ || die "Not on master. EEEK";
325f6231 82 /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream";
5154970c 83 }
84
85 for (scalar `git diff`) {
7374f43f 86 length && die "Outstanding changes";
5154970c 87 }
5154970c 88 my $ymd = sprintf(
89 "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3]
90 );
59fcfa65 91 my @cached = grep /^\+/, `git diff --cached -U0`;
12b4d7c3 92 @cached > 0 or die "Please add:\n\n$version - $ymd\n\nto Changes stage Changes (git add Changes)";
59fcfa65 93 @cached == 2 or die "Pre-commit Changes not just Changes line";
c373c51b 94 $cached[0] =~ /^\+\+\+ .\/Changes\n/ or die "Changes not changed";
12b4d7c3 95 $cached[1] eq "+$version - $ymd\n" or die "Changes new line should be: \n\n$version - $ymd\n ";
5154970c 96}
97
7ac9c6a6 98sub MY::postamble {
b0401762 99 my ($self, %extra) = @_;
100
a2f6bc7b 101 my $post = <<'END';
5154970c 102preflight:
584b890c 103 perl -IDistar/lib -MDistar -erun_preflight $(VERSION)
72932296 104release: preflight
105 $(MAKE) disttest
27dbd26e 106 rm -rf $(DISTVNAME)
107 $(MAKE) $(DISTVNAME).tar$(SUFFIX)
42e08a83 108 git commit -a -m "Release commit for $(VERSION)"
401ece0b 109 git tag v$(VERSION) -m "release v$(VERSION)"
65a1f7d9 110 cpan-upload $(DISTVNAME).tar$(SUFFIX)
2c636792 111 git push origin v$(VERSION) HEAD
5154970c 112distdir: readmefile
113readmefile: create_distdir
114 pod2text $(VERSION_FROM) >$(DISTVNAME)/README
046ee554 115 $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-readme-to-manifest
42e08a83 116END
a2f6bc7b 117 if (open my $fh, '<', 'maint/Makefile.include') {
118 $post .= do { local $/; <$fh> };
119 }
dfee3207 120
121 # add on any extra args that WriteMakefile chose to pass us
122 # (note that Devel::Declare, and possibly others, use this)
b0401762 123 $post .= "\n" . join('', %extra) if keys %extra;
dfee3207 124
a2f6bc7b 125 return $post;
7ac9c6a6 126}
42e08a83 127
128{
129 no warnings 'redefine';
130 sub main::WriteMakefile {
131 my %args = @_;
42e08a83 132 ExtUtils::MakeMaker::WriteMakefile(
2f88acd6 133 LICENSE => 'perl',
42e08a83 134 @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM},
281cfaad 135 test => { TESTS => ($args{test}{TESTS}||'t/*.t').' xt/*.t' },
42e08a83 136 );
137 }
138}
139
140END {
d7998bfa 141 write_manifest_skip() unless $Ran_Preflight
42e08a83 142}
143
1441;