fix(dev-infra): ensure that building environment stamp fails silently (#42985)
Previously when a failure occurred in part of building the environment stamp, the entire process errored. This should instead fail silently providing no value for the stamp. PR Close #42985
This commit is contained in:
parent
8116895ece
commit
2a0e28cf61
|
@ -7746,8 +7746,13 @@ function buildEnvStamp(mode) {
|
|||
}
|
||||
/** Whether the repo has local changes. */
|
||||
function hasLocalChanges() {
|
||||
const git = GitClient.get();
|
||||
return git.hasUncommittedChanges();
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
return git.hasUncommittedChanges();
|
||||
}
|
||||
catch (_a) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the versions for generated packages.
|
||||
|
@ -7756,41 +7761,63 @@ function hasLocalChanges() {
|
|||
* In release mode, the version is based on the base package.json version.
|
||||
*/
|
||||
function getSCMVersions(mode) {
|
||||
const git = GitClient.get();
|
||||
if (mode === 'release') {
|
||||
const packageJsonPath = path.join(git.baseDir, 'package.json');
|
||||
const { version } = new semver.SemVer(require(packageJsonPath).version);
|
||||
const { version: experimentalVersion } = createExperimentalSemver(new semver.SemVer(version));
|
||||
return { version, experimentalVersion };
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
if (mode === 'snapshot') {
|
||||
const localChanges = hasLocalChanges() ? '.with-local-changes' : '';
|
||||
const { stdout: rawVersion } = git.run(['describe', '--match', '*[0-9]*.[0-9]*.[0-9]*', '--abbrev=7', '--tags', 'HEAD~100']);
|
||||
const { version } = new semver.SemVer(rawVersion);
|
||||
const { version: experimentalVersion } = createExperimentalSemver(version);
|
||||
return {
|
||||
version: `${version.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||
experimentalVersion: `${experimentalVersion.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||
};
|
||||
}
|
||||
else {
|
||||
const packageJsonPath = path.join(git.baseDir, 'package.json');
|
||||
const { version } = new semver.SemVer(require(packageJsonPath).version);
|
||||
const { version: experimentalVersion } = createExperimentalSemver(new semver.SemVer(version));
|
||||
return { version, experimentalVersion };
|
||||
}
|
||||
}
|
||||
if (mode === 'snapshot') {
|
||||
const localChanges = hasLocalChanges() ? '.with-local-changes' : '';
|
||||
const { stdout: rawVersion } = git.run(['describe', '--match', '*[0-9]*.[0-9]*.[0-9]*', '--abbrev=7', '--tags', 'HEAD~100']);
|
||||
const { version } = new semver.SemVer(rawVersion);
|
||||
const { version: experimentalVersion } = createExperimentalSemver(version);
|
||||
catch (_a) {
|
||||
return {
|
||||
version: `${version.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||
experimentalVersion: `${experimentalVersion.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||
version: '',
|
||||
experimentalVersion: '',
|
||||
};
|
||||
}
|
||||
throw Error('No environment stamp mode was provided.');
|
||||
}
|
||||
/** Get the current branch or revision of HEAD. */
|
||||
function getCurrentBranchOrRevision() {
|
||||
const git = GitClient.get();
|
||||
return git.getCurrentBranchOrRevision();
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
return git.getCurrentBranchOrRevision();
|
||||
}
|
||||
catch (_a) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
/** Get the currently checked out branch. */
|
||||
function getCurrentBranch() {
|
||||
const git = GitClient.get();
|
||||
return git.run(['symbolic-ref', '--short', 'HEAD']).stdout.trim();
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
return git.run(['symbolic-ref', '--short', 'HEAD']).stdout.trim();
|
||||
}
|
||||
catch (_a) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
/** Get the current git user based on the git config. */
|
||||
function getCurrentGitUser() {
|
||||
const git = GitClient.get();
|
||||
let userName = git.runGraceful(['config', 'user.name']).stdout.trim() || 'Unknown User';
|
||||
let userEmail = git.runGraceful(['config', 'user.email']).stdout.trim() || 'unknown_email';
|
||||
return `${userName} <${userEmail}>`;
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
let userName = git.runGraceful(['config', 'user.name']).stdout.trim() || 'Unknown User';
|
||||
let userEmail = git.runGraceful(['config', 'user.email']).stdout.trim() || 'unknown_email';
|
||||
return `${userName} <${userEmail}>`;
|
||||
}
|
||||
catch (_a) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,8 +37,12 @@ export function buildEnvStamp(mode: EnvStampMode) {
|
|||
|
||||
/** Whether the repo has local changes. */
|
||||
function hasLocalChanges() {
|
||||
const git = GitClient.get();
|
||||
return git.hasUncommittedChanges();
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
return git.hasUncommittedChanges();
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,44 +52,61 @@ function hasLocalChanges() {
|
|||
* In release mode, the version is based on the base package.json version.
|
||||
*/
|
||||
function getSCMVersions(mode: EnvStampMode): {version: string, experimentalVersion: string} {
|
||||
const git = GitClient.get();
|
||||
if (mode === 'release') {
|
||||
const packageJsonPath = join(git.baseDir, 'package.json');
|
||||
const {version} = new SemVer(require(packageJsonPath).version);
|
||||
const {version: experimentalVersion} = createExperimentalSemver(new SemVer(version));
|
||||
return {version, experimentalVersion};
|
||||
}
|
||||
if (mode === 'snapshot') {
|
||||
const localChanges = hasLocalChanges() ? '.with-local-changes' : '';
|
||||
const {stdout: rawVersion} = git.run(
|
||||
['describe', '--match', '*[0-9]*.[0-9]*.[0-9]*', '--abbrev=7', '--tags', 'HEAD~100']);
|
||||
const {version} = new SemVer(rawVersion);
|
||||
const {version: experimentalVersion} = createExperimentalSemver(version);
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
if (mode === 'snapshot') {
|
||||
const localChanges = hasLocalChanges() ? '.with-local-changes' : '';
|
||||
const {stdout: rawVersion} = git.run(
|
||||
['describe', '--match', '*[0-9]*.[0-9]*.[0-9]*', '--abbrev=7', '--tags', 'HEAD~100']);
|
||||
const {version} = new SemVer(rawVersion);
|
||||
const {version: experimentalVersion} = createExperimentalSemver(version);
|
||||
return {
|
||||
version: `${version.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||
experimentalVersion:
|
||||
`${experimentalVersion.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||
};
|
||||
} else {
|
||||
const packageJsonPath = join(git.baseDir, 'package.json');
|
||||
const {version} = new SemVer(require(packageJsonPath).version);
|
||||
const {version: experimentalVersion} = createExperimentalSemver(new SemVer(version));
|
||||
return {version, experimentalVersion};
|
||||
}
|
||||
} catch {
|
||||
return {
|
||||
version: `${version.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||
experimentalVersion:
|
||||
`${experimentalVersion.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||
version: '',
|
||||
experimentalVersion: '',
|
||||
};
|
||||
}
|
||||
throw Error('No environment stamp mode was provided.');
|
||||
}
|
||||
|
||||
/** Get the current branch or revision of HEAD. */
|
||||
function getCurrentBranchOrRevision() {
|
||||
const git = GitClient.get();
|
||||
return git.getCurrentBranchOrRevision();
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
return git.getCurrentBranchOrRevision();
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the currently checked out branch. */
|
||||
function getCurrentBranch() {
|
||||
const git = GitClient.get();
|
||||
return git.run(['symbolic-ref', '--short', 'HEAD']).stdout.trim();
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
return git.run(['symbolic-ref', '--short', 'HEAD']).stdout.trim();
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the current git user based on the git config. */
|
||||
function getCurrentGitUser() {
|
||||
const git = GitClient.get();
|
||||
let userName = git.runGraceful(['config', 'user.name']).stdout.trim() || 'Unknown User';
|
||||
let userEmail = git.runGraceful(['config', 'user.email']).stdout.trim() || 'unknown_email';
|
||||
return `${userName} <${userEmail}>`;
|
||||
try {
|
||||
const git = GitClient.get();
|
||||
let userName = git.runGraceful(['config', 'user.name']).stdout.trim() || 'Unknown User';
|
||||
let userEmail = git.runGraceful(['config', 'user.email']).stdout.trim() || 'unknown_email';
|
||||
return `${userName} <${userEmail}>`;
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue