Skip to content

Commit 0ba6057

Browse files
devversionjelbourn
authored andcommitted
build: automatically push release tag to upstream (#14595)
1 parent 528dff5 commit 0ba6057

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

tools/release/git/git-client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,12 @@ export class GitClient {
6363
createTag(commitRef: string, tagName: string, message: string): boolean {
6464
return spawnSync('git', ['tag', tagName, '-m', message], {cwd: this.projectDir}).status === 0;
6565
}
66+
67+
/** Pushes the specified tag to the remote git repository. */
68+
pushTagToRemote(tagName: string): boolean {
69+
return spawnSync('git', ['push', this.remoteGitUrl, `refs/tags/${tagName}`], {
70+
cwd: this.projectDir
71+
}).status === 0;
72+
}
6673
}
6774

tools/release/publish-release.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ class PublishReleaseTask extends BaseReleaseTask {
8888
this.checkReleaseOutput();
8989
console.info(green(` ✓ Release output passed validation checks.`));
9090

91-
// TODO(devversion): find a way to extract the changelog part just for this version.
92-
this.git.createTag('HEAD', newVersionName, '');
93-
console.info(green(` ✓ Created release tag: "${italic(newVersionName)}"`));
91+
// Create and push the release tag before publishing to NPM.
92+
this.createAndPushReleaseTag(newVersionName);
9493

9594
// Ensure that we are authenticated before running "npm publish" for each package.
9695
this.checkNpmAuthentication();
@@ -105,8 +104,7 @@ class PublishReleaseTask extends BaseReleaseTask {
105104

106105
console.log();
107106
console.info(green(bold(` ✓ Published all packages successfully`)));
108-
console.info(yellow(` ⚠ Please push the newly created tag to Github and draft a new ` +
109-
`release.`));
107+
console.info(yellow(` ⚠ Please draft a new release of the version on Github.`));
110108
console.info(yellow(
111109
` ${getGithubReleasesUrl(this.repositoryOwner, this.repositoryName)}`));
112110
}
@@ -230,6 +228,27 @@ class PublishReleaseTask extends BaseReleaseTask {
230228

231229
console.info(green(` ✓ Successfully published "${packageName}"`));
232230
}
231+
232+
/** Creates a specified tag and pushes it to the remote repository */
233+
private createAndPushReleaseTag(tagName: string) {
234+
// TODO(devversion): find a way to extract the changelog part just for this version.
235+
if (!this.git.createTag('HEAD', tagName, '')) {
236+
console.error(red(` ✘ Could not create the "${tagName}" tag.`));
237+
console.error(red(` Please make sure there is no existing tag with the same name.`));
238+
process.exit(1);
239+
}
240+
241+
console.info(green(` ✓ Created release tag: "${italic(tagName)}"`));
242+
243+
if (!this.git.pushTagToRemote(tagName)) {
244+
console.error(red(` ✘ Could not push the "${tagName} "tag upstream.`));
245+
console.error(red(` Please make sure you have permission to push to the ` +
246+
`"${this.git.remoteGitUrl}" remote.`));
247+
process.exit(1);
248+
}
249+
250+
console.info(green(` ✓ Pushed release tag upstream.`));
251+
}
233252
}
234253

235254
/** Entry-point for the create release script. */

0 commit comments

Comments
 (0)