Skip to content

build: publish script should not print error if tag does not exist #15080

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
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
8 changes: 6 additions & 2 deletions tools/release/extract-release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ export function extractReleaseNotes(changelogPath: string, versionName: string)
// section of a version by starting with the release header which can either use the markdown
// "h1" or "h2" syntax. The end of the section will be matched by just looking for the first
// subsequent release header.
const releaseNotesRegex = new RegExp(`(##? ${escapedVersion}.*?)##? 7\\.`, 's');
const releaseNotesRegex = new RegExp(
`(##? ${escapedVersion} "(.*?)" \\(.*?)##? \\d+\\.\\d+`, 's');
const matches = releaseNotesRegex.exec(changelogContent);

return matches ? matches[1].trim() : null;
return matches ? {
releaseTitle: matches[2],
releaseNotes: matches[1].trim(),
} : null;
}
6 changes: 3 additions & 3 deletions tools/release/git/git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class GitClient {
* Spawns a child process running Git. The "stderr" output is inherited and will be printed
* in case of errors. This makes it easier to debug failed commands.
*/
private _spawnGitProcess(args: string[]): SpawnSyncReturns<string> {
private _spawnGitProcess(args: string[], printStderr = true): SpawnSyncReturns<string> {
return spawnSync('git', args, {
cwd: this.projectDir,
stdio: ['pipe', 'pipe', 'inherit'],
stdio: ['pipe', 'pipe', printStderr ? 'inherit' : 'pipe'],
encoding: 'utf8',
});
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export class GitClient {

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

/** Gets the Git SHA of the specified local tag. */
Expand Down
10 changes: 7 additions & 3 deletions tools/release/git/github-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ export function getGithubBranchCommitsUrl(owner: string, repository: string, bra
return `https://github.com/${owner}/${repository}/commits/${branchName}`;
}

/** Gets a Github URL that refers list of releases within the specified repository. */
export function getGithubReleasesUrl(owner: string, repository: string) {
return `https://github.com/${owner}/${repository}/releases`;
/** Gets a Github URL that can be used to create a new release from a given tag. */
export function getGithubNewReleaseUrl(options: {owner: string, repository: string,
tagName: string, releaseTitle: string}) {

return `https://github.com/${options.owner}/${options.repository}/releases/new?` +
`tag=${encodeURIComponent(options.tagName)}&` +
`title=${encodeURIComponent(options.releaseTitle)}&`;
}
14 changes: 10 additions & 4 deletions tools/release/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {BaseReleaseTask} from './base-release-task';
import {checkReleaseOutput} from './check-release-output';
import {extractReleaseNotes} from './extract-release-notes';
import {GitClient} from './git/git-client';
import {getGithubReleasesUrl} from './git/github-urls';
import {getGithubNewReleaseUrl} from './git/github-urls';
import {isNpmAuthenticated, runInteractiveNpmLogin, runNpmPublish} from './npm/npm-client';
import {promptForNpmDistTag} from './prompt/npm-dist-tag-prompt';
import {releasePackages} from './release-output/release-packages';
Expand Down Expand Up @@ -91,7 +91,7 @@ class PublishReleaseTask extends BaseReleaseTask {
checkReleaseOutput(this.releaseOutputPath);

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

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

const newReleaseUrl = getGithubNewReleaseUrl({
owner: this.repositoryOwner,
repository: this.repositoryName,
tagName: newVersionName,
releaseTitle: releaseTitle,
});

console.log();
console.info(green(bold(` ✓ Published all packages successfully`)));
console.info(yellow(` ⚠ Please draft a new release of the version on Github.`));
console.info(yellow(
` ${getGithubReleasesUrl(this.repositoryOwner, this.repositoryName)}`));
console.info(yellow(` ${newReleaseUrl}`));
}

/**
Expand Down