Skip to content
Open
Show file tree
Hide file tree
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
37 changes: 36 additions & 1 deletion ng-dev/release/publish/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,38 @@ export abstract class ReleaseAction {
pullRequest: PullRequest;
builtPackagesWithInfo: BuiltPackageWithInfo[];
}> {
const releaseNotesCompareTag = getReleaseTagForVersion(compareVersionForReleaseNotes);
/** Tag name for the version being used for the base of comparison generating release notes. */
let releaseNotesCompareTag: string;
// Determine whether the previous version used for comparison in generating release notes used a v prefix.
/** The expected comparison version prefixed with `v`. */
const prefixedTag = getReleaseTagForVersion(compareVersionForReleaseNotes);
/** The expected comparison version. */
const unprefixedTag = compareVersionForReleaseNotes.version;

if (
this.git.runGraceful([
'ls-remote',
'-q',
'--exit-code',
this.git.getRepoGitUrl(),
`refs/tags/${prefixedTag}`,
]).status === 0
) {
releaseNotesCompareTag = prefixedTag;
} else if (
this.git.runGraceful([
'ls-remote',
'-q',
'--exit-code',
this.git.getRepoGitUrl(),
`refs/tags/${unprefixedTag}`,
]).status === 0
) {
releaseNotesCompareTag = unprefixedTag;
} else {
Log.error(` ✘ Unable to find previous tag (${prefixedTag}) for building release notes.`);
throw new FatalReleaseActionError();
}

// Fetch the compare tag so that commits for the release notes can be determined.
// We forcibly override existing local tags that are named similar as we will fetch
Expand Down Expand Up @@ -700,6 +731,10 @@ export abstract class ReleaseAction {
// built in the staging phase have not been modified accidentally.
await assertIntegrityOfBuiltPackages(builtPackagesWithInfo);

// NOTE:
// The Github Release must be created prior to publishing to npm as the version of the package
// being published is verified by wombot proxy to already match the existing Github relase.

// Create a Github release for the new version.
await this._createGithubReleaseForVersion(
releaseNotes,
Expand Down
2 changes: 1 addition & 1 deletion ng-dev/release/publish/test/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ describe('common release action logic', () => {
tagName,
true,
changelogPattern`
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).
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).
`,
);

Expand Down
2 changes: 1 addition & 1 deletion ng-dev/release/versioning/version-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import semver from 'semver';

/** Gets the release tag name for the specified version. */
export function getReleaseTagForVersion(version: semver.SemVer): string {
return version.format();
return `v${version.format()}`;
}
12 changes: 9 additions & 3 deletions ng-dev/utils/testing/github-api-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export class GithubTestingRepo {
}

expectReleaseByTagRequest(tagName: string, id: number): this {
nock(this.repoApiUrl).get(`/releases/tags/${tagName}`).reply(200, {id});
nock(this.repoApiUrl)
.get(new RegExp(`/releases/tags/v?${tagName}`))
.reply(200, {id});
return this;
}

Expand Down Expand Up @@ -113,7 +115,11 @@ export class GithubTestingRepo {

expectTagToBeCreated(tagName: string, sha: string): this {
nock(this.repoApiUrl)
.post(`/git/refs`, (b) => b.ref === `refs/tags/${tagName}` && b.sha === sha)
.post(
`/git/refs`,
(b: {ref: string; sha: string}) =>
new RegExp(`refs/tags/v?${tagName}`).test(b.ref) && b.sha === sha,
)
.reply(200, {});
return this;
}
Expand All @@ -135,7 +141,7 @@ export class GithubTestingRepo {
if (bodyRegex && !bodyRegex.test(requestBody.body)) {
return false;
}
return requestBody['tag_name'] === tagName;
return new RegExp(`v?${tagName}`).test(requestBody['tag_name']);
})
.reply(200, {});
return this;
Expand Down
11 changes: 11 additions & 0 deletions ng-dev/utils/testing/sandbox-git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ export class SandboxGitClient extends AuthenticatedGitClient {
return noopSpawnSyncReturns;
}

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

return super.runGraceful(args, options);
}
}
Expand Down
Loading