Skip to content

build: automatically push release tag to upstream #14595

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
merged 1 commit into from
Dec 20, 2018
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
7 changes: 7 additions & 0 deletions tools/release/git/git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,12 @@ export class GitClient {
createTag(commitRef: string, tagName: string, message: string): boolean {
return spawnSync('git', ['tag', tagName, '-m', message], {cwd: this.projectDir}).status === 0;
}

/** Pushes the specified tag to the remote git repository. */
pushTagToRemote(tagName: string): boolean {
return spawnSync('git', ['push', this.remoteGitUrl, `refs/tags/${tagName}`], {
cwd: this.projectDir
}).status === 0;
}
}

29 changes: 24 additions & 5 deletions tools/release/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ class PublishReleaseTask extends BaseReleaseTask {
this.checkReleaseOutput();
console.info(green(` ✓ Release output passed validation checks.`));

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

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

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

console.info(green(` ✓ Successfully published "${packageName}"`));
}

/** Creates a specified tag and pushes it to the remote repository */
private createAndPushReleaseTag(tagName: string) {
// TODO(devversion): find a way to extract the changelog part just for this version.
if (!this.git.createTag('HEAD', tagName, '')) {
console.error(red(` ✘ Could not create the "${tagName}" tag.`));
console.error(red(` Please make sure there is no existing tag with the same name.`));
process.exit(1);
}

console.info(green(` ✓ Created release tag: "${italic(tagName)}"`));

if (!this.git.pushTagToRemote(tagName)) {
console.error(red(` ✘ Could not push the "${tagName} "tag upstream.`));
console.error(red(` Please make sure you have permission to push to the ` +
`"${this.git.remoteGitUrl}" remote.`));
process.exit(1);
}

console.info(green(` ✓ Pushed release tag upstream.`));
}
}

/** Entry-point for the create release script. */
Expand Down