Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Jan 29, 2025

The script simplifies the update of the version in various files by running a single command, instead of modifying several files manually.

In addition, lint packages/core/package.json to not introduce changes when the file is updated by the script.

Notes

Script logs

$ node scripts/update-versions.mjs 0.16.1
Updating version in various files, version: 0.16.1
Updating package-lock.json
Updating packages/core/package.json
Updating packages/core/src/Client.ts
Files have been updated

Summary by CodeRabbit

  • Chores

    • Introduced an automated script for updating package versions across multiple files
    • Simplified version update process during release preparation
    • Reformatted package configuration for better readability
  • Documentation

    • Updated release documentation with new version update instructions
    • Added comments in source files to guide version management

The script simplifies the update of the version in various files by running a single command, instead of modifying
several files manually.

In addition, lint `packages/core/package.json` to not introduce changes when the file is updated by the script.
@tbouffard tbouffard added the chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...) label Jan 29, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

This pull request introduces a new script update-versions.mjs to automate the version update process across multiple project files. The changes simplify the release workflow by replacing manual version updates with a single command-line script. The script can update versions in package-lock.json, packages/core/package.json, and packages/core/src/Client.ts, reducing the potential for human error during release preparation.

Changes

File Change Summary
packages/core/package.json Reformatted sideEffects property to use multi-line array syntax
packages/core/src/Client.ts Added comments about VERSION constant update process
packages/website/docs/development/release.md Updated release instructions to use new version update script
scripts/update-versions.mjs New script to automate version updates across project files

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant Script as update-versions.mjs
    participant Files as Project Files

    Dev->>Script: Run script with new version
    Script->>Files: Update package-lock.json
    Script->>Files: Update core package.json
    Script->>Files: Update Client.ts version constant
    Script-->>Dev: Confirm version updates complete
Loading

Possibly related PRs

Suggested labels

documentation


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
scripts/update-versions.mjs (2)

60-62: Consider removing redundant utility function.

The readFileContent function adds unnecessary abstraction. Consider inlining it within the try-catch blocks where it's used.

-function readFileContent(path) {
-  return readFileSync(path, 'utf8').toString();
-}

64-66: Add error handling to JSON writing utility.

The function should handle potential JSON stringification errors.

 function writeJsonContentToFile(path, obj) {
-  writeFileSync(path, JSON.stringify(obj, null, 2) + '\n');
+  try {
+    const content = JSON.stringify(obj, null, 2) + '\n';
+    writeFileSync(path, content);
+  } catch (error) {
+    console.error(`Failed to write to ${path}:`, error.message);
+    process.exit(1);
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3cc82f and 82844a2.

📒 Files selected for processing (4)
  • packages/core/package.json (1 hunks)
  • packages/core/src/Client.ts (1 hunks)
  • packages/website/docs/development/release.md (1 hunks)
  • scripts/update-versions.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/core/src/Client.ts
  • packages/core/package.json
🧰 Additional context used
🪛 ESLint
scripts/update-versions.mjs

[error] 22-22: 'process' is not defined.

(no-undef)


[error] 24-24: Unexpected console statement.

(no-console)


[error] 28-28: Unexpected console statement.

(no-console)


[error] 32-32: Unexpected console statement.

(no-console)


[error] 41-41: Unexpected console statement.

(no-console)


[error] 50-50: Unexpected console statement.

(no-console)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build
  • GitHub Check: build (macos-14)
  • GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (2)
scripts/update-versions.mjs (1)

1-19: LGTM! Good practices in imports and documentation.

The use of the node: protocol for importing core modules and the clear documentation about workflow dependencies are excellent practices.

packages/website/docs/development/release.md (1)

38-38: LGTM! Clear documentation update.

The new instruction for using the version update script is well-integrated into the release process documentation.

Comment on lines +39 to +46
function updateVersionInCorePackageJsonFile(newVersion) {
const path = 'packages/core/package.json';
console.info('Updating', path);
const fileContent = readFileContent(path);
const packageJson = JSON.parse(fileContent);
packageJson.version = newVersion;
writeJsonContentToFile(path, packageJson);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for core package.json operations.

Similar to the previous function, add error handling and file validation.

Consider this implementation:

 function updateVersionInCorePackageJsonFile(newVersion) {
   const path = 'packages/core/package.json';
   console.info('Updating', path);
-  const fileContent = readFileContent(path);
-  const packageJson = JSON.parse(fileContent);
-  packageJson.version = newVersion;
-  writeJsonContentToFile(path, packageJson);
+  try {
+    const fileContent = readFileContent(path);
+    const packageJson = JSON.parse(fileContent);
+    packageJson.version = newVersion;
+    writeJsonContentToFile(path, packageJson);
+  } catch (error) {
+    console.error(`Failed to update ${path}:`, error.message);
+    process.exit(1);
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function updateVersionInCorePackageJsonFile(newVersion) {
const path = 'packages/core/package.json';
console.info('Updating', path);
const fileContent = readFileContent(path);
const packageJson = JSON.parse(fileContent);
packageJson.version = newVersion;
writeJsonContentToFile(path, packageJson);
}
function updateVersionInCorePackageJsonFile(newVersion) {
const path = 'packages/core/package.json';
console.info('Updating', path);
try {
const fileContent = readFileContent(path);
const packageJson = JSON.parse(fileContent);
packageJson.version = newVersion;
writeJsonContentToFile(path, packageJson);
} catch (error) {
console.error(`Failed to update ${path}:`, error.message);
process.exit(1);
}
}
🧰 Tools
🪛 ESLint

[error] 41-41: Unexpected console statement.

(no-console)

Comment on lines +21 to +28
// run from the root of the repository: node scripts/update-versions.mjs 0.12.0.alpha-1
const newVersion = process.argv[2];

console.info('Updating version in various files, version:', newVersion);
updateVersionInRootPackageLockJsonFile(newVersion);
updateVersionInCorePackageJsonFile(newVersion);
updateVersionInSourceFile(newVersion);
console.info('Files have been updated');
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add version format validation.

The script should validate the version format and handle missing arguments gracefully.

Consider adding this validation:

 const newVersion = process.argv[2];
+if (!newVersion) {
+  console.error('Error: Version argument is required');
+  console.error('Usage: node scripts/update-versions.mjs <version>');
+  process.exit(1);
+}
+if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/.test(newVersion)) {
+  console.error('Error: Invalid version format. Must follow semver (e.g., 1.2.3, 1.2.3-alpha.1)');
+  process.exit(1);
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// run from the root of the repository: node scripts/update-versions.mjs 0.12.0.alpha-1
const newVersion = process.argv[2];
console.info('Updating version in various files, version:', newVersion);
updateVersionInRootPackageLockJsonFile(newVersion);
updateVersionInCorePackageJsonFile(newVersion);
updateVersionInSourceFile(newVersion);
console.info('Files have been updated');
// run from the root of the repository: node scripts/update-versions.mjs 0.12.0.alpha-1
const newVersion = process.argv[2];
if (!newVersion) {
console.error('Error: Version argument is required');
console.error('Usage: node scripts/update-versions.mjs <version>');
process.exit(1);
}
if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/.test(newVersion)) {
console.error('Error: Invalid version format. Must follow semver (e.g., 1.2.3, 1.2.3-alpha.1)');
process.exit(1);
}
console.info('Updating version in various files, version:', newVersion);
updateVersionInRootPackageLockJsonFile(newVersion);
updateVersionInCorePackageJsonFile(newVersion);
updateVersionInSourceFile(newVersion);
console.info('Files have been updated');
🧰 Tools
🪛 ESLint

[error] 22-22: 'process' is not defined.

(no-undef)


[error] 24-24: Unexpected console statement.

(no-console)


[error] 28-28: Unexpected console statement.

(no-console)

Comment on lines +30 to +37
function updateVersionInRootPackageLockJsonFile(newVersion) {
const path = 'package-lock.json';
console.info('Updating', path);
const fileContent = readFileContent(path);
const packageJson = JSON.parse(fileContent);
packageJson.packages['packages/core'].version = newVersion;
writeJsonContentToFile(path, packageJson);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for file operations and package structure validation.

The function should handle file operation errors and validate the package-lock.json structure.

Consider this implementation:

 function updateVersionInRootPackageLockJsonFile(newVersion) {
   const path = 'package-lock.json';
   console.info('Updating', path);
-  const fileContent = readFileContent(path);
-  const packageJson = JSON.parse(fileContent);
-  packageJson.packages['packages/core'].version = newVersion;
-  writeJsonContentToFile(path, packageJson);
+  try {
+    const fileContent = readFileContent(path);
+    const packageJson = JSON.parse(fileContent);
+    if (!packageJson.packages?.['packages/core']) {
+      throw new Error('packages/core not found in package-lock.json');
+    }
+    packageJson.packages['packages/core'].version = newVersion;
+    writeJsonContentToFile(path, packageJson);
+  } catch (error) {
+    console.error(`Failed to update ${path}:`, error.message);
+    process.exit(1);
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function updateVersionInRootPackageLockJsonFile(newVersion) {
const path = 'package-lock.json';
console.info('Updating', path);
const fileContent = readFileContent(path);
const packageJson = JSON.parse(fileContent);
packageJson.packages['packages/core'].version = newVersion;
writeJsonContentToFile(path, packageJson);
}
function updateVersionInRootPackageLockJsonFile(newVersion) {
const path = 'package-lock.json';
console.info('Updating', path);
try {
const fileContent = readFileContent(path);
const packageJson = JSON.parse(fileContent);
if (!packageJson.packages?.['packages/core']) {
throw new Error('packages/core not found in package-lock.json');
}
packageJson.packages['packages/core'].version = newVersion;
writeJsonContentToFile(path, packageJson);
} catch (error) {
console.error(`Failed to update ${path}:`, error.message);
process.exit(1);
}
}
🧰 Tools
🪛 ESLint

[error] 32-32: Unexpected console statement.

(no-console)

Comment on lines +48 to +58
function updateVersionInSourceFile(newVersion) {
const path = 'packages/core/src/Client.ts';
console.info('Updating', path);
const content = readFileContent(path);
// replace the 1st occurrence, this is OK as the constant appears only once in the file
const updatedContent = content.replace(
/static VERSION =.*/,
`static VERSION = '${newVersion}';`
);
writeFileSync(path, updatedContent);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve version replacement reliability in source file.

The current implementation could be more robust with better error handling and replacement verification.

Consider this enhanced implementation:

 function updateVersionInSourceFile(newVersion) {
   const path = 'packages/core/src/Client.ts';
   console.info('Updating', path);
-  const content = readFileContent(path);
-  // replace the 1st occurrence, this is OK as the constant appears only once in the file
-  const updatedContent = content.replace(
-    /static VERSION =.*/,
-    `static VERSION = '${newVersion}';`
-  );
-  writeFileSync(path, updatedContent);
+  try {
+    const content = readFileContent(path);
+    const versionRegex = /static\s+VERSION\s*=\s*['"]([^'"]+)['"]\s*;/;
+    if (!versionRegex.test(content)) {
+      throw new Error('VERSION constant not found in expected format');
+    }
+    const updatedContent = content.replace(
+      versionRegex,
+      `static VERSION = '${newVersion}';`
+    );
+    if (content === updatedContent) {
+      throw new Error('Failed to update version in file');
+    }
+    writeFileSync(path, updatedContent);
+  } catch (error) {
+    console.error(`Failed to update ${path}:`, error.message);
+    process.exit(1);
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function updateVersionInSourceFile(newVersion) {
const path = 'packages/core/src/Client.ts';
console.info('Updating', path);
const content = readFileContent(path);
// replace the 1st occurrence, this is OK as the constant appears only once in the file
const updatedContent = content.replace(
/static VERSION =.*/,
`static VERSION = '${newVersion}';`
);
writeFileSync(path, updatedContent);
}
function updateVersionInSourceFile(newVersion) {
const path = 'packages/core/src/Client.ts';
console.info('Updating', path);
try {
const content = readFileContent(path);
const versionRegex = /static\s+VERSION\s*=\s*['"]([^'"]+)['"]\s*;/;
if (!versionRegex.test(content)) {
throw new Error('VERSION constant not found in expected format');
}
const updatedContent = content.replace(
versionRegex,
`static VERSION = '${newVersion}';`
);
if (content === updatedContent) {
throw new Error('Failed to update version in file');
}
writeFileSync(path, updatedContent);
} catch (error) {
console.error(`Failed to update ${path}:`, error.message);
process.exit(1);
}
}
🧰 Tools
🪛 ESLint

[error] 50-50: Unexpected console statement.

(no-console)

@tbouffard tbouffard merged commit f11ccf2 into main Jan 29, 2025
7 checks passed
@tbouffard tbouffard deleted the chore/add_scripts_to_help_release branch January 29, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant