PageRenderTime 75ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/etc/tag_release.pl

https://bitbucket.org/kim_rutherford/pomcur
Perl | 126 lines | 107 code | 14 blank | 5 comment | 5 complexity | fa2323a96ad080e526af2a754beca202 MD5 | raw file
Possible License(s): GPL-3.0
  1. #!/usr/bin/perl -w
  2. # This script will tag the current master with the next available
  3. # version number (eg. v321) and then push the changes to GitHub
  4. # and Bitbucket
  5. use strict;
  6. use warnings;
  7. use Carp;
  8. my $version_prefix = "v";
  9. sub move_to_master
  10. {
  11. system "git checkout master";
  12. }
  13. sub get_current_version
  14. {
  15. my $describe = `git describe --tags --always --match "$version_prefix*"`;
  16. if ($describe =~ /^$version_prefix(\d+)/) {
  17. if ($describe =~ /^$version_prefix(\d+)$/) {
  18. die "no changes since last version\n";
  19. } else {
  20. return $1;
  21. }
  22. } else {
  23. warn "git describe didn't return a version starting with: $version_prefix\n";
  24. return undef;
  25. }
  26. }
  27. sub get_new_version
  28. {
  29. my $current_version = get_current_version();
  30. if (defined $current_version) {
  31. return $current_version + 1;
  32. } else {
  33. 0;
  34. }
  35. }
  36. sub tag_version
  37. {
  38. my $new_version = $version_prefix . get_new_version();
  39. local $/ = undef;
  40. open my $config_fh, '<', 'canto.yaml' or die "$!";
  41. my $contents = <$config_fh>;
  42. close $config_fh or die "$!";
  43. my $old_contents = $contents;
  44. $contents =~ s/(app_version:\s*)(.*)/$1$new_version/m;
  45. open $config_fh, '>', 'canto.yaml' or die "$!";
  46. print $config_fh $contents;
  47. close $config_fh or die "$!";
  48. system "git commit -m 'Update to version $new_version' canto.yaml";
  49. # system "git tag -s -a -m 'Version $new_version' $new_version"
  50. system "git tag -a -m 'Version $new_version' $new_version"
  51. }
  52. sub make_release_branch
  53. {
  54. my $new_version = shift;
  55. system "git branch release/$version_prefix$new_version";
  56. system "git branch -f release/latest release/$version_prefix$new_version";
  57. }
  58. sub stash
  59. {
  60. open my $stash_fh, 'git stash|' or die "$!";
  61. my $stashed = 0;
  62. my $nothing_to_save = 0;
  63. my $save = '';
  64. while (defined (my $line = <$stash_fh>)) {
  65. if ($line =~ /No local changes to save/) {
  66. $nothing_to_save = 1;
  67. }
  68. if ($line =~ /Saved working directory/) {
  69. $stashed = 1;
  70. }
  71. $save .= $line;
  72. }
  73. close $stash_fh or die "$!";
  74. if (!$stashed && !$nothing_to_save) {
  75. die "couldn't parse git stash output:\n$save";
  76. }
  77. return $stashed;
  78. }
  79. move_to_master();
  80. print 'current version: ', `git describe --always`, "\n";
  81. my $stashed = stash();
  82. my $new_version = get_new_version();
  83. print 'new version: ', $new_version, "\n";
  84. tag_version($new_version);
  85. # make_release_branch($new_version);
  86. print "pushing to GitHub\n";
  87. system "git push --tags github master";
  88. print "pushing to Bitbucket\n";
  89. system "git push --tags bitb master";
  90. END {
  91. if ($stashed) {
  92. system "git stash pop";
  93. }
  94. }