From 48ebc7c1797b13db2f22eb0cd4335598b68f7079 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 23 Jun 2025 12:43:20 -0300 Subject: [PATCH] ci: Update publishRelease logic for patch and pre-release handling (#36278) --- packages/release-action/src/publishRelease.ts | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/release-action/src/publishRelease.ts b/packages/release-action/src/publishRelease.ts index 16d8955e465..fefd08421cb 100644 --- a/packages/release-action/src/publishRelease.ts +++ b/packages/release-action/src/publishRelease.ts @@ -36,7 +36,9 @@ export async function publishRelease({ const { version: currentVersion } = await readPackageJson(cwd); - if (mergeFinal && isPreRelease(cwd)) { + const prerelease = isPreRelease(cwd); + + if (mergeFinal && prerelease) { // finish release candidate await exec('yarn', ['changeset', 'pre', 'exit']); } @@ -76,9 +78,19 @@ export async function publishRelease({ core.info(`latest release tag: ${latestRelease.tag_name}`); - const isLatestRelease = semver.gt(newVersion, latestRelease.tag_name); + const isLatestRelease = semver.gt(newVersion, latestRelease.tag_name) && !prerelease; + + /** + * These conditions are set to allow a patch release, which will be the latest, to be made without the need to merge into master (normalizing how patch releases are done, always via the 'cut' action) + * + * Strangely before, if mergeFinal was true a checkout was performed and then a push was made, which didn’t make sense because in theory mergeFinal is when merging into master (it was redundant but didn’t cause any issues) + * + * Today, we want that if the action is `cut` and the version is a patch, the merge should be performed, the pull request will automatically be closed, and the release will be made. + * However, if the `cut` is for a pre-release version, the merge to master should not be performed, because minor/major releases are still done manually. + * + * by `mergeFinal` we can know it was triggered by a pull request merge to master + */ - // if the action is "cut" on a branch that will be the next release, we need to merge the changes to master if (!mergeFinal && isLatestRelease) { // get current branch name const branchName = await getCurrentBranch(); @@ -86,6 +98,10 @@ export async function publishRelease({ // merge release changes to master await checkoutBranch('master'); await mergeBranch(branchName); + + await pushChanges(); + + await checkoutBranch(branchName); } core.info('fix dependencies in workspace packages'); @@ -102,7 +118,7 @@ export async function publishRelease({ name: newVersion, tag_name: newVersion, body: releaseBody, - prerelease: newVersion.includes('-'), + prerelease, make_latest: isLatestRelease ? 'true' : 'false', ...github.context.repo, });