Skip to content

Conversation

@rubencarvalho
Copy link
Contributor

@rubencarvalho rubencarvalho commented Oct 8, 2025

Description

Refactored and updated the current global changelog generation script (first-gen/scripts/update-global-changelog.js) to allow generating a 2nd-gen global changelog.
Updated the changesets README documentation to provide guidance for creating changesets in the new monorepo structure considering both first-gen and second-gen packages.

Motivation and context

The monorepo structure now includes both first-gen Spectrum Web Components and second-gen @swc/core packages, but the changeset documentation didn't provide clear guidance on how to create changesets for this new structure nor did the global changelog script support it.

Related issue(s)

  • SWC-1238

Screenshots (if appropriate)

N/A - Internal tooling improvement


Author's checklist

  • I have read the CONTRIBUTING and PULL_REQUESTS documents.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices
  • I have added automated tests to cover my changes.
  • I have included a well-written changeset if my change needs to be published.
  • I have included updated documentation if my change required it.

Reviewer's checklist

  • Includes a Github Issue with appropriate flag or Jira ticket number without a link
  • Includes thoughtfully written changeset if changes suggested include patch, minor, or major features
  • Automated tests cover all use cases and follow best practices for writing
  • Validated on all supported browsers
  • All VRTs are approved before the author can update Golden Hash

Manual review test cases

  • Test changelog generation for first-gen components

    1. Go to the project root directory
    2. Run yarn changeset and create a changeset with @spectrum-web-components/button: minor
    3. Run node first-gen/scripts/update-global-changelog.js
    4. Expect the first-gen CHANGELOG.md to be updated with the new version entry
  • Test changelog generation for @swc/core packages

    1. Go to the project root directory
    2. Run yarn changeset and create a changeset with @swc/core: patch
    3. Run node first-gen/scripts/update-global-changelog.js
    4. Expect the second-gen/packages/core/CHANGELOG.md to be updated with the new version entry
  • Test changeset documentation clarity

    1. Go to .changeset/README.md
    2. Review the updated documentation
    3. Expect clear guidance on creating changesets for both first-gen and second-gen packages
  • Test script error handling

    1. Run the script when no changesets exist
    2. Run the script when git tags are missing
    3. Expect appropriate error messages

@changeset-bot
Copy link

changeset-bot bot commented Oct 8, 2025

⚠️ No Changeset found

Latest commit: fa42e41

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2025

📚 Branch Preview

🔍 Visual Regression Test Results

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

Deployed to Azure Blob Storage: pr-5795

If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2025

Tachometer results

Currently, no packages are changed by this PR...

@Rajdeepc
Copy link
Contributor

Rajdeepc commented Oct 9, 2025

Is it a good idea to create a approach document before we add these changes or are you planning to add it in the description root of this PR?

@rubencarvalho rubencarvalho changed the title Changelog changeset barebones chore: make changelog generation work for multiple packages and update changeset docs Oct 9, 2025
@rubencarvalho rubencarvalho marked this pull request as ready for review October 9, 2025 09:01
@rubencarvalho rubencarvalho requested a review from a team as a code owner October 9, 2025 09:01
@rubencarvalho rubencarvalho force-pushed the changelog-changeset-barebones branch from 56bf0c9 to c522607 Compare October 9, 2025 09:34
@rubencarvalho
Copy link
Contributor Author

Is it a good idea to create a approach document before we add these changes or are you planning to add it in the description root of this PR?

This is being tackled in SWC-1234. We can wait for those docs!

@caseyisonit caseyisonit added 2nd gen These issues or PRs map to our 2nd generation work to modernizing infrastructure. Status: Ready for review PR ready for review or re-review. labels Oct 20, 2025
@rubencarvalho
Copy link
Contributor Author

rubencarvalho commented Oct 23, 2025

Is it a good idea to create a approach document before we add these changes or are you planning to add it in the description root of this PR?

This is being tackled in SWC-1234. We can wait for those docs!

Update: we agreed to not keep this one blocked, separate both concerns and revisit documentation post-barebones (e.g., how to surface this and other docs in the unified place).

@caseyisonit caseyisonit added the High Priority PR Review PR is a high priority and should be reviewed ASAP label Oct 24, 2025
Copy link
Contributor

@Rajdeepc Rajdeepc left a comment

Choose a reason for hiding this comment

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

Thanks! The changes look fairly structured and robust. Just few nits on some performance improvement and abstraction.

