From 9ad1b0a5173762e6573a6ff0681538536d5fe5bb Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 18 Jul 2010 15:38:10 +0200 Subject: [PATCH] release.pm: implement Git repository tagging --- maint/release.pm | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/maint/release.pm b/maint/release.pm index b0fa46e..cc84bbe 100644 --- a/maint/release.pm +++ b/maint/release.pm @@ -1,6 +1,6 @@ #!/usr/bin/perl # A simple system for making software releases -# (c) 2003--2006 Martin Mares +# (c) 2003--2010 Martin Mares package UCW::Release; use strict; @@ -34,7 +34,9 @@ sub new($$) { "do_test" => 1, "do_patch" => 1, "diff_against" => "", - "do_upload" => 1 + "do_upload" => 1, + "do_git_tag" => 0, + "force_git_tag" => 0, }; bless $s; return $s; @@ -216,15 +218,39 @@ sub GenFile($$) { push @{$s->{"distfiles"}}, $df; } +sub Usage($) { + my ($s) = @_; + my $usage = < + +Options: +--[no]verbose Be chatty about the inner workings of the release system {verbose} +--[no]test Test the package before uploading {do_test} +--[no]patch Make a patch against the previous version {do_patch} +--diff-against= Set which version we create the patch against +--[no]upload Upload released files {do_upload} +--[no]git-tag Tag the Git repository with "v" {do_git_tag} +--force-git-tag Rewrite the Git tag if it already exists {force_git_tag} +FOE + sub state($) { + return "(default: " . ($_ ? "on" : "off") . ")"; + } + $usage =~ s[{(\w+)}][state($s->{$1})]ge; + die $usage; +} + sub ParseOptions($) { my ($s) = @_; + $s->{"do_git_tag"} = 1 if (-d ".git"); GetOptions( "verbose!" => \$verbose, "test!" => \$s->{"do_test"}, "patch!" => \$s->{"do_patch"}, "diff-against=s" => \$s->{"diff_against"}, - "upload!" => \$s->{"do_upload"} - ) || die "Syntax: release [--verbose] [--test] [--nopatch] [--diff-against=] [--noupload]"; + "upload!" => \$s->{"do_upload"}, + 'git-tag!' => \$s->{"do_git_tag"}, + 'force-git-tag!' => \$s->{"force_git_tag"}, + ) || $s->Usage; } sub Test($) { @@ -307,10 +333,21 @@ sub Upload($) { } } +sub GitTag($) { + my ($s) = @_; + my $tag = 'v' . $s->{'VERSION'}; + my $force = ($s->{'force_git_tag'} ? '--force' : ''); + print "Tagging Git repository with $tag\n"; + `git tag $tag $force`; die if $?; + print "Pushing the tags upstream\n"; + `git push --tags`; die if $?; +} + sub Dispatch($) { my ($s) = @_; $s->Test if $s->{"do_test"}; $s->MakePatch if $s->{"do_patch"}; + $s->GitTag if $s->{"do_git_tag"}; $s->Upload if $s->{"do_upload"}; } -- 2.39.2