Skip to content

Instantly share code, notes, and snippets.

@schwern
Created February 25, 2010 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schwern/314420 to your computer and use it in GitHub Desktop.
Save schwern/314420 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl
use perl5i::0;
use File::Copy;
my %Is;
my $builder;
my $build_file;
my @build_args;
sub run {
system(@_) == 0 or exit $? >> 8;
}
sub cat {
my $file = shift;
open my $fh, "<", $file;
return join '', <$fh>;
}
sub check_branch {
return 1 unless $Is{git};
return 1 if cat(".git/HEAD") =~ m{^ref: refs/heads/master\n};
print STDERR "\a\a";
warn "Releasing non-master branch!\n";
sleep 2;
return;
}
$ENV{PERL_MM_USE_DEFAULT} = 1;
$ENV{PERL_RELEASING} = 1;
$ENV{AUTHOR_TESTING} = 'MSCHWERN';
my @gits = qw(.git ../.git ../../.git);
$Is{git} = @gits->first(sub { -d $_ });
# A real git-svn, not just an accident
$Is{'git-svn'} = glob(".git/svn/*");
-e "Build.PL" ? $Is{'Module::Build'} = 1
: $Is{'MakeMaker'} = 1;
check_branch();
if( $Is{'Module::Build'} ) {
$builder = './Build';
$build_file = 'Build.PL';
@build_args = qw(--sign 1);
}
else {
$builder = 'make';
$build_file = 'Makefile.PL';
@build_args = qw(SIGN=1);
}
run("$^X $build_file @build_args");
run("$builder disttest");
run("$builder dist");
my @tarballs = glob("*.tar.gz");
die "More than one tarball" if @tarballs > 1;
die "No tarball?" if @tarballs == 0;
my $dist = $tarballs[0];
run("cpan-upload -verbose $dist");
my($version) = $dist =~ m{-v?([\d\._]+)\.tar\.gz};
print "Released $version\n";
if( $Is{git} ) {
run(qq[git commit -a -m 'Version $version']);
my $tag = "v$version";
run("git tag $tag -a -m 'Version $version released to CPAN'");
if( $Is{'git-svn'} ) {
# XXX Not sure how to push the tag with git-svn
run("git svnpush");
}
else {
run("git push origin");
run("git push origin $tag");
}
}
run("scp $dist schwern.net:~/schwern.org/src/");
move($dist, "$ENV{HOME}/releases/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment