Skip to content

Commit 155a0cb

Browse files
devversionjelbourn
authored andcommitted
build: publish script should not print error if tag does not exist (#15080)
Currently the publish script prints an error if the release tag does not exist locally yet. This is not expected since the function that calls `git` to check if a given tag exists, returns a boolean and should not additionally print the git `stderr`. Note we can also look into attaching the release notes automatically, but since the release notes are making the URL too large and Github denies too large URL's, this is something we can explore in a follow-ups.
1 parent 1099c79 commit 155a0cb

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

tools/release/extract-release-notes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ export function extractReleaseNotes(changelogPath: string, versionName: string)
1010
// section of a version by starting with the release header which can either use the markdown
1111
// "h1" or "h2" syntax. The end of the section will be matched by just looking for the first
1212
// subsequent release header.
13-
const releaseNotesRegex = new RegExp(`(##? ${escapedVersion}.*?)##? 7\\.`, 's');
13+
const releaseNotesRegex = new RegExp(
14+
`(##? ${escapedVersion} "(.*?)" \\(.*?)##? \\d+\\.\\d+`, 's');
1415
const matches = releaseNotesRegex.exec(changelogContent);
1516

16-
return matches ? matches[1].trim() : null;
17+
return matches ? {
18+
releaseTitle: matches[2],
19+
releaseNotes: matches[1].trim(),
20+
} : null;
1721
}

tools/release/git/git-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export class GitClient {
1414
* Spawns a child process running Git. The "stderr" output is inherited and will be printed
1515
* in case of errors. This makes it easier to debug failed commands.
1616
*/
17-
private _spawnGitProcess(args: string[]): SpawnSyncReturns<string> {
17+
private _spawnGitProcess(args: string[], printStderr = true): SpawnSyncReturns<string> {
1818
return spawnSync('git', args, {
1919
cwd: this.projectDir,
20-
stdio: ['pipe', 'pipe', 'inherit'],
20+
stdio: ['pipe', 'pipe', printStderr ? 'inherit' : 'pipe'],
2121
encoding: 'utf8',
2222
});
2323
}
@@ -76,7 +76,7 @@ export class GitClient {
7676

7777
/** Checks whether the specified tag exists locally. */
7878
hasLocalTag(tagName: string) {
79-
return this._spawnGitProcess(['rev-parse', `refs/tags/${tagName}`]).status === 0;
79+
return this._spawnGitProcess(['rev-parse', `refs/tags/${tagName}`], false).status === 0;
8080
}
8181

8282
/** Gets the Git SHA of the specified local tag. */

tools/release/git/github-urls.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ export function getGithubBranchCommitsUrl(owner: string, repository: string, bra
33
return `https://github.com/${owner}/${repository}/commits/${branchName}`;
44
}
55

6-
/** Gets a Github URL that refers list of releases within the specified repository. */
7-
export function getGithubReleasesUrl(owner: string, repository: string) {
8-
return `https://github.com/${owner}/${repository}/releases`;
6+
/** Gets a Github URL that can be used to create a new release from a given tag. */
7+
export function getGithubNewReleaseUrl(options: {owner: string, repository: string,
8+
tagName: string, releaseTitle: string}) {
9+
10+
return `https://github.com/${options.owner}/${options.repository}/releases/new?` +
11+
`tag=${encodeURIComponent(options.tagName)}&` +
12+
`title=${encodeURIComponent(options.releaseTitle)}&`;
913
}

tools/release/publish-release.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {BaseReleaseTask} from './base-release-task';
66
import {checkReleaseOutput} from './check-release-output';
77
import {extractReleaseNotes} from './extract-release-notes';
88
import {GitClient} from './git/git-client';
9-
import {getGithubReleasesUrl} from './git/github-urls';
9+
import {getGithubNewReleaseUrl} from './git/github-urls';
1010
import {isNpmAuthenticated, runInteractiveNpmLogin, runNpmPublish} from './npm/npm-client';
1111
import {promptForNpmDistTag} from './prompt/npm-dist-tag-prompt';
1212
import {releasePackages} from './release-output/release-packages';
@@ -91,7 +91,7 @@ class PublishReleaseTask extends BaseReleaseTask {
9191
checkReleaseOutput(this.releaseOutputPath);
9292

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

9797
if (!releaseNotes) {
@@ -114,11 +114,17 @@ class PublishReleaseTask extends BaseReleaseTask {
114114
this.publishPackageToNpm(packageName, npmDistTag);
115115
}
116116

117+
const newReleaseUrl = getGithubNewReleaseUrl({
118+
owner: this.repositoryOwner,
119+
repository: this.repositoryName,
120+
tagName: newVersionName,
121+
releaseTitle: releaseTitle,
122+
});
123+
117124
console.log();
118125
console.info(green(bold(` ✓ Published all packages successfully`)));
119126
console.info(yellow(` ⚠ Please draft a new release of the version on Github.`));
120-
console.info(yellow(
121-
` ${getGithubReleasesUrl(this.repositoryOwner, this.repositoryName)}`));
127+
console.info(yellow(` ${newReleaseUrl}`));
122128
}
123129

124130
/**

0 commit comments

Comments
 (0)