@@ -27,6 +27,7 @@ import {changelogPath, packageJsonPath, waitForPullRequestInterval} from './cons
2727import { invokeReleaseBuildCommand , invokeYarnInstallCommand } from './external-commands' ;
2828import { findOwnedForksOfRepoQuery } from './graphql-queries' ;
2929import { getPullRequestState } from './pull-request-state' ;
30+ import { getReleaseTagForVersion } from '../versioning/version-tags' ;
3031
3132/** Interface describing a Github repository. */
3233export interface GithubRepo {
@@ -377,33 +378,44 @@ export abstract class ReleaseAction {
377378 /**
378379 * Creates a commit for the specified files with the given message.
379380 * @param message Message for the created commit
380- * @param files List of project-relative file paths to be commited .
381+ * @param files List of project-relative file paths to be committed .
381382 */
382383 protected async createCommit ( message : string , files : string [ ] ) {
384+ // Note: `git add` would not be needed if the files are already known to
385+ // Git, but the specified files could also be newly created, and unknown.
386+ this . git . run ( [ 'add' , ...files ] ) ;
383387 this . git . run ( [ 'commit' , '-q' , '--no-verify' , '-m' , message , ...files ] ) ;
384388 }
385389
386390 /**
387- * Stages the specified new version for the current branch and creates a
388- * pull request that targets the given base branch.
391+ * Stages the specified new version for the current branch and creates a pull request
392+ * that targets the given base branch. Assumes the staging branch is already checked-out.
393+ *
394+ * @param newVersion New version to be staged.
395+ * @param compareVersionForReleaseNotes Version used for comparing with the current
396+ * `HEAD` in order build the release notes.
397+ * @param pullRequestTargetBranch Branch the pull request should target.
389398 * @returns an object describing the created pull request.
390399 */
391400 protected async stageVersionForBranchAndCreatePullRequest (
392401 newVersion : semver . SemVer ,
393- pullRequestBaseBranch : string ,
402+ compareVersionForReleaseNotes : semver . SemVer ,
403+ pullRequestTargetBranch : string ,
394404 ) : Promise < { releaseNotes : ReleaseNotes ; pullRequest : PullRequest } > {
395- /**
396- * The current version of the project for the branch from the root package.json. This must be
397- * retrieved prior to updating the project version.
398- */
399- const currentVersion = this . git . getMatchingTagForSemver ( await this . getProjectVersion ( ) ) ;
400- const releaseNotes = await ReleaseNotes . fromRange ( newVersion , currentVersion , 'HEAD' ) ;
405+ const releaseNotesCompareTag = getReleaseTagForVersion ( compareVersionForReleaseNotes ) ;
406+
407+ // Fetch the compare tag so that commits for the release notes can be determined.
408+ this . git . run ( [ 'fetch' , this . git . getRepoGitUrl ( ) , `refs/tags/${ releaseNotesCompareTag } ` ] ) ;
409+
410+ // Build release notes for commits from `<releaseNotesCompareTag>..HEAD`.
411+ const releaseNotes = await ReleaseNotes . forRange ( newVersion , releaseNotesCompareTag , 'HEAD' ) ;
412+
401413 await this . updateProjectVersion ( newVersion ) ;
402414 await this . prependReleaseNotesToChangelog ( releaseNotes ) ;
403415 await this . waitForEditsAndCreateReleaseCommit ( newVersion ) ;
404416
405417 const pullRequest = await this . pushChangesToForkAndCreatePullRequest (
406- pullRequestBaseBranch ,
418+ pullRequestTargetBranch ,
407419 `release-stage-${ newVersion } ` ,
408420 `Bump version to "v${ newVersion } " with changelog.` ,
409421 ) ;
@@ -417,15 +429,25 @@ export abstract class ReleaseAction {
417429 /**
418430 * Checks out the specified target branch, verifies its CI status and stages
419431 * the specified new version in order to create a pull request.
432+ *
433+ * @param newVersion New version to be staged.
434+ * @param compareVersionForReleaseNotes Version used for comparing with `HEAD` of
435+ * the staging branch in order build the release notes.
436+ * @param stagingBranch Branch within the new version should be staged.
420437 * @returns an object describing the created pull request.
421438 */
422439 protected async checkoutBranchAndStageVersion (
423440 newVersion : semver . SemVer ,
441+ compareVersionForReleaseNotes : semver . SemVer ,
424442 stagingBranch : string ,
425443 ) : Promise < { releaseNotes : ReleaseNotes ; pullRequest : PullRequest } > {
426444 await this . verifyPassingGithubStatus ( stagingBranch ) ;
427445 await this . checkoutUpstreamBranch ( stagingBranch ) ;
428- return await this . stageVersionForBranchAndCreatePullRequest ( newVersion , stagingBranch ) ;
446+ return await this . stageVersionForBranchAndCreatePullRequest (
447+ newVersion ,
448+ compareVersionForReleaseNotes ,
449+ stagingBranch ,
450+ ) ;
429451 }
430452
431453 /**
@@ -481,7 +503,7 @@ export abstract class ReleaseAction {
481503 versionBumpCommitSha : string ,
482504 prerelease : boolean ,
483505 ) {
484- const tagName = releaseNotes . version . format ( ) ;
506+ const tagName = getReleaseTagForVersion ( releaseNotes . version ) ;
485507 await this . git . github . git . createRef ( {
486508 ...this . git . remoteParams ,
487509 ref : `refs/tags/${ tagName } ` ,
0 commit comments