Skip to content
Merged
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
24 changes: 20 additions & 4 deletions packages/release-action/src/publishRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down Expand Up @@ -76,16 +78,30 @@ 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();

// merge release changes to master
await checkoutBranch('master');
await mergeBranch(branchName);

await pushChanges();

await checkoutBranch(branchName);
}

core.info('fix dependencies in workspace packages');
Expand All @@ -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,
});
Expand Down
Loading