Skip to content

Instantly share code, notes, and snippets.

@dchest
Created February 8, 2009 00:06
Show Gist options
  • Save dchest/60110 to your computer and use it in GitHub Desktop.
Save dchest/60110 to your computer and use it in GitHub Desktop.
"Tag, build, zip, upload, etc" automation script
#!/usr/bin/env perl
use File::Temp qw/ tempdir /;
use File::Path qw/ rmtree /;
use File::Spec::Functions;
print "autobuild (C) 2009 Dmitry Chestnykh and friends (http://twitter.com/dchest/friends)\n\n";
if ($#ARGV < 3) {
usage();
}
($cmd, $product, $ver, $build) = @ARGV;
$SIG{__DIE__} = sub {
rmtree($tempdir) if $tempdir; # Remove temporary folder
system("git tag -d $ver.$build") unless $dont_delete_tag; # Remove tag. If it doesn't exist, fuck it
die(shift);
};
$remote_login = "TEST";
$remote_host = "EXAMPLE.COM";
$remote_dir = "TEST/DIRECTORY";
if ($cmd eq "all" || $cmd eq "no-tag") {
if ($cmd ne "no-tag") {
print "Tagging...\n";
tag();
}
else
{
$dont_delete_tag = 1;
}
print "Building RELEASE...\n";
my $zip = build_and_zip("Release");
print "Uploading $zip to ".$remote_login."@"."$remote_host:$remote_dir\n"; # report result
upload($zip);
print "\n\nDONE!\n\n";
rmtree($tempdir);
}
else
{
usage();
}
sub usage
{
print <<END;
Usage: autobuild CMD PRODUCT_NAME VERSION BUILD_NO
Commands:
all - tag, build, zip, and upload
no-tag - like 'all' but without tagging
Options:
PRODUCT_NAME - product name (e.g memoires).
VERSION - version to use for tag and filename (e.g. 1.0)
BUILD_NO - build number (e.g. 33)
END
exit(1);
}
sub tag
{
$dont_delete_tag = 1; # oh crap
system("git tag $ver.$build") == 0 or die("[!] Error tagging");
undef $dont_delete_tag;
}
sub build_and_zip
{
my $config = shift;
$tempdir = tempdir("/tmp/autobuild.XXXXX");
system("xcodebuild -configuration $config clean build SYMROOT=$tempdir") == 0 or die("[!] Error building");
my @lines = `cd $tempdir && cd $config && ls -md *.app`;
die "[!] No build result found." unless @lines;
chomp(my $app = $lines[0]);
my $zip = "${product}_$ver.$build.zip";
print "Zipping $app...\n";
system("cd $tempdir && cd $config && ditto -ck --keepParent $app $zip") == 0 or die("[!] Error zipping");
return catfile($tempdir, $config, $zip);
}
sub upload($)
{
my $filename = shift;
system("scp $filename ".$remote_login."@"."$remote_host:$remote_dir") == 0 or die "[!] Error uploading";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment