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