Ensure release ZIP is built from latest commit

[MAILPOET-1883]
This commit is contained in:
Jan Jakeš
2019-04-10 13:03:43 +02:00
committed by wxa
parent b33c149d6f
commit 400fb7f559
2 changed files with 22 additions and 0 deletions

View File

@ -38,6 +38,7 @@ class CircleCiController {
],
'base_uri' => 'https://circleci.com/api/v1.1/project/github/' . urlencode($username) . "/$circle_ci_project/",
]);
$this->github_controller = $github_controller;
}
public function downloadLatestBuild($target_path) {
@ -75,6 +76,14 @@ class CircleCiController {
if ($job['has_artifacts'] === false) {
throw new \Exception('Job has no artifacts');
}
// ensure we're downloading latest revision on given branch
$revision = $this->github_controller->getLatestCommitRevisionOnBranch(self::RELEASE_BRANCH);
if ($revision === null || $job['vcs_revision'] !== $revision) {
throw new \Exception(
"Found ZIP was built from revision '$revision' but the latest one is '$job[vcs_revision]'"
);
}
}
private function getReleaseZipUrl($build_number) {

View File

@ -43,6 +43,19 @@ class GitHubController {
$this->publishDraftAsRelease($release_info['id']);
}
public function getLatestCommitRevisionOnBranch($branch) {
try {
$response = $this->http_client->get('commits/' . urlencode($branch));
$data = json_decode($response->getBody()->getContents(), true);
} catch (ClientException $e) {
if ($e->getCode() === 404) {
return null;
}
throw $e;
}
return $data['sha'];
}
private function ensureNoDraftReleaseExists() {
$response = $this->http_client->get('releases');
$data = json_decode($response->getBody()->getContents(), true);