From f051ce0602853c2f6381b7a2f468da7d05c60b6a Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Fri, 4 Mar 2022 11:56:02 -0800 Subject: [PATCH 1/2] fix(ng-dev/release): only match on a single character prefixed version for snapshotting Previously we matched on all characters before our semver matching in the glob used for finding the latest version for the branch we are on. However when the branch contains something like zonejs-1.2.3, the * matcher would capture it, leading to an unexpected syntax. Instead we should allow for only a single letter, typically 'v', to prefix our version tags. --- ng-dev/release/stamping/env-stamp.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ng-dev/release/stamping/env-stamp.ts b/ng-dev/release/stamping/env-stamp.ts index 47ee99271..3ad40b271 100644 --- a/ng-dev/release/stamping/env-stamp.ts +++ b/ng-dev/release/stamping/env-stamp.ts @@ -63,7 +63,10 @@ function getSCMVersions( const {stdout: rawVersion} = git.run([ 'describe', '--match', - '*[0-9]*.[0-9]*.[0-9]*', + // 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', @@ -83,7 +86,8 @@ function getSCMVersions( const {version: experimentalVersion} = createExperimentalSemver(new SemVer(version)); return {version, experimentalVersion}; } - } catch { + } catch (e) { + console.error(e); return { version: '', experimentalVersion: '', @@ -136,4 +140,4 @@ function getCurrentGitUser(git: GitClient) { } catch { return ''; } -} +} \ No newline at end of file From 198f4c713980afa3e5a85d12c1603ed8da6886b7 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Fri, 4 Mar 2022 12:50:23 -0800 Subject: [PATCH 2/2] fixup! fix(ng-dev/release): only match on a single character prefixed version for snapshotting --- ng-dev/release/stamping/env-stamp.ts | 60 ++++++++++++---------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/ng-dev/release/stamping/env-stamp.ts b/ng-dev/release/stamping/env-stamp.ts index 3ad40b271..8631217e9 100644 --- a/ng-dev/release/stamping/env-stamp.ts +++ b/ng-dev/release/stamping/env-stamp.ts @@ -57,41 +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', - // 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: `${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 (e) { - console.error(e); + 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}; } } @@ -140,4 +132,4 @@ function getCurrentGitUser(git: GitClient) { } catch { return ''; } -} \ No newline at end of file +}