push branch and tag at the same time
[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;
59
5154970c 60 system("git fetch");
61
ca313d5a 62 my $make = $Config{make};
28268771 63 my $null = File::Spec->devnull;
ca313d5a 64
4df609ef 65 for (scalar `"$make" manifest 2>&1 >$null`) {
ca313d5a 66 $_ && die "$make manifest changed:\n$_ Go check it and retry";
41c39fda 67 }
68
5154970c 69 for (scalar `git status`) {
50d3c4ad 70 /^# On branch master/ || die "Not on master. EEEK";
325f6231 71 /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream";
5154970c 72 }
73
74 for (scalar `git diff`) {
7374f43f 75 length && die "Outstanding changes";
5154970c 76 }
5154970c 77 my $ymd = sprintf(
78 "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3]
79 );
59fcfa65 80 my @cached = grep /^\+/, `git diff --cached -U0`;
4477708b 81 @cached > 0 or die "Please add:\n\n$ARGV[0] - $ymd\n\nto Changes stage Changes (git add Changes)";
59fcfa65 82 @cached == 2 or die "Pre-commit Changes not just Changes line";
c373c51b 83 $cached[0] =~ /^\+\+\+ .\/Changes\n/ or die "Changes not changed";
5154970c 84 $cached[1] eq "+$ARGV[0] - $ymd\n" or die "Changes new line should be: \n\n$ARGV[0] - $ymd\n ";
85}
86
7ac9c6a6 87sub MY::postamble {
a2f6bc7b 88 my $post = <<'END';
5154970c 89preflight:
584b890c 90 perl -IDistar/lib -MDistar -erun_preflight $(VERSION)
72932296 91release: preflight
92 $(MAKE) disttest
27dbd26e 93 rm -rf $(DISTVNAME)
94 $(MAKE) $(DISTVNAME).tar$(SUFFIX)
42e08a83 95 git commit -a -m "Release commit for $(VERSION)"
401ece0b 96 git tag v$(VERSION) -m "release v$(VERSION)"
65a1f7d9 97 cpan-upload $(DISTVNAME).tar$(SUFFIX)
452dfa09 98 git push origin --tags HEAD
5154970c 99distdir: readmefile
100readmefile: create_distdir
101 pod2text $(VERSION_FROM) >$(DISTVNAME)/README
046ee554 102 $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-readme-to-manifest
42e08a83 103END
a2f6bc7b 104 if (open my $fh, '<', 'maint/Makefile.include') {
105 $post .= do { local $/; <$fh> };
106 }
107 return $post;
7ac9c6a6 108}
42e08a83 109
110{
111 no warnings 'redefine';
112 sub main::WriteMakefile {
113 my %args = @_;
42e08a83 114 ExtUtils::MakeMaker::WriteMakefile(
2f88acd6 115 LICENSE => 'perl',
42e08a83 116 @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM},
281cfaad 117 test => { TESTS => ($args{test}{TESTS}||'t/*.t').' xt/*.t' },
42e08a83 118 );
119 }
120}
121
122END {
d7998bfa 123 write_manifest_skip() unless $Ran_Preflight
42e08a83 124}
125
1261;