-
Notifications
You must be signed in to change notification settings - Fork 229
ci: global changelog generator script #5328
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
Conversation
|
Branch previewReview the following VRT differencesWhen a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:
If the changes are expected, update the |
Tachometer resultsCurrently, no packages are changed by this PR... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is an urgent automation, I think this approach can work as a temporary fix with a few hardening updates to how it's written but long-term we need to be handling this from the Changesets tooling (https://github.com/changesets/changesets/blob/main/docs/modifying-changelog-format.md#writing-changelog-formatting-functions)
scripts/add-global-changelog.js
Outdated
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const repoUrl = 'https://github.com/adobe/spectrum-web-components'; | ||
|
||
const pkg = JSON.parse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A best practice to keep code scoped is to wrap them in a main function and call the function at the end of the file. I think it's a good idea to maintain that best practice here that we see in our other scripts as well.
scripts/add-global-changelog.js
Outdated
const pkg = JSON.parse( | ||
fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf-8') | ||
); | ||
const newVersion = pkg.version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can skip this abstraction since newVersion is only used in the following line. We also need a check for if the package doesn't load to throw that warning. You're assuming here that pkg.version exists.
scripts/add-global-changelog.js
Outdated
const prevTag = execSync('git tag --sort=-creatordate') | ||
.toString() | ||
.split('\n') | ||
.filter(Boolean) | ||
.find((tag) => tag !== newTag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs more robust failure captures. I recommend if you're going to use exec for this, separate the command execution (exec is notoriously flaky in node scripts so you need to account for it failing) from the string parsing. Check that exec returned a string and then run the split, etc.
scripts/add-global-changelog.js
Outdated
if (!prevTag) { | ||
console.error('No previous tag found.'); | ||
process.exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to think about what information I would need to debug this error. At the age of this project, there's no change that there aren't previous tags to be found so maybe we want this error to tell us why the exec command couldn't return a value we were expecting? Maybe this should log the git tag command output?
scripts/add-global-changelog.js
Outdated
process.exit(1); | ||
} | ||
|
||
const date = new Date().toISOString().split('T')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const date = new Date().toISOString().split('T')[0]; | |
const date = new Date().toLocaleDateString('en-CA', { | |
year: 'numeric', | |
month: '2-digit', | |
day: '2-digit', | |
})); |
This should return the result you're wanting without having to do inline array parsing (which can sometimes lead to invalid results or fail when the array isn't in the format we're expecting).
scripts/add-global-changelog.js
Outdated
} | ||
|
||
const date = new Date().toISOString().split('T')[0]; | ||
const compareUrl = `${repoUrl}/compare/${prevTag}...${newTag}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is prevTag allowed to be a pre-tag or is there a requirement that prevTag must be a semver version? It seems like it must be one of the semver releases (not the betas for example) so maybe we can add a comment to that effect?
scripts/add-global-changelog.js
Outdated
const commitLogs = execSync(`git log ${prevTag}..HEAD --pretty=format:"%s|%h"`) | ||
.toString() | ||
.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's returning the commit logs but not the changelog content. Is that what we're wanting to add to the global changelog? It seems like the commit history is less useful now that we've migrated to changesets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great point where I would want everyone's opinion on. I don't think only a summary of the change is sufficient for the users to check what changes went along. I want to keep the CHANGELOG to follow the same pattern as we were doing during lerna which I feel the users still wants.
scripts/add-global-changelog.js
Outdated
|
||
// Skip if nothing relevant | ||
if (!features.length && !fixes.length) { | ||
console.log('🚫 No new feat() or fix() commits to add.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log('🚫 No new feat() or fix() commits to add.'); | |
console.log('🚫 No new feat() or fix() commits to add.'); |
Since no new features or fixes isn't necessarily a failure of the script, should we format this more like a success message that it ran successfully but with no changes?
scripts/add-global-changelog.js
Outdated
commits.forEach(({ message, hash }) => { | ||
const typeMatch = message.match(/^(feat|fix)\(([^)]+)\):\s*(.+)/i); | ||
if (typeMatch) { | ||
const [, type, scope, description] = typeMatch; | ||
const entry = `- **${scope}**: ${description} ([\`${hash}\`](${repoUrl}/commit/${hash}))`; | ||
if (type === 'feat') { | ||
features.push(entry); | ||
} else if (type === 'fix') { | ||
fixes.push(entry); | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can serve a temporary fix but we should really be using the changesets tooling to create this content from it's new source (which is not the commit messages): https://github.com/changesets/changesets/blob/main/docs/modifying-changelog-format.md#writing-changelog-formatting-functions
I think the challenge with this as a sustainable approach is that less and less useful data is present in commit messages and the real value for customers now lives in the changesets files.
scripts/add-global-changelog.js
Outdated
|
||
fs.writeFileSync( | ||
changelogPath, | ||
`${newEntry.trim()}\n\n${existingChangelog}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this push the # Change log
heading down to below the latest update?
Thanks for the info, I deliberately added a custom script and didn't opt for built-in |
I agree, I think the custom script approach here is quite pragmatic. While Changesets does a great job generating per-package changelogs, it doesn’t currently offer a built-in mechanism or public API to aggregate them into a single global changelog file. This script effectively fills that gap without waiting on upstream support. Relying solely on Changesets tooling would either limit us to fragmented changelogs or require non-trivial workarounds. The custom solution gives us immediate value, full control over formatting, and keeps things transparent for consumers of the monorepo. Until Changesets supports this natively, this seems like a solid and scalable workaround. |
package.json
Outdated
@@ -23,7 +23,8 @@ | |||
"build:types": "wireit", | |||
"build:watch": "wireit", | |||
"changeset-snapshot-publish": "yarn prepublishOnly && yarn changeset version --snapshot && yarn lint:versions --fix && yarn update-version && yarn changeset publish --no-git-tag --tag snapshot", | |||
"changeset-publish": "yarn prepublishOnly && yarn changeset version && yarn install && yarn lint:versions --fix && yarn update-version && yarn changeset publish --no-git-tag && yarn push-to-remote && yarn create-git-tag && yarn postpublish", | |||
"changeset-publish": "yarn prepublishOnly && yarn changeset version && yarn changelog:global && yarn install && yarn lint:versions --fix && yarn update-version && yarn changeset publish --no-git-tag && yarn push-to-remote && yarn create-git-tag && yarn postpublish", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t yarn changelog:global
be executed before yarn changeset version
? This is because yarn changelog:global
reads from changeset files located in the .changeset
directory. However, after running yarn changeset version
, all the changesets are removed/deleted, and the changelogs are populated. Consequently, yarn changelog:global
will no longer be able to read the changeset files in the .changeset
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right — excellent observation.
@import url("@spectrum-web-components/styles/tokens/global-vars.css"); | ||
@import url("@spectrum-web-components/styles/tokens/spectrum/global-vars.css"); | ||
@import url("@spectrum-web-components/styles/tokens/spectrum/custom-vars.css"); | ||
@import url("@spectrum-web-components/styles/tokens/spectrum/system-theme-bridge.css"); | ||
@import url("@spectrum-web-components/styles/src/spectrum-heading.css"); | ||
@import url("@spectrum-web-components/styles/src/spectrum-body.css"); | ||
@import url("@spectrum-web-components/styles/src/spectrum-code.css"); | ||
@import url("@spectrum-web-components/opacity-checkerboard/src/spectrum-opacity-checkerboard.css"); | ||
@import url("./inline-alert.css"); | ||
@import url("./fonts.css"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
Why did we add this url
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files came in from the main
.
8380afc
to
d7fad41
Compare
d7fad41
to
39c3832
Compare
39c3832
to
0079d0d
Compare
* ci: re-arranged order of execution of global addtion of changelog script * chore: fix logic for this to work before changeset version * chore: add snapshot back --------- Co-authored-by: Rajdeep Chandra <rajdeepchandra@Rajdeeps-MacBook-Pro-2.local> Co-authored-by: Piyush Vashisht <piyush17303@iiitd.ac.in>
Dismissing as @castastrophe is out of town and don't want to block the updated changes from being reviewed and merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this - looks great! 🚀 I just left a few comments
process.exit(1); | ||
} | ||
|
||
if (!gitTag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already throwing above (on line 73), so this seems redundant?
Description
This PR introduces a dual changelog generation setup in our monorepo:
✅ Per-package changelogs via @changesets/changelog-github
✅ Custom global changelog appended to the root CHANGELOG.md using a Yarn 4-compatible ESM script
Changes
Configured .changeset/config.json to use @changesets/changelog-github for individual packages.
Added a custom ESM script (scripts/add-global-changelog.js) to:
Read newly generated changelogs from the .changeset output
Format and append only feat: and fix: commits to the root CHANGELOG.md
Automatically add diff links (e.g., 1.4.0)
Updated package.json scripts to include:
Related issue(s)
Motivation and context
Since Changesets doesn’t support a global changelog out of the box, this is a custom script to bring that adds the experience back.
How has this been tested?
DO NOT COMMIT OR PUSH ANYTHING FROM TESTING
Patch version changelog
yarn prepublishOnly && yarn changelog:global
Minor version changelog
yarn changeset
sp-alert-banner
packageminor
version- **Fixed**: Updated
default styles for better contrast [#9999](https://github.com/adobe/spectrum-web-components/pull/9999)
yarn changelog:global
Major version changelog
yarn changeset
sp-textfield
packagemajor
version- **Added**: Added
hidden-labelattribute, for use with assistive technologies. (Before:
/ After:
)
yarn changelog:global
UNSTAGE ALL CHANGES AND CHANGESETS
Screenshots (if appropriate)
Types of changes
Checklist
Best practices
This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against
main
.