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