Comment on lines 151 to 163
function calculateNextVersion(currentVersion, majorChanges, minorChanges) {
const currentVersionParts = currentVersion
.split('.')
.map((part) => parseInt(part, 10));
let nextVersion;

// Calculate next version based on changes
if (majorChanges.length > 0) {
// Major version bump
nextVersion = `${currentVersionParts[0] + 1}.0.0`;
return `${currentVersionParts[0] + 1}.0.0`;
} else if (minorChanges.length > 0) {
// Minor version bump
nextVersion = `${currentVersionParts[0]}.${currentVersionParts[1] + 1}.0`;
return `${currentVersionParts[0]}.${currentVersionParts[1] + 1}.0`;
} else {
// Patch version bump
nextVersion = `${currentVersionParts[0]}.${currentVersionParts[1]}.${currentVersionParts[2] + 1}`;
return `${currentVersionParts[0]}.${currentVersionParts[1]}.${currentVersionParts[2] + 1}`;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use can use semver package to do this.

function calculateNextVersion(currentVersion, majorChanges, minorChanges) {
    if (majorChanges.length > 0) return semver.inc(currentVersion, 'major');
    if (minorChanges.length > 0) return semver.inc(currentVersion, 'minor');
    return semver.inc(currentVersion, 'patch');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Updated it.

Comment on lines 274 to 278
fs.writeFileSync(
changelogPath,
`${headerText}\n\n${newEntry.trim()}\n\n${existingChangelog.trim()}`,
`${headerText}\n\n${newEntry.trim()}\n\n${remainingContent.trim()}`,
'utf-8'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

These sync writes can block the event loop and will slow down execution since we are trying to read through the component readme. With growing component directory this can impact. You can use non blocking fsPromises instead.

await fsPromises.writeFile(
        changelogPath,
        `${headerText}\n\n${newEntry.trim()}\n\n${remainingContent.trim()}`,
        'utf8'
    );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

async function createGlobalChangelog() {
const currentTag = validateCurrentVersion();
const { firstGen, core } = processChangesets();

Copy link
Contributor

Choose a reason for hiding this comment

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

you can skip here early if no changes detected just to add that extra performance optimisation.

   if (
     !firstGen.majorChanges.length && !firstGen.minorChanges.length && !firstGen.patchChanges.length &&
     !core.majorChanges.length && !core.minorChanges.length && !core.patchChanges.length
   ) {
     console.log('No new changesets detected. Skipping changelog generation.');
     return;
   }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 372 to 374
createGlobalChangelog().catch((error) => {
console.error('Error updating changelog:', error);
process.exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very hard exit. Can you add a global try/catch?

 (async () => {
   try {
     await createGlobalChangelog();
   } catch (error) {
     console.error('Error updating changelog:', error);
     process.exit(1);
   }
 })();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update it!

Comment on lines 88 to 142
const changesetDir = path.resolve(__dirname, '../.changeset');
/**
* Processes changeset files and categorizes changes by type and target
* @returns {Object} Object containing categorized changes for both first-gen and core
*/
function processChangesets() {
const changesetDir = path.resolve(__dirname, '../../.changeset');
const changesetFiles = fs
.readdirSync(changesetDir)
.filter((file) => file.endsWith('.md') && file !== 'README.md');

const majorChanges = [];
const minorChanges = [];
const patchChanges = [];
const coreMajorChanges = [];
const coreMinorChanges = [];
const corePatchChanges = [];

// Process each changeset file to extract change information
for (const file of changesetFiles) {
const filePath = path.join(changesetDir, file);
const content = fs.readFileSync(filePath, 'utf-8');

// Extract the frontmatter from the changeset
const frontmatterMatch = content.match(
/---\n([\s\S]*?)\n---\n([\s\S]*)/
);

if (frontmatterMatch) {
const [, frontmatter, description] = frontmatterMatch;

// Parse the frontmatter to determine the change type
const isMajor = frontmatter.includes('major');
const isMinor = frontmatter.includes('minor');
// If not major or minor, it's a patch

// Extract the package scope from the frontmatter
const packageMatch = frontmatter.match(
/'@spectrum-web-components\/([^']+)':|"@spectrum-web-components\/([^"]+)":/
);
// Extract component name from package name and prefix with "sp-"
const match = packageMatch?.[1] || packageMatch?.[2];
const scope = match ? `sp-${match}` : 'core';
// Clean up the description text
const cleanDescription = description.trim();

// Create the entry (without commit hash since we're using changesets)
const entry = `**${scope}**: ${cleanDescription}\n\n`;
// "@spectrum-web-components" (first-gen components)
// go to first-gen global changelog
for (const match of frontmatter.matchAll(
/['"]@spectrum-web-components\/([^'"]+)['"]:\s*(major|minor|patch)/g
)) {
const componentName = match[1];
const changeType = match[2];
const scope = `sp-${componentName}`;
const entry = `**${scope}**: ${cleanDescription}\n\n`;

if (changeType === 'major') {
majorChanges.push(entry);
} else if (changeType === 'minor') {
minorChanges.push(entry);
} else {
patchChanges.push(entry);
}
}

// Categorize based on semver bump type
if (isMajor) {
majorChanges.push(entry);
} else if (isMinor) {
minorChanges.push(entry);
} else {
patchChanges.push(entry);
// @swc/core changes go to core changelog
for (const match of frontmatter.matchAll(
/['"]@swc\/core['"]:\s*(major|minor|patch)/g
)) {
const changeType = match[1];
const entry = `${cleanDescription}\n\n`;

if (changeType === 'major') {
coreMajorChanges.push(entry);
} else if (changeType === 'minor') {
coreMinorChanges.push(entry);
} else {
corePatchChanges.push(entry);
}
}
}
}

// Parse version into number array for potential version calculations
return {
firstGen: { majorChanges, minorChanges, patchChanges },
core: {
majorChanges: coreMajorChanges,
minorChanges: coreMinorChanges,
patchChanges: corePatchChanges,
},
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel this is a little noisy since you are repeating nearly identical parsing logic for @spectrum-web-components/* and @swc/core.
This is not a blocker but just a suggestion. I just abstracted the parsing logic into a helper extractChanges just to reduce the cognitive load.

function extractChanges(frontmatter, description, pattern, prefix = '') {
    const changes = { major: [], minor: [], patch: [] };
    for (const match of frontmatter.matchAll(pattern)) {
        const [, name, type] = match;
        const entry = prefix
            ? `**${prefix}${name}**: ${description.trim()}\n\n`
            : `${description.trim()}\n\n`;
        changes[type].push(entry);
    }
    return changes;
}

async function processChangesets() {
    const changesetDir = path.resolve(__dirname, '../../.changeset');

    // 💡 Use non-blocking I/O for directory read
    const files = await fsPromises.readdir(changesetDir);
    const markdownFiles = files.filter(
        (f) => f.endsWith('.md') && f !== 'README.md'
    );

    // 💡 Read all files concurrently
    const fileContents = await Promise.all(
        markdownFiles.map((file) =>
            fsPromises.readFile(path.join(changesetDir, file), 'utf8')
        )
    );

    // Prepare change containers
    const firstGen = { majorChanges: [], minorChanges: [], patchChanges: [] };
    const core = { majorChanges: [], minorChanges: [], patchChanges: [] };

    for (const content of fileContents) {
        const frontmatterMatch = content.match(/---\n([\s\S]*?)\n---\n([\s\S]*)/);
        if (!frontmatterMatch) continue;

        const [, frontmatter, description] = frontmatterMatch;
        const cleanDescription = description.trim();

        // 💡 Extract first-gen (@spectrum-web-components/*) changes
        const swcChanges = extractChanges(
            frontmatter,
            cleanDescription,
            /['"]@spectrum-web-components\/([^'"]+)['"]:\s*(major|minor|patch)/g,
            'sp-'
        );

        // 💡 Extract @swc/core changes
        const coreChanges = extractChanges(
            frontmatter,
            cleanDescription,
            /['"]@swc\/core['"]:\s*(major|minor|patch)/g
        );

        // 💡 Merge results into categorized buckets
        firstGen.majorChanges.push(...swcChanges.major);
        firstGen.minorChanges.push(...swcChanges.minor);
        firstGen.patchChanges.push(...swcChanges.patch);

        core.majorChanges.push(...coreChanges.major);
        core.minorChanges.push(...coreChanges.minor);
        core.patchChanges.push(...coreChanges.patch);
    }

    return { firstGen, core };
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link
Contributor

@Rajdeepc Rajdeepc left a comment

Choose a reason for hiding this comment

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

Thanks for doing all the changes. Looks solid.

@rubencarvalho rubencarvalho merged commit 5e35222 into barebones Oct 27, 2025
22 checks passed
@rubencarvalho rubencarvalho deleted the changelog-changeset-barebones branch October 27, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2nd gen These issues or PRs map to our 2nd generation work to modernizing infrastructure. High Priority PR Review PR is a high priority and should be reviewed ASAP Status: Ready for review PR ready for review or re-review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants