Skip to content

Releases aren't created when changesets exist on the main branch #507

@breadadams

Description

@breadadams

We're using changesets in a large monorepo, where we are also using the GitHub Merge Queue feature. This is a feature that allows engineers to queue their PRs to be merged to the main branch, and the queue handles merging all the branches with the latest main, in addition to merging them into each other (i.e. main and first PR into second PR; main, first PR and second PR into third PR, and so on).

Problem

  1. An engineer opens PR A, it includes a changset. It is added to the merge queue.
  2. PR A is merged into master.
  3. While that was happening, someone opens PR B (also including a changeset).
  4. When PR A hit master, it triggered a release.yml workflow to run, which has created a "Version packages" PR.
  5. PR B is added to the merge queue (position in the queue: 1).
  6. The "Version packages" PR is also added to the merge queue (position in the queue: 2).
  7. PR B and "Version packages" both reach master.
  8. The release.yml workflow runs again, however since there's a changeset file from PR B, it doesn't create the release (GitHub release nor npm publish) for the changes from PR A – the ones that came through in the "Version packages" PR. Instead it creates another "Version packages" PR, containing the bump + changeset removal from PR B.
  9. The latest "Version packages" goes into the merge queue, and eventually reaches the main branch.
  10. Again, release.yml runs and this time due to there being no new changeset files present, it performs the expected releases.

Although there are lots of steps here, I have simplified this a bit. We're in a situation where we don't get a release until for instance 5 or 6 "Version packages" PRs are merged during busy working hours.

Expected

In the list above, at step 8 when realease.yml ran, we would expect it to create releases/publish for the bumped versions on main branch, whilst also creating a new "Version packages" PR for the changesets present on main.

Question

Is there a specific reason why the action doesn't publish and create PRs in the same run?

From checking out the code I can see that this is caused by the switch statement in the primary index.ts, where publish only occurs for this case:

action/src/index.ts

Lines 65 to 68 in 04d574e

case !hasChangesets && hasPublishScript: {
core.info(
"No changesets found. Attempting to publish any unpublished packages to npm"
);

And a PR is only created for this case:

action/src/index.ts

Lines 119 to 121 in 04d574e

case hasChangesets: {
const octokit = setupOctokit(githubToken);
const { pullRequestNumber } = await runVersion({

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions