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