Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign .js release files in addition to .tar.gz files #11

Merged
merged 1 commit into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions nightly/api/sign_releases.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,40 @@
Config::REPO_NAME
);

$releases_to_sign = [];
$files_to_sign = [];
$promises = [];
foreach ($releases as $release) {
$tarball = null;
$has_sig = false;
$files_in_release = [];
$signed_files = [];

foreach ($release->assets as $asset) {
if (Str::endsWith($asset->name, '.tar.gz')) {
$tarball = $asset;
} else if (Str::endsWith($asset->name, '.tar.gz.asc')) {
$has_sig = true;
break;
if (preg_match(Config::SIGN_FILE_TYPES, $asset->name)) {
$files_in_release[] = $asset;
} else if (Str::endsWith($asset->name, '.asc')) {
$signed_files[str_replace('.asc', '', $asset->name)] = true;
}
}
if ($has_sig || !$tarball) {
// This release's tarball already has a signature, skip it
continue;
}

$download_path = tempnam(sys_get_temp_dir(), '');
$download_handle = fopen($download_path, 'w');
$releases_to_sign[] = [
'tarball' => $tarball,
'download_handle' => $download_handle,
'download_path' => $download_path,
'release' => $release,
];
$promises[] = $client->getAsync($tarball->browser_download_url, [
'sink' => $download_handle,
]);
foreach ($files_in_release as $asset) {
if (array_key_exists($asset->name, $signed_files)) {
// File is already signed
continue;
}
$download_path = tempnam(sys_get_temp_dir(), '');
$download_handle = fopen($download_path, 'w');
$files_to_sign[] = [
'asset' => $asset,
'download_handle' => $download_handle,
'download_path' => $download_path,
'release' => $release,
];
$promises[] = $client->getAsync($asset->browser_download_url, [
'sink' => $download_handle,
]);
}
}

if (count($releases_to_sign) === 0) {
if (count($files_to_sign) === 0) {
api_response('All releases have already been signed!');
}

Expand All @@ -66,13 +68,13 @@
$output = "Signed:\n";
$promises = [];
$uri = new \Rize\UriTemplate\UriTemplate();
foreach ($releases_to_sign as $release) {
$signature = GPG::sign($release['download_path'], Config::GPG_RELEASE);
unlink($release['download_path']);
foreach ($files_to_sign as $file) {
$signature = GPG::sign($file['download_path'], Config::GPG_RELEASE);
unlink($file['download_path']);

$upload_url = $uri->expand(
$release['release']->upload_url,
['name' => $release['tarball']->name.'.asc']
$file['release']->upload_url,
['name' => $file['asset']->name.'.asc']
);
$promises[] = $client->postAsync($upload_url, [
'body' => $signature,
Expand All @@ -81,7 +83,7 @@
'Content-Type' => 'application/pgp-signature',
],
]);
$output .= $release['release']->tag_name.': '.$release['tarball']->name."\n";
$output .= $file['release']->tag_name.': '.$file['asset']->name."\n";
}

// Upload all the signature files in parallel
Expand Down
4 changes: 4 additions & 0 deletions nightly/lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ class Config {
const BRANCH = 'master';
const RELEASE_TAG_FORMAT = '/v[0-9]+(\.[0-9]+)*/';

// Auth token for sign_releases endpoint
const SIGN_AUTH_TOKEN = 'CHANGEME';
// File types that should be GPG signed as part of GitHub releases
const SIGN_FILE_TYPES = '/\.(tar\.gz|js)$/';

const GITHUB_TOKEN = 'CHANGEME';
const CIRCLECI_TOKEN = 'CHANGEME';

Expand Down