feat(dev-infra): prevent `git push` from being called in dryRun mode (#41387)
Update GitClient to prevent the `push` command from being run in dryMode. PR Close #41387
This commit is contained in:
parent
f23406462b
commit
2cef385e43
|
@ -434,6 +434,31 @@ function addGithubTokenOption(yargs) {
|
||||||
.default('github-token', '', '<LOCAL TOKEN>');
|
.default('github-token', '', '<LOCAL TOKEN>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
/** Whether the current environment is in dry run mode. */
|
||||||
|
function isDryRun() {
|
||||||
|
return process.env['DRY_RUN'] !== undefined;
|
||||||
|
}
|
||||||
|
/** Error to be thrown when a function or method is called in dryRun mode and shouldn't be. */
|
||||||
|
var DryRunError = /** @class */ (function (_super) {
|
||||||
|
tslib.__extends(DryRunError, _super);
|
||||||
|
function DryRunError() {
|
||||||
|
var _this = _super.call(this, 'Cannot call this function in dryRun mode.') || this;
|
||||||
|
// Set the prototype explicitly because in ES5, the prototype is accidentally lost due to
|
||||||
|
// a limitation in down-leveling.
|
||||||
|
// https://github.com/Microsoft/TypeScript/wiki/FAQ#why-doesnt-extending-built-ins-like-error-array-and-map-work.
|
||||||
|
Object.setPrototypeOf(_this, DryRunError.prototype);
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
return DryRunError;
|
||||||
|
}(Error));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @license
|
* @license
|
||||||
* Copyright Google LLC All Rights Reserved.
|
* Copyright Google LLC All Rights Reserved.
|
||||||
|
@ -604,6 +629,12 @@ var GitClient = /** @class */ (function () {
|
||||||
*/
|
*/
|
||||||
GitClient.prototype.runGraceful = function (args, options) {
|
GitClient.prototype.runGraceful = function (args, options) {
|
||||||
if (options === void 0) { options = {}; }
|
if (options === void 0) { options = {}; }
|
||||||
|
/** The git command to be run. */
|
||||||
|
var gitCommand = args[0];
|
||||||
|
if (isDryRun() && gitCommand === 'push') {
|
||||||
|
debug("\"git push\" is not able to be run in dryRun mode.");
|
||||||
|
throw new DryRunError();
|
||||||
|
}
|
||||||
// To improve the debugging experience in case something fails, we print all executed Git
|
// To improve the debugging experience in case something fails, we print all executed Git
|
||||||
// commands to better understand the git actions occuring. Depending on the command being
|
// commands to better understand the git actions occuring. Depending on the command being
|
||||||
// executed, this debugging information should be logged at different logging levels.
|
// executed, this debugging information should be logged at different logging levels.
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {spawnSync, SpawnSyncOptions, SpawnSyncReturns} from 'child_process';
|
||||||
|
|
||||||
import {getConfig, getRepoBaseDir, NgDevConfig} from '../config';
|
import {getConfig, getRepoBaseDir, NgDevConfig} from '../config';
|
||||||
import {debug, info, yellow} from '../console';
|
import {debug, info, yellow} from '../console';
|
||||||
|
import {DryRunError, isDryRun} from '../dry-run';
|
||||||
import {GithubClient} from './github';
|
import {GithubClient} from './github';
|
||||||
import {getRepositoryGitUrl, GITHUB_TOKEN_GENERATE_URL, GITHUB_TOKEN_SETTINGS_URL} from './github-urls';
|
import {getRepositoryGitUrl, GITHUB_TOKEN_GENERATE_URL, GITHUB_TOKEN_SETTINGS_URL} from './github-urls';
|
||||||
|
|
||||||
|
@ -89,6 +90,14 @@ export class GitClient {
|
||||||
* info failed commands.
|
* info failed commands.
|
||||||
*/
|
*/
|
||||||
runGraceful(args: string[], options: SpawnSyncOptions = {}): SpawnSyncReturns<string> {
|
runGraceful(args: string[], options: SpawnSyncOptions = {}): SpawnSyncReturns<string> {
|
||||||
|
/** The git command to be run. */
|
||||||
|
const gitCommand = args[0];
|
||||||
|
|
||||||
|
if (isDryRun() && gitCommand === 'push') {
|
||||||
|
debug(`"git push" is not able to be run in dryRun mode.`);
|
||||||
|
throw new DryRunError();
|
||||||
|
}
|
||||||
|
|
||||||
// To improve the debugging experience in case something fails, we print all executed Git
|
// To improve the debugging experience in case something fails, we print all executed Git
|
||||||
// commands to better understand the git actions occuring. Depending on the command being
|
// commands to better understand the git actions occuring. Depending on the command being
|
||||||
// executed, this debugging information should be logged at different logging levels.
|
// executed, this debugging information should be logged at different logging levels.
|
||||||
|
|
Loading…
Reference in New Issue