Skip to content

build: publish-release script should run npm login before build #16188

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

Merged
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
19 changes: 11 additions & 8 deletions tools/release/git/git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {spawnSync, SpawnSyncReturns} from 'child_process';
* guaranteed that the working directory is always the target project directory.
*/
export class GitClient {

constructor(public projectDir: string, public remoteGitUrl: string) {}

/**
Expand All @@ -29,9 +28,9 @@ export class GitClient {

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

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

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

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

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

13 changes: 8 additions & 5 deletions tools/release/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,31 @@ class PublishReleaseTask extends BaseReleaseTask {
await this._promptStableVersionForNextTag();
}

// Ensure that we are authenticated, so that we can run "npm publish" for
// each package once the release output is built.
this._checkNpmAuthentication();

this._buildReleasePackages();
console.info(green(` ✓ Built the release output.`));

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

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

if (!releaseNotes) {
if (!extractedReleaseNotes) {
console.error(red(` ✘ Could not find release notes in the changelog.`));
process.exit(1);
}

const {releaseNotes, releaseTitle} = extractedReleaseNotes;

// Create and push the release tag before publishing to NPM.
this._createReleaseTag(newVersionName, releaseNotes);
this._pushReleaseTag(newVersionName, upstreamRemote);

// Ensure that we are authenticated before running "npm publish" for each package.
this._checkNpmAuthentication();

// Just in order to double-check that the user is sure to publish to NPM, we want
// the user to interactively confirm that the script should continue.
await this._promptConfirmReleasePublish();
Expand Down
2 changes: 1 addition & 1 deletion tools/release/stage-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class StageReleaseTask extends BaseReleaseTask {

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

// After the prompt for the new version, we print a new line because we want the
Expand Down
2 changes: 1 addition & 1 deletion tools/release/version-name/parse-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Version {
this.major, this.minor, this.patch, this.prereleaseLabel, this.prereleaseNumber);
}

equalsTo(other: Version): boolean {
equals(other: Version): boolean {
return this.major === other.major && this.minor === other.minor && this.patch === other.patch &&
this.prereleaseLabel === other.prereleaseLabel &&
this.prereleaseNumber === other.prereleaseNumber;
Expand Down