Skip to content

Commit a35b47e

Browse files
committed
refactor(ng-dev): switch to creating github release tags prefixed with v
When github tags are generated during release, they are now prefixed with `v` to allow support for release backed publishing via wombot
1 parent e53a3b1 commit a35b47e

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

ng-dev/release/publish/actions.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ export abstract class ReleaseAction {
469469
pullRequest: PullRequest;
470470
builtPackagesWithInfo: BuiltPackageWithInfo[];
471471
}> {
472-
const releaseNotesCompareTag = getReleaseTagForVersion(compareVersionForReleaseNotes);
472+
const releaseNotesCompareTag = this._getReleaseNotesCompareTag(compareVersionForReleaseNotes);
473473

474474
// Fetch the compare tag so that commits for the release notes can be determined.
475475
// We forcibly override existing local tags that are named similar as we will fetch
@@ -669,6 +669,33 @@ export abstract class ReleaseAction {
669669
return `${baseUrl}#${urlFragment}`;
670670
}
671671

672+
/**
673+
* Determine the previous tag to be used for used for comparison in generating release
674+
* notes. Finding the tag whether or not it is `v` prefixed.
675+
*/
676+
private _getReleaseNotesCompareTag(version: semver.SemVer): string {
677+
/** The expected comparison version prefixed with `v`. */
678+
const prefixedTag = getReleaseTagForVersion(version);
679+
/** The expected comparison version. */
680+
const unprefixedTag = version.version;
681+
682+
/** Check if the tag exists on the upstream repo. */
683+
const verifyTagExists = (tag: string) => {
684+
const args = ['ls-remote', '--exit-code', this.git.getRepoGitUrl(), `refs/tags/${tag}`];
685+
return this.git.runGraceful(args).status === 0;
686+
};
687+
688+
if (verifyTagExists(prefixedTag)) {
689+
return prefixedTag;
690+
}
691+
if (verifyTagExists(unprefixedTag)) {
692+
return unprefixedTag;
693+
}
694+
695+
Log.error(` ✘ Unable to find previous tag (${prefixedTag}) for building release notes.`);
696+
throw new FatalReleaseActionError();
697+
}
698+
672699
/**
673700
* Publishes the given packages to the registry and makes the releases
674701
* available on GitHub.
@@ -700,6 +727,10 @@ export abstract class ReleaseAction {
700727
// built in the staging phase have not been modified accidentally.
701728
await assertIntegrityOfBuiltPackages(builtPackagesWithInfo);
702729

730+
// NOTE:
731+
// The Github Release must be created prior to publishing to npm as the version of the package
732+
// being published is verified by wombot proxy to already match the existing Github relase.
733+
703734
// Create a Github release for the new version.
704735
await this._createGithubReleaseForVersion(
705736
releaseNotes,

ng-dev/release/publish/test/common.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ describe('common release action logic', () => {
345345
tagName,
346346
true,
347347
changelogPattern`
348-
Release notes are too large to be captured here. [View all changes here](https://github.com/angular/dev-infra-test/blob/10.0.1/CHANGELOG.md#10.0.1).
348+
Release notes are too large to be captured here. [View all changes here](https://github.com/angular/dev-infra-test/blob/v10.0.1/CHANGELOG.md#10.0.1).
349349
`,
350350
);
351351

ng-dev/release/versioning/version-tags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ import semver from 'semver';
1010

1111
/** Gets the release tag name for the specified version. */
1212
export function getReleaseTagForVersion(version: semver.SemVer): string {
13-
return version.format();
13+
return `v${version.format()}`;
1414
}

ng-dev/utils/testing/github-api-testing.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export class GithubTestingRepo {
7979
}
8080

8181
expectReleaseByTagRequest(tagName: string, id: number): this {
82-
nock(this.repoApiUrl).get(`/releases/tags/${tagName}`).reply(200, {id});
82+
nock(this.repoApiUrl)
83+
.get(new RegExp(`/releases/tags/v?${tagName}`))
84+
.reply(200, {id});
8385
return this;
8486
}
8587

@@ -113,7 +115,11 @@ export class GithubTestingRepo {
113115

114116
expectTagToBeCreated(tagName: string, sha: string): this {
115117
nock(this.repoApiUrl)
116-
.post(`/git/refs`, (b) => b.ref === `refs/tags/${tagName}` && b.sha === sha)
118+
.post(
119+
`/git/refs`,
120+
(b: {ref: string; sha: string}) =>
121+
new RegExp(`refs/tags/v?${tagName}`).test(b.ref) && b.sha === sha,
122+
)
117123
.reply(200, {});
118124
return this;
119125
}
@@ -135,7 +141,7 @@ export class GithubTestingRepo {
135141
if (bodyRegex && !bodyRegex.test(requestBody.body)) {
136142
return false;
137143
}
138-
return requestBody['tag_name'] === tagName;
144+
return new RegExp(`v?${tagName}`).test(requestBody['tag_name']);
139145
})
140146
.reply(200, {});
141147
return this;

ng-dev/utils/testing/sandbox-git-client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ export class SandboxGitClient extends AuthenticatedGitClient {
5555
return noopSpawnSyncReturns;
5656
}
5757

58+
// When ls-remote is run in our testing environment we are always
59+
// checking for an already defined ref which "should exist upstream"
60+
// Since no upstream exists in testing, we just check to make sure
61+
// the ref has already been defined locally by changing the git remote
62+
// provided to '.' which points to the local git repo.
63+
if (command === 'ls-remote') {
64+
const gitRemoteMatcher =
65+
/((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@\:/\-~]+)(\.git)(\/)?/;
66+
args = args.map((arg) => (gitRemoteMatcher.test(arg) ? '.' : arg));
67+
}
68+
5869
return super.runGraceful(args, options);
5970
}
6071
}

0 commit comments

Comments
 (0)