Repository navigation
Expand file tree
/
Copy pathmake_release_tag
More file actions
executable file
·216 lines (159 loc) · 5.13 KB
/
Copy pathmake_release_tag
File metadata and controls
executable file
·216 lines (159 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env perl
use strict;
use warnings;
use Carp;
use Cwd;
use Data::Dumper;
use FindBin;
use File::Spec;
use File::Basename;
use Getopt::Std;
use List::Util qw/ min /;
use Pod::Usage;
use version;
# parse and validate command line args
my %opt;
sub vprint(@) {
print @_ if $opt{v};
@_;
}
sub fsystem(@) {
my $cmd_string = join(' ', map {$_ =~ /\s/ ? "'$_'" : $_} @_);
print "DO: $cmd_string\n" if $opt{v} || $opt{x};
unless($opt{x}) {
system(@_);
$? and die "command failed: $cmd_string\nAborting.\n";
}
}
getopts('c:nMmr:V:vpx',\%opt) or pod2usage(1);
$opt{M} || $opt{m} || $opt{V}
or pod2usage('must specify either -M, -m, or -V');
#@ARGV == 1 || @ARGV == 2 or pod2usage('must provide component name, and optionally remote name');
my ($component_name,$remote) = @ARGV;
$component_name = basename( getcwd() ) unless defined $component_name;
$remote = 'origin' unless defined $remote;
unless( $opt{n} ) {
vprint("fetching tags from $remote ...\n");
fsystem('git','fetch','--tags',
($opt{v} ? () : '-q'),
$remote )
}
my @previous_releases = previous_releases($component_name);
#figure out the next major version number
my $major_version =
defined( $opt{V} ) ? $opt{V} :
@previous_releases ? $opt{M} ? $previous_releases[0][0]+1 :
$opt{m} ? $previous_releases[0][0] :
pod2usage('must specify either -M, -m, or -V')
: 1
;
#figure out the next minor version number
my $minor_version = do {
if(my @other_rels = grep {$major_version == $_->[0]} @previous_releases) {
$other_rels[0][1] + 1
} else {
0
}
};
my $release_ref = $opt{r} || 'master';
my $comment = $opt{c} ? $opt{c} : "";
my $new_release_tag = "$component_name-$major_version.$minor_version";
fsystem( 'git', 'tag',
-m => $new_release_tag,
-m => "$FindBin::Script: tagging $release_ref as release $new_release_tag",
-m => $comment,
$new_release_tag,
$release_ref,
);
print <<"";
tagged $release_ref as release $new_release_tag
if( $opt{p} ) {
vprint("pushing tags to $remote ...\n");
fsystem(qw( git push --tags ),
($opt{v} ? () : '-q'),
$remote );
} else {
print "-p not passed, skipping auto-push. You may want to run: git push --tags\n";
}
exit;
#### SUBROUTINES
# args: git remote base, component name (e.g. 'cxgn-corelibs')
# returns: a list as ([major,minor],[major,minor]) of
# previous revisions that are present in the repos,
# in descending order by major and minor revision number
sub previous_releases {
my ($component_name) = @_;
my @releases =
sort { $b->[0] <=> $a->[0] || $b->[1] <=> $a->[1] }
map {
if(m|^$component_name-(\d+)\.(\d+)(?=\s)|) {
[$1,$2,$&]
} else {
()
}
} `git tag`;
vprint("last few $component_name releases:\n");
vprint(" $_->[2]\n") for reverse grep $_, @releases[0 .. min(2,$#releases)];
return @releases;
}
sub revparse {
my $r = shift;
$r = `git rev-parse $r`;
chomp $r;
return $r;
}
sub version_number {
my $class = shift;
my $tag = shift;
$tag =~ /(v?[\d\.]+)$/
or return;
return version->new($1);
}
__END__
=head1 NAME
make_release_tag.pl - make a new release tag for the given software component name.
=head1 SYNOPSIS
cd my_component; make_release_tag.pl [options] [component_name] [remote_name]
Must specify one of -M, -m, or -V. Must be run from a working
directory inside the git repository in question.
The default component name is the name of the current working
directory.
The default remote name is 'origin'.
Options:
-n
do not run 'git fetch --tags' before making a new release tag.
good for making a tag without network access, but be sure someone
has not already done it!
-p
run a git push --tags <remote> after creating the tag to push the
tag to the given remote. be careful with this!
-M
make this a major release. equivalent to '-V <num+1>', where
num is the current major release.
-m
number this as a minor release. equivalent to '-V <num>', where
num is the current major release.
-r <sha or branch>
the rev (branch, commit, or other tag) to take as this release,
defaults to 'master'
-V <num>
major version number for this release, like '4'
defaults to the next major number in the sequence
of releases
-v be verbose about what you're doing
-x just do a dry run, printing what you _would_ do
=head1 EXAMPLES
=head2 Without autopush
=head3 make a new release tag for the Phenome component
cd Phenome; make_release_tag.pl -M Phenome
=head3 make sure the tag it just made is correct, then send it to github
git push --tags
=head2 With autopush (be careful!)
cd Phenome; make_release_tag.pl -pM Phenome
=head1 AUTHOR
Robert Buels, E<lt>rmb32@cornell.eduE<gt>
=head1 COPYRIGHT & LICENSE
Copyright 2010 Boyce Thompson Institute for Plant Research
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut