Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Changesets and update release actions #56

Open
wants to merge 4 commits into
base: canary
Choose a base branch
from

Conversation

ernestoresende
Copy link
Collaborator

This introduces Changesets as part of the publishing pipeline and sets up the actions necessary to handle canary releases.

With this setup, any new commits to canary branch will automatically create a new release with the tag x.x.x-canary.{commitHash}. Canary releases will not show up in the Releases page from GitHub (let me know if this is not the wanted behavior).

Beware that in this setup, canary releases are not using the snapshot release feature from Changesets, as the idea is to automatically generate canary releases off the corresponding branch. We can still manually use the Snapshot feature and alter the template in "prereleaseTemplate": "{tag}.{commit}" if we need to trigger other kinds of manual and/or CI releases.

@trevor-scheer
Copy link
Member

trevor-scheer commented Sep 5, 2023

You are of course welcome to do what you think is best for this project, but I do think the canary stuff adds a level of complexity that's solved very well by CodeSandbox CI. This allows any contributor to get a "canary" build from their PR, which is the ideal DX in my opinion. Every PR gets a comment with a link to builds that can be npm installed (or yarn, etc.).

Example: apollographql/apollo-server#7699 (comment)

@ernestoresende
Copy link
Collaborator Author

I see. From what I can gather, I like the idea of giving individual PR's a Sandbox where the library can be immediately tested and installed as a dependency from the registry.

I don't know if CodeSandbox CI allows you to actually publish those changes to the NPM registry, but if this is not the case, I think we're trying to solve for two different problems here:

  • CodeSandbox CI, as you proposed, would be used to generate a new build in a sandbox for each new contribution PR automatically;
  • The current Changesets setup is used to generate canary releases that actually end up on the NPM registry and receive a canary tag (similar to what happens in apollo-server during v4.0.0 launch with the rc and alpha tags).

The main point here being that canary releases will actually get published to the NPM registry instead of the isolated CodeSandbox registry, and can be easily installed by non-contributor users.

Let me know if you'd recommend me going trough with both approaches, or just dropping the canary release workflow and sticking with the CodeSandbox CI releases, both approaches are okay for me.

@trevor-scheer
Copy link
Member

@ernestoresende yeah - they're not mutually exclusive, so if you like the canary workflow don't let me stop you. As always, this is more your project than mine; I'm just here to guide.

The codesandbox builds are npm installable via a URL provided in the comment, but you're right that they aren't published to the npm registry. The difference is subtle, though, and they're effectively equivalent for dev/testing purposes. Possibly the biggest drawback is that the codesandbox builds aren't persisted forever, it's something like 90 days (don't quote me) so they do expire. That would probably be the best argument for the canary workflow.

This is also a pretty reversible decision, so feel free to go forward with both and see if you prefer one workflow over the other 👍

"changedFilePatterns": ["src/**"],
"snapshot": {
"useCalculatedVersion": true,
"prereleaseTemplate": "{tag}.{commit}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker - but if you wanted to release a normal alpha, rc, etc, you'd be stuck with the commit hash on the version as well?

const [major, minor, patch] = oldVersion.split('.').map(Number);
const newVersion = `${major}.${minor}.${patch + 1}-canary.${commitHash}`;
pkg.version = newVersion;
const content = JSON.stringify(pkg, null, '\t') + '\n';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never actually seen a \t used here, typically it's a 2. I guess this depends on if the project uses tabs or spaces? Haven't thought about that in a long time :)

Suggested change
const content = JSON.stringify(pkg, null, '\t') + '\n';
const content = JSON.stringify(pkg, null, 2) + '\n';

Comment on lines +1 to +11
// ORIGINALLY FROM CLOUDFLARE WRANGLER:
// https://github.com/cloudflare/wrangler2/blob/main/.github/changeset-version.js

import { exec } from 'child_process';
// This script is used by the `release.yml` workflow to update the version of the packages being released.
// The standard step is only to run `changeset version` but this does not update the package-lock.json file.
// So we also run `npm install`, which does this update.
// This is a workaround until this is handled automatically by `changeset version`.
// See https://github.com/changesets/changesets/issues/421.
exec('npx changeset version');
exec('npm install');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be an npm script, fine as is too. We do the same thing in Apollo Server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants