Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ng-dev/release): only match on a single character prefixed version for snapshotting #449

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 25 additions & 29 deletions ng-dev/release/stamping/env-stamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,33 @@ function getSCMVersions(
git: GitClient,
mode: EnvStampMode,
): {version: string; experimentalVersion: string} {
try {
if (mode === 'snapshot') {
const localChanges = hasLocalChanges(git) ? '.with-local-changes' : '';
const {stdout: rawVersion} = git.run([
'describe',
'--match',
'*[0-9]*.[0-9]*.[0-9]*',
'--abbrev=7',
'--tags',
'HEAD',
]);
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 {
if (mode === 'snapshot') {
const localChanges = hasLocalChanges(git) ? '.with-local-changes' : '';
const {stdout: rawVersion} = git.run([
'describe',
'--match',
// As git describe uses glob matchers we cannot the specific describe what we expect to see
// starting character we expect for our version string. To ensure we can handle 'v'
// prefixed verstions we have the '?' wildcard character.
'?[0-9]*.[0-9]*.[0-9]*',
'--abbrev=7',
'--tags',
'HEAD',
]);
const {version} = new SemVer(rawVersion);
const {version: experimentalVersion} = createExperimentalSemver(version);
return {
version: '',
experimentalVersion: '',
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};
}
}

Expand Down