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. */
|
/** Whether the repo has local changes. */
|
||||||
function hasLocalChanges() {
|
function hasLocalChanges() {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
return git.hasUncommittedChanges();
|
const git = GitClient.get();
|
||||||
|
return git.hasUncommittedChanges();
|
||||||
|
}
|
||||||
|
catch (_a) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the versions for generated packages.
|
* 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.
|
* In release mode, the version is based on the base package.json version.
|
||||||
*/
|
*/
|
||||||
function getSCMVersions(mode) {
|
function getSCMVersions(mode) {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
if (mode === 'release') {
|
const git = GitClient.get();
|
||||||
const packageJsonPath = path.join(git.baseDir, 'package.json');
|
if (mode === 'snapshot') {
|
||||||
const { version } = new semver.SemVer(require(packageJsonPath).version);
|
const localChanges = hasLocalChanges() ? '.with-local-changes' : '';
|
||||||
const { version: experimentalVersion } = createExperimentalSemver(new semver.SemVer(version));
|
const { stdout: rawVersion } = git.run(['describe', '--match', '*[0-9]*.[0-9]*.[0-9]*', '--abbrev=7', '--tags', 'HEAD~100']);
|
||||||
return { version, experimentalVersion };
|
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') {
|
catch (_a) {
|
||||||
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 {
|
return {
|
||||||
version: `${version.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
version: '',
|
||||||
experimentalVersion: `${experimentalVersion.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
experimentalVersion: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw Error('No environment stamp mode was provided.');
|
|
||||||
}
|
}
|
||||||
/** Get the current branch or revision of HEAD. */
|
/** Get the current branch or revision of HEAD. */
|
||||||
function getCurrentBranchOrRevision() {
|
function getCurrentBranchOrRevision() {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
return git.getCurrentBranchOrRevision();
|
const git = GitClient.get();
|
||||||
|
return git.getCurrentBranchOrRevision();
|
||||||
|
}
|
||||||
|
catch (_a) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/** Get the currently checked out branch. */
|
/** Get the currently checked out branch. */
|
||||||
function getCurrentBranch() {
|
function getCurrentBranch() {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
return git.run(['symbolic-ref', '--short', 'HEAD']).stdout.trim();
|
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. */
|
/** Get the current git user based on the git config. */
|
||||||
function getCurrentGitUser() {
|
function getCurrentGitUser() {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
let userName = git.runGraceful(['config', 'user.name']).stdout.trim() || 'Unknown User';
|
const git = GitClient.get();
|
||||||
let userEmail = git.runGraceful(['config', 'user.email']).stdout.trim() || 'unknown_email';
|
let userName = git.runGraceful(['config', 'user.name']).stdout.trim() || 'Unknown User';
|
||||||
return `${userName} <${userEmail}>`;
|
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. */
|
/** Whether the repo has local changes. */
|
||||||
function hasLocalChanges() {
|
function hasLocalChanges() {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
return git.hasUncommittedChanges();
|
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.
|
* In release mode, the version is based on the base package.json version.
|
||||||
*/
|
*/
|
||||||
function getSCMVersions(mode: EnvStampMode): {version: string, experimentalVersion: string} {
|
function getSCMVersions(mode: EnvStampMode): {version: string, experimentalVersion: string} {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
if (mode === 'release') {
|
const git = GitClient.get();
|
||||||
const packageJsonPath = join(git.baseDir, 'package.json');
|
if (mode === 'snapshot') {
|
||||||
const {version} = new SemVer(require(packageJsonPath).version);
|
const localChanges = hasLocalChanges() ? '.with-local-changes' : '';
|
||||||
const {version: experimentalVersion} = createExperimentalSemver(new SemVer(version));
|
const {stdout: rawVersion} = git.run(
|
||||||
return {version, experimentalVersion};
|
['describe', '--match', '*[0-9]*.[0-9]*.[0-9]*', '--abbrev=7', '--tags', 'HEAD~100']);
|
||||||
}
|
const {version} = new SemVer(rawVersion);
|
||||||
if (mode === 'snapshot') {
|
const {version: experimentalVersion} = createExperimentalSemver(version);
|
||||||
const localChanges = hasLocalChanges() ? '.with-local-changes' : '';
|
return {
|
||||||
const {stdout: rawVersion} = git.run(
|
version: `${version.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||||
['describe', '--match', '*[0-9]*.[0-9]*.[0-9]*', '--abbrev=7', '--tags', 'HEAD~100']);
|
experimentalVersion:
|
||||||
const {version} = new SemVer(rawVersion);
|
`${experimentalVersion.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
||||||
const {version: experimentalVersion} = createExperimentalSemver(version);
|
};
|
||||||
|
} 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 {
|
return {
|
||||||
version: `${version.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
version: '',
|
||||||
experimentalVersion:
|
experimentalVersion: '',
|
||||||
`${experimentalVersion.replace(/-([0-9]+)-g/, '+$1.sha-')}${localChanges}`,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw Error('No environment stamp mode was provided.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the current branch or revision of HEAD. */
|
/** Get the current branch or revision of HEAD. */
|
||||||
function getCurrentBranchOrRevision() {
|
function getCurrentBranchOrRevision() {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
return git.getCurrentBranchOrRevision();
|
const git = GitClient.get();
|
||||||
|
return git.getCurrentBranchOrRevision();
|
||||||
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the currently checked out branch. */
|
/** Get the currently checked out branch. */
|
||||||
function getCurrentBranch() {
|
function getCurrentBranch() {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
return git.run(['symbolic-ref', '--short', 'HEAD']).stdout.trim();
|
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. */
|
/** Get the current git user based on the git config. */
|
||||||
function getCurrentGitUser() {
|
function getCurrentGitUser() {
|
||||||
const git = GitClient.get();
|
try {
|
||||||
let userName = git.runGraceful(['config', 'user.name']).stdout.trim() || 'Unknown User';
|
const git = GitClient.get();
|
||||||
let userEmail = git.runGraceful(['config', 'user.email']).stdout.trim() || 'unknown_email';
|
let userName = git.runGraceful(['config', 'user.name']).stdout.trim() || 'Unknown User';
|
||||||
return `${userName} <${userEmail}>`;
|
let userEmail = git.runGraceful(['config', 'user.email']).stdout.trim() || 'unknown_email';
|
||||||
|
return `${userName} <${userEmail}>`;
|
||||||
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue