-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(release): try changesets instead of changelog (#10138)
The newish changelog workflow has personally saved me a lot of time and is half the reason we were able to release so many times on a moment's notice last week. But it's prone to merge conflicts, both in this repo and in the release tooling (most cherry picks from the main branch to the next branch had merge conflicts because of the changelog) so it's not going to scale out much more. But it's proved it's usefulness. I tried Changesets proper—seemed like the obvious choice and @ahaywood even independently came up with the idea—but it's overkill. I don't want to have to associate a semver with a PR (we use milestones for that). I also don't want to have to pick which packages we're versioning. Right now it's always all of them. And without the tooling or without using git, there's no obvious way to tie a changeset back to the PR that made it. (Maybe one of the changeset changelog packages do this, but config.) All I really want is what we're doing right now without the merge conflicts, so I spiked on a small script to generate a minimal changeset: ``` yarn changesets 10116 yarn changesets #10116 ``` The idea is that we'll do what we've been doing, but just via that command. It'll write a file to `.changesets/three-random-words.md`, and we'll put our release notes for the PR there. The release tooling can aggregate them into release notes at the time of release. The main con is that we can't see all the unreleased changes in linear order in one file. But tradeoffs. It's definitely worth not having to put up with merge conflicts.
- Loading branch information
Showing
12 changed files
with
283 additions
and
87 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: Check changesets | ||
description: Checks if changeset was added to the PR | ||
|
||
runs: | ||
using: node20 | ||
main: check_changesets.mjs | ||
|
||
inputs: | ||
labels: | ||
required: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { getInput } from '@actions/core' | ||
import { exec, getExecOutput } from '@actions/exec' | ||
import github from '@actions/github' | ||
|
||
async function main() { | ||
// If the PR has the "changesets-ok" label, just pass. | ||
const { labels } = JSON.parse(getInput('labels')) | ||
const hasChangesetsOkLabel = labels.some((label) => label.name === 'changesets-ok') | ||
if (hasChangesetsOkLabel) { | ||
console.log('Skipping check because of the "changesets-ok" label') | ||
return | ||
} | ||
|
||
// Check if the PR adds a changeset. | ||
await exec('git fetch origin main', [], { silent: true }) | ||
const { stdout } = await getExecOutput('git diff origin/main --name-only', [], { silent: true }) | ||
const changedFiles = stdout.toString().trim().split('\n').filter(Boolean) | ||
const addedChangeset = changedFiles.some((file) => file.startsWith('.changesets/')) | ||
if (addedChangeset) { | ||
// Empty space here (and in subsequent `console.log`s) for formatting in the action. | ||
console.log( | ||
[ | ||
'', | ||
"Added a changeset", | ||
].join('\n') | ||
) | ||
|
||
return | ||
} | ||
|
||
const pr = github.context.payload.pull_request | ||
console.log( | ||
[ | ||
'', | ||
'📝 Consider adding a changeset', | ||
'==============================', | ||
'', | ||
'If this is a user-facing PR (a feature or a fix), it should probably have a changeset.', | ||
`Run \`yarn changesets ${pr.number}\` to create a changeset for this PR.`, | ||
"If it doesn't need one (it's a chore), you can add the 'changesets-ok' label.", | ||
].join('\n') | ||
) | ||
|
||
process.exitCode = 1 | ||
} | ||
|
||
main() |
2 changes: 1 addition & 1 deletion
2
.github/actions/check_changelog/package.json → ...hub/actions/check_changesets/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { chalk, fs } from 'zx' | ||
|
||
import { | ||
getChangesetFilePath, | ||
getPlaceholder, | ||
resolveArgv, | ||
shouldShowHelp, | ||
showHelp, | ||
} from './changesetsHelpers.mjs' | ||
|
||
async function main() { | ||
if (shouldShowHelp()) { | ||
showHelp() | ||
return | ||
} | ||
|
||
const { prNumber } = resolveArgv() | ||
|
||
const changesetFilePath = getChangesetFilePath(prNumber) | ||
const placeholder = await getPlaceholder(prNumber) | ||
await fs.outputFile(changesetFilePath, placeholder) | ||
console.log( | ||
[ | ||
`📝 Created a changeset at ${chalk.magenta(changesetFilePath)}`, | ||
" Commit it when you're done and push your branch up to GitHub. Thank you! 🙏", | ||
].join('\n') | ||
) | ||
} | ||
|
||
try { | ||
await main() | ||
} catch (error) { | ||
console.error(`${error.message}\n`) | ||
showHelp() | ||
process.exitCode = 1 | ||
} | ||
|
||
// Test suite | ||
// | ||
// - should be the placeholder at ./placeholder.md | ||
// - yarn changesets | ||
// | ||
// - should be the title and body of PR 10075 | ||
// - yarn changesets 10075 | ||
// - yarn changesets '#10075' | ||
// | ||
// - should throw and show help | ||
// - yarn changesets abcd | ||
// - yarn changesets 10075000 | ||
// - yarn changesets https://github.com/redwoodjs/redwood/pull/10075 |
Oops, something went wrong.