2020-09-01 14:29:32 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import fetch from 'node-fetch';
|
2020-09-30 16:16:33 -04:00
|
|
|
import {fetchActiveReleaseTrains} from '../../release/versioning/index';
|
2020-09-01 14:29:32 -04:00
|
|
|
|
2020-09-30 16:16:33 -04:00
|
|
|
import {bold, debug, info} from '../../utils/console';
|
2020-09-01 14:29:32 -04:00
|
|
|
import {GitClient} from '../../utils/git';
|
|
|
|
|
|
|
|
|
|
|
|
/** The results of checking the status of CI. */
|
|
|
|
interface StatusCheckResult {
|
2020-09-30 16:16:33 -04:00
|
|
|
status: 'success'|'failed';
|
2020-09-01 14:29:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Retrieve and log status of CI for the project. */
|
|
|
|
export async function printCiStatus(git: GitClient) {
|
2020-09-30 16:16:33 -04:00
|
|
|
const releaseTrains = await fetchActiveReleaseTrains({api: git.github, ...git.remoteConfig});
|
|
|
|
|
2020-09-01 14:29:32 -04:00
|
|
|
info.group(bold(`CI`));
|
2020-09-30 16:16:33 -04:00
|
|
|
for (const [trainName, train] of Object.entries(releaseTrains)) {
|
|
|
|
if (train === null) {
|
|
|
|
debug(`No active release train for ${trainName}`);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const status = await getStatusOfBranch(git, train.branchName);
|
|
|
|
await printStatus(`${trainName.padEnd(6)} (${train.branchName})`, status);
|
|
|
|
}
|
2020-09-01 14:29:32 -04:00
|
|
|
info.groupEnd();
|
|
|
|
info();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Log the status of CI for a given branch to the console. */
|
2020-09-30 16:16:33 -04:00
|
|
|
async function printStatus(label: string, status: StatusCheckResult|null) {
|
|
|
|
const branchName = label.padEnd(16);
|
|
|
|
if (status === null) {
|
2020-09-01 14:29:32 -04:00
|
|
|
info(`${branchName} was not found on CircleCI`);
|
2020-09-30 16:16:33 -04:00
|
|
|
} else if (status.status === 'success') {
|
2020-09-01 14:29:32 -04:00
|
|
|
info(`${branchName} ✅`);
|
|
|
|
} else {
|
2020-09-30 16:16:33 -04:00
|
|
|
info(`${branchName} ❌`);
|
2020-09-01 14:29:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the CI status of a given branch from CircleCI. */
|
|
|
|
async function getStatusOfBranch(git: GitClient, branch: string): Promise<StatusCheckResult|null> {
|
|
|
|
const {owner, name} = git.remoteConfig;
|
2020-09-30 16:16:33 -04:00
|
|
|
const url = `https://circleci.com/gh/${owner}/${name}/tree/${branch}.svg?style=shield`;
|
|
|
|
const result = await fetch(url).then(result => result.text());
|
2020-09-01 14:29:32 -04:00
|
|
|
|
2020-09-30 16:16:33 -04:00
|
|
|
if (result && !result.includes('no builds')) {
|
2020-09-01 14:29:32 -04:00
|
|
|
return {
|
2020-09-30 16:16:33 -04:00
|
|
|
status: result.includes('passing') ? 'success' : 'failed',
|
2020-09-01 14:29:32 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|