Skip to content

Commit 48ebc7c

Browse files
committed
ci: Update publishRelease logic for patch and pre-release handling (#36278)
1 parent 0428cf1 commit 48ebc7c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

packages/release-action/src/publishRelease.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export async function publishRelease({
3636

3737
const { version: currentVersion } = await readPackageJson(cwd);
3838

39-
if (mergeFinal && isPreRelease(cwd)) {
39+
const prerelease = isPreRelease(cwd);
40+
41+
if (mergeFinal && prerelease) {
4042
// finish release candidate
4143
await exec('yarn', ['changeset', 'pre', 'exit']);
4244
}
@@ -76,16 +78,30 @@ export async function publishRelease({
7678

7779
core.info(`latest release tag: ${latestRelease.tag_name}`);
7880

79-
const isLatestRelease = semver.gt(newVersion, latestRelease.tag_name);
81+
const isLatestRelease = semver.gt(newVersion, latestRelease.tag_name) && !prerelease;
82+
83+
/**
84+
* 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)
85+
*
86+
* 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)
87+
*
88+
* 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.
89+
* 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.
90+
*
91+
* by `mergeFinal` we can know it was triggered by a pull request merge to master
92+
*/
8093

81-
// if the action is "cut" on a branch that will be the next release, we need to merge the changes to master
8294
if (!mergeFinal && isLatestRelease) {
8395
// get current branch name
8496
const branchName = await getCurrentBranch();
8597

8698
// merge release changes to master
8799
await checkoutBranch('master');
88100
await mergeBranch(branchName);
101+
102+
await pushChanges();
103+
104+
await checkoutBranch(branchName);
89105
}
90106

91107
core.info('fix dependencies in workspace packages');
@@ -102,7 +118,7 @@ export async function publishRelease({
102118
name: newVersion,
103119
tag_name: newVersion,
104120
body: releaseBody,
105-
prerelease: newVersion.includes('-'),
121+
prerelease,
106122
make_latest: isLatestRelease ? 'true' : 'false',
107123
...github.context.repo,
108124
});

0 commit comments

Comments
 (0)