changesets / action

628 stars 218 forks source link

Build packages only if there's something to publish #171

Open diegohaz opened 2 years ago

diegohaz commented 2 years ago

Hi! I started using Changesets and the GitHub action on this project: https://github.com/ariakit/ariakit/blob/08cc868f0868eb77c304969c60920b4d155b40b7/.github/workflows/release.yml#L42-L48

To the publish property, I passed a script that builds the packages and then calls npx changeset publish.

The problem is that the build will always happen even when there's no package to publish.

Is there a way to run a command only if changeset publish will publish the packages, but before it actually publishes them to npm?

Andarist commented 2 years ago

The problem is that the build will always happen even when there's no package to publish.

It only happens when there are no changeset files on your base branch - so, usually, it's just a temporary situation as you often add a changeset file quickly after the release in some new PR, and then the Changeset action shouldn't use the publish script at all.

Is there a way to run a command only if changeset publish will publish the packages, but before it actually publishes them to npm?

You would have to add a prepare script or something to your packages as those should only be called when we actually start publishing packages (so after npm info call that determines if we need to publish in the first place).

Note however that the npm info-based strategy is quite problematic for us - especially when we consider custom registries etc. It turns out that the responses received from them are far from standardized. Some other tools (like yarn3 and pnpm) usually just try to publish stuff and if it turns out that a particular version was already published then they just "swallow" this error. So their strategy increases correctness and the expense of the perf (as they always need to prepare packages before they attempt to publish them). I was thinking about using their strategy - although maybe we should just fallback to that if we fail to detect if the package is already published or not.

diegohaz commented 2 years ago

It only happens when there are no changeset files on your base branch - so, usually, it's just a temporary situation as you often add a changeset file quickly after the release in some new PR, and then the Changeset action shouldn't use the publish script at all.

Nice! I just realized that was the case. I think that mitigates the problem. Thanks for the response.