Skip to content

Instantly share code, notes, and snippets.

@benchester
Created August 1, 2012 11:07
Show Gist options
  • Save benchester/3225846 to your computer and use it in GitHub Desktop.
Save benchester/3225846 to your computer and use it in GitHub Desktop.
jenkins post-build script for uploading to HockeyApp
<?php
// USAGE:
// php script.php -t "title" -b "bundleID" -p "platform" -r "release type"
$new_url = "https://rink.hockeyapp.net/api/2/apps/new";
function getMyBundleID()
{
// framework folder, there shouldn't be more than one
foreach (glob("*.framework") as $framework) {}
// .plist path
$path = $framework . "/Resources/Info.plist";
$handle = @fopen($path, "r");
if ($handle)
{
while (($buffer = fgets($handle, 4096)) !== false) {
if (substr_count($buffer, "CFBundleIdentifier") == 1)
{
if (($buffer = fgets($handle, 4096)) !== false)
{
$lastpos = strripos($buffer, "</string>");
$bundleID = str_replace("<string>", "", $buffer);
$bundleID = str_replace("</string>", "", $bundleID);
$bundleID = trim($bundleID);
}
}
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
return $bundleID;
}
function connectSetup($url)
{
// This should be your app token for all apps
$globalAppToken = "824612757d5f4f6d8020c73b31af81aa";
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($c, CURLOPT_HTTPHEADER, array("X-HockeyAppToken: ".$globalAppToken));
return $c;
}
// Checks if bundleID matches an existing bundleID on HockeyAPP
// If app exists, returns public app identifier. Otherwise returns 0
function publicIDforBundleID($bundleID)
{
$url = "https://rink.hockeyapp.net/api/2/apps/";
$c = connectSetup($url);
$result = curl_exec($c);
$json = json_decode($result);
//var_dump($json);
$public_identifier = "";
foreach($json->apps as $app)
{
if (strcmp($app->bundle_identifier, $bundleID) == 0)
{
$public_identifier = $app->public_identifier;
}
}
curl_close($c);
return $public_identifier;
}
// Uploads an app using ipa and dSYM found in directory
function uploadApp()
{
$url = "https://rink.hockeyapp.net/api/2/apps/";
// get ipa, dSYM paths
foreach (glob("build/Distribution-iphoneos/*.ipa") as $ipa) {}
foreach (glob("build/Distribution-iphoneos/*dSYM.zip") as $dsym) {}
$c = connectSetup($url);
$data = array(
'status' =>'2',
'notify' =>'1',
'notes' => 'note',
'notes_type' => '0',
'ipa' => "@".$ipa,
'dsym' => "@".$dsym
);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
echo $post_string."\n";
$result = curl_exec($c);
curl_close($c);
return $result;
}
// Creates a new app
// platform = iOS, Android, Mac OS, Windows Phone, Custom
// release_type = 2:Alpha, 0:Beta, 1:Live
function newApp($title, $bundle_identifier, $platform, $release_type)
{
$url = "https://rink.hockeyapp.net/api/2/apps/new";
$c = connectSetup($url);
$data = array(
'title' => $title,
'bundle_identifier' => $bundle_identifier,
'platform' => $platform,
'release_type' => $release_type
);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($c);
curl_close($c);
return $result;
}
$opts = "t:"; // title
$opts .= "b:"; // bundle identifier
$opts .= "p:"; // platform
$opts .= "r:"; // release type
$options = getopt($opts);
var_dump($options);
$title = $options[t];
echo $title;
$bundle_identifier = $options[b];
$platform = $options[p];
$release_type = $options[r];
var_dump($options);
var_dump(parse_str(implode('&', array_slice($argv, 1)), $_GET));
$myBundleID = getMyBundleID();
echo $myBundleID . "\n";
if (strlen(publicIDforBundleID($myBundleID)) == 0)
{
echo "Creating new app\n";
echo newApp("defaultTitle",$myBundleID, "iOS", "0")."\n";
echo uploadApp()."\n";
}
else
{
echo "Updating app"."\n";
echo uploadApp();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment