Commit | Line | Data |
42e08a83 |
1 | package Distar; |
2 | |
3 | use strictures 1; |
4 | use base qw(Exporter); |
5 | |
6 | our @EXPORT = qw( |
5154970c |
7 | author manifest_include run_preflight |
42e08a83 |
8 | ); |
9 | |
10 | sub import { |
11 | strictures->import; |
12 | shift->export_to_level(1,@_); |
13 | } |
14 | |
15 | sub author { our $Author = shift } |
16 | |
d7998bfa |
17 | our $Ran_Preflight; |
18 | |
42e08a83 |
19 | our @Manifest = ( |
20 | 'lib' => '.pm', |
21 | 't' => '.t', |
22 | 't/lib' => '.pm', |
23 | 'xt' => '.t', |
24 | 'xt/lib' => '.pm', |
1d950b4a |
25 | '' => qr{[^/]*\.PL}, |
42e08a83 |
26 | '' => qr{Changes|MANIFEST|README|META\.yml}, |
42e08a83 |
27 | 'maint' => qr{[^.].*}, |
28 | ); |
29 | |
30 | sub manifest_include { |
31 | push @Manifest, @_; |
32 | } |
33 | |
34 | sub write_manifest_skip { |
35 | use autodie; |
36 | my @files = @Manifest; |
37 | my @parts; |
38 | while (my ($dir, $spec) = splice(@files, 0, 2)) { |
39 | my $re = ($dir ? $dir.'/' : ''). |
40 | ((ref($spec) eq 'Regexp') |
41 | ? $spec |
42 | : !ref($spec) |
43 | ? ".*\Q${spec}\E" |
a3e39afd |
44 | # print ref as well as stringification in case of overload "" |
42e08a83 |
45 | : die "spec must be string or regexp, was: ${spec} (${\ref $spec})"); |
46 | push @parts, $re; |
47 | } |
48 | my $final = '^(?!'.join('|', map "${_}\$", @parts).')'; |
49 | open my $skip, '>', 'MANIFEST.SKIP'; |
50 | print $skip "${final}\n"; |
51 | close $skip; |
52 | } |
53 | |
5154970c |
54 | sub run_preflight { |
d7998bfa |
55 | $Ran_Preflight = 1; |
56 | |
5154970c |
57 | system("git fetch"); |
58 | |
41c39fda |
59 | for (scalar `make manifest 2>&1 >/dev/null`) { |
60 | $_ && die "make manifest changed:\n$_ Go check it and retry"; |
61 | } |
62 | |
5154970c |
63 | for (scalar `git status`) { |
50d3c4ad |
64 | /^# On branch master/ || die "Not on master. EEEK"; |
5154970c |
65 | /Your branch is (behind|ahead of)/ && die "Not synced with upstream"; |
66 | } |
67 | |
68 | for (scalar `git diff`) { |
69 | length && die "Oustanding changes"; |
70 | } |
5154970c |
71 | my $ymd = sprintf( |
72 | "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3] |
73 | ); |
59fcfa65 |
74 | my @cached = grep /^\+/, `git diff --cached -U0`; |
75 | @cached > 0 or die "Please add:\n\n$ARGV[0] - $ymd\n\nto Changes and git add"; |
76 | @cached == 2 or die "Pre-commit Changes not just Changes line"; |
77 | $cached[0] eq "+++ b/Changes\n" or die "Changes not changed"; |
5154970c |
78 | $cached[1] eq "+$ARGV[0] - $ymd\n" or die "Changes new line should be: \n\n$ARGV[0] - $ymd\n "; |
79 | } |
80 | |
42e08a83 |
81 | sub MY::postamble { <<'END'; } |
5154970c |
82 | preflight: |
584b890c |
83 | perl -IDistar/lib -MDistar -erun_preflight $(VERSION) |
e06cbac3 |
84 | upload: preflight $(DISTVNAME).tar$(SUFFIX) |
5154970c |
85 | cpan-upload $(DISTVNAME).tar$(SUFFIX) |
42e08a83 |
86 | release: upload |
87 | git commit -a -m "Release commit for $(VERSION)" |
401ece0b |
88 | git tag v$(VERSION) -m "release v$(VERSION)" |
42e08a83 |
89 | git push --tags |
1fcacfb8 |
90 | git push |
5154970c |
91 | distdir: readmefile |
92 | readmefile: create_distdir |
93 | pod2text $(VERSION_FROM) >$(DISTVNAME)/README |
59fcfa65 |
94 | $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) -MExtUtils::Manifest=maniadd -e 'eval { maniadd({q{README} => q{README file (added by Distar)}}) } ' \ |
95 | -e ' or print "Could not add README to MANIFEST: $${'\''@'\''}\n"' -- |
42e08a83 |
96 | END |
97 | |
98 | { |
99 | no warnings 'redefine'; |
100 | sub main::WriteMakefile { |
101 | my %args = @_; |
42e08a83 |
102 | ExtUtils::MakeMaker::WriteMakefile( |
2f88acd6 |
103 | LICENSE => 'perl', |
42e08a83 |
104 | @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM}, |
281cfaad |
105 | test => { TESTS => ($args{test}{TESTS}||'t/*.t').' xt/*.t' }, |
42e08a83 |
106 | ); |
107 | } |
108 | } |
109 | |
110 | END { |
d7998bfa |
111 | write_manifest_skip() unless $Ran_Preflight |
42e08a83 |
112 | } |
113 | |
114 | 1; |