1#!perl 2use strict; 3sub run(@) { 4 open PROC, "-|", @_ or die("Cannot run $_[0]: $!"); 5 my @out; 6 while (<PROC>) { 7 chomp; 8 push @out, $_; 9 } 10 close PROC; 11 return @out; 12} 13 14my @tags = run("git", "tag"); 15my @v = run("git", "show", "HEAD:VERSION"); 16my $v = $v[0]; 17 18my $tagfile = ".git/TAG_EDITMSG"; 19open TAGFILE, ">", $tagfile 20 or die("Cannot create file for editing tag message: $!"); 21select TAGFILE; 22print "TinyCBOR release $v\n"; 23print "\n"; 24print "# Write something nice about this release here\n"; 25 26# Do we have a commit template? 27my @result = run("git", "config", "--get", "commit.template"); 28if (scalar @result) { 29 open TEMPLATE, "<", $result[0]; 30 map { print $_; } <TEMPLATE>; 31 close TEMPLATE; 32} 33 34print "\n"; 35print "# Commit log\n"; 36open LOG, "-|", "git", "shortlog", "-e", "--no-merges", "--not", @tags; 37map { print "# $_"; } <LOG>; 38close LOG; 39 40print "# Header diff:\n"; 41open DIFF, "-|", "git", "diff", "HEAD", "--not", @tags, "--", 'src/*.h', ':!*_p.h'; 42map { print "# $_"; } <DIFF>; 43close DIFF; 44 45select STDOUT; 46close TAGFILE; 47 48# Run the editor. 49# We use system so that stdin, stdout and stderr are forwarded. 50@result = run("git", "var", "GIT_EDITOR"); 51@result = ($result[0], $tagfile); 52system @result; 53exit ($? >> 8) if $?; 54 55# Create the tag 56# Also using system so that hte user can see the output. 57system("git", "tag", "-a", "-F", $tagfile, split(' ', $ENV{GITTAGFLAGS}), "v$v"); 58exit ($? >> 8) if $?; 59 60# Update the version files for the next patch release 61@v = split(/\./, $v); 62if (scalar @v < 3) { 63 push @v, '1'; 64} else { 65 ++$v[-1]; 66} 67$v = join('.', @v); 68open VERSION, ">", "VERSION" or die("Cannot open VERSION file: $!"); 69print VERSION "$v\n"; 70close VERSION; 71 72open VERSION, ">", "src/tinycbor-version.h" or die("Cannot open src/tinycbor-version.h: $!"); 73print VERSION "#define TINYCBOR_VERSION_MAJOR ", $v[0], "\n"; 74print VERSION "#define TINYCBOR_VERSION_MINOR ", $v[1], "\n"; 75print VERSION "#define TINYCBOR_VERSION_PATCH ", $v[2], "\n"; 76close VERSION; 77 78if (open APPVEYORYML, "<", ".appveyor.yml") { 79 my @contents = map { 80 s/^version:.*/version: $v[0].$v[1].$v[2]-build-{build}/; 81 $_; 82 } <APPVEYORYML>; 83 close APPVEYORYML; 84 open APPVEYORYML, ">", ".appveyor.yml"; 85 print APPVEYORYML join('', @contents); 86 close APPVEYORYML; 87} 88 89# Print summary 90print "Tag created and next versions updated.\n"; 91print "Don't forget to create the docs.\n" if $v[2] == 1; 92