Skip to content

Instantly share code, notes, and snippets.

@bshaffer
Last active May 16, 2022 19:41
Show Gist options
  • Save bshaffer/85f96c1315c486ce3bc8d4cfce033493 to your computer and use it in GitHub Desktop.
Save bshaffer/85f96c1315c486ce3bc8d4cfce033493 to your computer and use it in GitHub Desktop.
<?php
if (count($argv) < 2) {
exit("usage: publish_release.php [tag]\n");
}
// strip alphabetic characters
$tag = $argv[1];
$version = $tag;
if ('v' == $argv[1][0]) {
// remove initial V for version
$version = substr($version, 1);
}
$releaseName = sprintf('google-api-php-client-%s', $version);
$tmpDir = tempnam(sys_get_temp_dir(), 'publish_release-'.$tag);
unlink($tmpDir);
@mkdir($tmpDir);
chdir($tmpDir);
echo "Release files will be added to $tmpDir\n";
run_command(sprintf(
'curl -L -o %s/%s.zip https://github.com/google/google-api-php-client/archive/%s.zip',
$tmpDir,
$tag,
$tag
));
run_command(sprintf(
'unzip %s/%s.zip -d %s',
$tmpDir,
$tag,
$tmpDir
));
run_command(sprintf('mv %s/google-api-php-client-%s %s/google-api-php-client', $tmpDir, $version, $tmpDir));
create_release($tmpDir, $tag, 'google-api-php-client-'.$version);
create_release($tmpDir, $tag, 'google-api-php-client-'.$version.'_PHP54', true);
unlink(sprintf('%s/%s.zip', $tmpDir, $tag));
echo sprintf("run the following to see the releases:\n\topen %s\n", $tmpDir);
function create_release($tmpDir, $tag, $releaseName, $preferLowest = false)
{
$cmd = sprintf('composer update --prefer-dist --no-dev --working-dir=%s/google-api-php-client', $tmpDir, $releaseName);
if ($preferLowest) {
$cmd .= ' --prefer-lowest';
}
run_command($cmd);
run_command(sprintf('mv google-api-php-client %s', $releaseName));
run_command(sprintf('zip -q -r %s.zip %s', $releaseName, $releaseName));
run_command(sprintf('zip -d %s.zip "__MACOSX*" || true', $releaseName));
run_command(sprintf('mv %s google-api-php-client', $releaseName));
}
function run_command($cmd)
{
echo "$cmd\n";
passthru($cmd, $return_var);
if (0 !== $return_var) {
exit("\ncommand failed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment