Skip to content

Commit 70aee92

Browse files
devversionjosephperrott
authored andcommitted
build: publish-release script should run npm login before build (#16188)
Building the release packages can take up a lot of time and we should rather run `npm login` before starting the build because otherwise if the login fails, the output needs to be rebuilt again. Additionally this commit fixes that existing local/remote tags are not properly parsed due to an issue with the Git references that refer to tags. Closes #16141
1 parent ffad004 commit 70aee92

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

tools/release/git/git-client.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {spawnSync, SpawnSyncReturns} from 'child_process';
77
* guaranteed that the working directory is always the target project directory.
88
*/
99
export class GitClient {
10-
1110
constructor(public projectDir: string, public remoteGitUrl: string) {}
1211

1312
/**
@@ -29,9 +28,9 @@ export class GitClient {
2928

3029
/** Gets the commit SHA for the specified remote repository branch. */
3130
getRemoteCommitSha(branchName: string): string {
32-
return this._spawnGitProcess(['ls-remote', this.remoteGitUrl, '-h',
33-
`refs/heads/${branchName}`])
34-
.stdout.split('\t')[0].trim();
31+
return this._spawnGitProcess(['ls-remote', this.remoteGitUrl, '-h', `refs/heads/${branchName}`])
32+
.stdout.split('\t')[0]
33+
.trim();
3534
}
3635

3736
/** Gets the latest commit SHA for the specified git reference. */
@@ -83,13 +82,18 @@ export class GitClient {
8382

8483
/** Gets the Git SHA of the specified local tag. */
8584
getShaOfLocalTag(tagName: string) {
86-
return this._spawnGitProcess(['rev-parse', `refs/tags/${tagName}`]).stdout.trim();
85+
// We need to use the "^{}" suffix to instruct Git to deference the tag to
86+
// the actual commit. See: https://www.git-scm.com/docs/git-rev-parse
87+
return this._spawnGitProcess(['rev-parse', `refs/tags/${tagName}^{}`]).stdout.trim();
8788
}
8889

8990
/** Gets the Git SHA of the specified remote tag. */
9091
getShaOfRemoteTag(tagName: string): string {
91-
return this._spawnGitProcess(['ls-remote', this.remoteGitUrl, '-t', `refs/tags/${tagName}`])
92-
.stdout.split('\t')[0].trim();
92+
// We need to use the "^{}" suffix to instruct Git to deference the tag to
93+
// the actual commit. See: https://www.git-scm.com/docs/git-rev-parse
94+
return this._spawnGitProcess(['ls-remote', this.remoteGitUrl, '-t', `refs/tags/${tagName}^{}`])
95+
.stdout.split('\t')[0]
96+
.trim();
9397
}
9498

9599
/** Pushes the specified tag to the remote git repository. */
@@ -108,4 +112,3 @@ export class GitClient {
108112
return this._spawnGitProcess(['remote']).stdout.trim().split('\n');
109113
}
110114
}
111-

tools/release/publish-release.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,31 @@ class PublishReleaseTask extends BaseReleaseTask {
9191
await this._promptStableVersionForNextTag();
9292
}
9393

94+
// Ensure that we are authenticated, so that we can run "npm publish" for
95+
// each package once the release output is built.
96+
this._checkNpmAuthentication();
97+
9498
this._buildReleasePackages();
9599
console.info(green(` ✓ Built the release output.`));
96100

97101
// Checks all release packages against release output validations before releasing.
98102
checkReleaseOutput(this.releaseOutputPath);
99103

100104
// Extract the release notes for the new version from the changelog file.
101-
const {releaseNotes, releaseTitle} = extractReleaseNotes(
105+
const extractedReleaseNotes = extractReleaseNotes(
102106
join(this.projectDir, CHANGELOG_FILE_NAME), newVersionName);
103107

104-
if (!releaseNotes) {
108+
if (!extractedReleaseNotes) {
105109
console.error(red(` ✘ Could not find release notes in the changelog.`));
106110
process.exit(1);
107111
}
108112

113+
const {releaseNotes, releaseTitle} = extractedReleaseNotes;
114+
109115
// Create and push the release tag before publishing to NPM.
110116
this._createReleaseTag(newVersionName, releaseNotes);
111117
this._pushReleaseTag(newVersionName, upstreamRemote);
112118

113-
// Ensure that we are authenticated before running "npm publish" for each package.
114-
this._checkNpmAuthentication();
115-
116119
// Just in order to double-check that the user is sure to publish to NPM, we want
117120
// the user to interactively confirm that the script should continue.
118121
await this._promptConfirmReleasePublish();

tools/release/stage-release.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class StageReleaseTask extends BaseReleaseTask {
7676

7777
const newVersion = await promptForNewVersion(this.currentVersion);
7878
const newVersionName = newVersion.format();
79-
const needsVersionBump = !newVersion.equalsTo(this.currentVersion);
79+
const needsVersionBump = !newVersion.equals(this.currentVersion);
8080
const stagingBranch = `release-stage/${newVersionName}`;
8181

8282
// After the prompt for the new version, we print a new line because we want the

tools/release/version-name/parse-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Version {
2424
this.major, this.minor, this.patch, this.prereleaseLabel, this.prereleaseNumber);
2525
}
2626

27-
equalsTo(other: Version): boolean {
27+
equals(other: Version): boolean {
2828
return this.major === other.major && this.minor === other.minor && this.patch === other.patch &&
2929
this.prereleaseLabel === other.prereleaseLabel &&
3030
this.prereleaseNumber === other.prereleaseNumber;

0 commit comments

Comments
 (0)