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

Configured Gitpod workspace to start with node version 22 #616

Closed

Conversation

Kamlesh72
Copy link
Contributor

@Kamlesh72 Kamlesh72 commented Oct 28, 2024

Linked Issue(s)

Fixes #612

Summary by CodeRabbit

  • Chores
    • Enhanced local setup script with improved package management checks
    • Added support for detecting and installing yarn across different operating systems
    • Integrated nvm script sourcing to ensure proper Node.js version management

@jayantbh
Copy link
Contributor

Instead of this, how about just invoking the ./local-setup.sh script with the -y flag?
That takes care of setting up everything that might be needed, including node.

@Kamlesh72
Copy link
Contributor Author

Ah, missed on many new updates. Will have a look into that.
Arigatou.

@Kamlesh72
Copy link
Contributor Author

@jayantbh After executing ./local-setup.sh the node version of current terminal is still previous one. Is this expected behavior?

Screenshot 2024-10-30 at 5 00 54 PM

@jayantbh
Copy link
Contributor

No that's certainly not intended. I guess the script is missing an nvm use

Copy link

coderabbitai bot commented Jan 28, 2025

Walkthrough

The local-setup.sh script has been enhanced with improved package management setup. New checks have been implemented to verify the installation of yarn and nvm, with system-specific installation instructions for yarn. The script now provides more robust detection and setup for JavaScript development tools, ensuring developers can easily configure their local environment across different operating systems.

Changes

File Change Summary
local-setup.sh Added checks for yarn installation with OS-specific installation methods, integrated nvm script sourcing

Assessment against linked issues

Objective Addressed Explanation
Set Node.js version 22 as default [#612] Script modifications do not explicitly set Node 22 as default

Poem

🐰 In the realm of scripts so neat,
Yarn and NVM now dance and meet
Local setup with rabbit's care
Dependencies installed with flair
A development environment prepared! 🚀


🪧 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.

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: 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 c1e8b44 and 11163d5.

📒 Files selected for processing (1)
  • .gitpod.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: All file linting
🔇 Additional comments (2)
.gitpod.yml (2)

1-3: LGTM! Good choice using the before task.

Using a before task ensures Node.js is installed before the workspace starts, which is the correct approach for environment setup.


3-3: Verify integration with existing setup scripts.

Based on the PR comments, there might be overlap between this configuration and ./local-setup.sh. Let's verify the script contents to avoid duplicate Node.js setup.

✅ Verification successful

Scripts serve different purposes - no integration issues found

The scripts are complementary:

  • local-setup.sh handles one-time development environment setup
  • dev.sh performs runtime version validation and CLI execution
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the contents of both scripts
echo "=== dev.sh contents ==="
cat ./dev.sh
echo -e "\n=== local-setup.sh contents ==="
cat ./local-setup.sh

Length of output: 8889

.gitpod.yml Outdated
tasks:
- init: |
- before: nvm install 22
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 nvm use and consider using LTS version.

The current setup has a few potential issues:

  1. nvm install alone doesn't automatically use the installed version
  2. Node.js 22 is not yet an LTS version and might be unstable

Consider this improved configuration:

- before: nvm install 22
+ before: |
+   nvm install --lts
+   nvm use --lts
+   nvm alias default "$(nvm current)"

This change:

  • Uses the latest LTS version for stability
  • Ensures the version persists across terminal sessions
  • Sets the LTS version as default
📝 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
- before: nvm install 22
- before: |
nvm install --lts
nvm use --lts
nvm alias default "$(nvm current)"

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: 2

🧹 Nitpick comments (1)
local-setup.sh (1)

Line range hint 1-142: Consider broader improvements to the setup script.

While the changes improve the setup process, consider these additional enhancements:

  1. Add a cleanup function for failed installations
  2. Document minimum system requirements
  3. Add version checks for system-wide packages
  4. Consider using a container-based setup for consistency

Would you like me to provide an example implementation of these improvements?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11163d5 and 4d4f827.

📒 Files selected for processing (1)
  • local-setup.sh (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: All file linting
🔇 Additional comments (1)
local-setup.sh (1)

19-19: LGTM! Setup message updated correctly.

The added message about yarn check maintains consistency with the existing format and accurately reflects the new functionality.

Comment on lines +36 to +39
# Source nvm if already installed in system
if [ -f "$HOME/.nvm/nvm.sh" ]; then
source ~/.nvm/nvm.sh
fi
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance shell persistence for nvm.

While sourcing nvm is correct, it doesn't ensure the Node version persists in the user's shell after script completion. This explains the reported issue where the Node version remains unchanged after running the script.

Consider adding these improvements:

 if [ -f "$HOME/.nvm/nvm.sh" ]; then
     source ~/.nvm/nvm.sh
+    # Add to shell rc file if not already present
+    if ! grep -q "source ~/.nvm/nvm.sh" ~/.bashrc; then
+        echo "source ~/.nvm/nvm.sh" >> ~/.bashrc
+    fi
+    if ! grep -q "nvm use 22" ~/.bashrc; then
+        echo "nvm use 22" >> ~/.bashrc
+    fi
 fi

Also, add a note to inform users they need to restart their shell:

+echo -e "${YELLOW}Note: Please restart your terminal or run 'source ~/.bashrc' for the Node.js version changes to take effect.${NC}"

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +118 to +141
# Install yarn if not installed
if ! command -v yarn &> /dev/null; then
echo -e "${YELLOW}Yarn is not installed. Installing Yarn...${NC}"

# If it's a Linux system
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Check if 'curl' is available and install Yarn on Ubuntu/Debian
if command -v curl &> /dev/null; then
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
else
echo -e "${RED}'curl' is not installed. Please install curl or download Yarn manually.${NC}"
exit 1
fi
# If it's a macOS system, install using Homebrew
elif command -v brew &> /dev/null; then
brew install yarn
else
echo -e "${RED}No suitable installation method found. Please install Yarn manually.${NC}"
fi
else
echo -e "${GREEN}Yarn is already installed.${NC}"
fi
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Address security and reliability concerns in yarn installation.

Several issues need attention in the yarn installation block:

  1. The apt-key command is deprecated and should be replaced with keyring files
  2. Direct piping of curl to sudo poses security risks
  3. Missing error handling for failed installations
  4. No version pinning for yarn

Consider these improvements:

 if ! command -v yarn &> /dev/null; then
     echo -e "${YELLOW}Yarn is not installed. Installing Yarn...${NC}"
 
     # If it's a Linux system
     if [[ "$OSTYPE" == "linux-gnu"* ]]; then
         # Check if 'curl' is available and install Yarn on Ubuntu/Debian
         if command -v curl &> /dev/null; then
-            curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
-            echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
-            sudo apt update && sudo apt install yarn
+            # Download GPG key to keyring directory
+            curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg --output /tmp/yarn-pubkey.gpg
+            sudo mkdir -p /etc/apt/keyrings
+            sudo gpg --dearmor -o /etc/apt/keyrings/yarn.gpg /tmp/yarn-pubkey.gpg
+            rm /tmp/yarn-pubkey.gpg
+            
+            # Add repository
+            echo "deb [signed-by=/etc/apt/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" | \
+                sudo tee /etc/apt/sources.list.d/yarn.list
+            
+            # Install specific version
+            if ! sudo apt update && sudo apt install yarn=1.22.19-1; then
+                echo -e "${RED}Failed to install yarn. Please check your internet connection and try again.${NC}"
+                exit 1
+            fi
         else
             echo -e "${RED}'curl' is not installed. Please install curl or download Yarn manually.${NC}"
             exit 1
         fi
     # If it's a macOS system, install using Homebrew
     elif command -v brew &> /dev/null; then
-        brew install yarn
+        if ! brew install [email protected]; then
+            echo -e "${RED}Failed to install yarn. Please check your internet connection and try again.${NC}"
+            exit 1
+        fi
     else
         echo -e "${RED}No suitable installation method found. Please install Yarn manually.${NC}"
+        exit 1
     fi
 else
     echo -e "${GREEN}Yarn is already installed.${NC}"
 fi
📝 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
# Install yarn if not installed
if ! command -v yarn &> /dev/null; then
echo -e "${YELLOW}Yarn is not installed. Installing Yarn...${NC}"
# If it's a Linux system
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Check if 'curl' is available and install Yarn on Ubuntu/Debian
if command -v curl &> /dev/null; then
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
else
echo -e "${RED}'curl' is not installed. Please install curl or download Yarn manually.${NC}"
exit 1
fi
# If it's a macOS system, install using Homebrew
elif command -v brew &> /dev/null; then
brew install yarn
else
echo -e "${RED}No suitable installation method found. Please install Yarn manually.${NC}"
fi
else
echo -e "${GREEN}Yarn is already installed.${NC}"
fi
# Install yarn if not installed
if ! command -v yarn &> /dev/null; then
echo -e "${YELLOW}Yarn is not installed. Installing Yarn...${NC}"
# If it's a Linux system
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Check if 'curl' is available and install Yarn on Ubuntu/Debian
if command -v curl &> /dev/null; then
# Download GPG key to keyring directory
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg --output /tmp/yarn-pubkey.gpg
sudo mkdir -p /etc/apt/keyrings
sudo gpg --dearmor -o /etc/apt/keyrings/yarn.gpg /tmp/yarn-pubkey.gpg
rm /tmp/yarn-pubkey.gpg
# Add repository
echo "deb [signed-by=/etc/apt/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" | \
sudo tee /etc/apt/sources.list.d/yarn.list
# Install specific version
if ! sudo apt update && sudo apt install yarn=1.22.19-1; then
echo -e "${RED}Failed to install yarn. Please check your internet connection and try again.${NC}"
exit 1
fi
else
echo -e "${RED}'curl' is not installed. Please install curl or download Yarn manually.${NC}"
exit 1
fi
# If it's a macOS system, install using Homebrew
elif command -v brew &> /dev/null; then
if ! brew install [email protected]; then
echo -e "${RED}Failed to install yarn. Please check your internet connection and try again.${NC}"
exit 1
fi
else
echo -e "${RED}No suitable installation method found. Please install Yarn manually.${NC}"
exit 1
fi
else
echo -e "${GREEN}Yarn is already installed.${NC}"
fi

@Kamlesh72
Copy link
Contributor Author

Kamlesh72 commented Jan 28, 2025

Gitpod updated default node version to 22. Reference
So I think updating gitpod.yml file is not needed.

@adnanhashmi09
Copy link
Contributor

Gitpod updated default node version to 22. Reference So I think updating gitpod.yml file is not needed.

Hey Kamlesh! Thank you for letting us know about the gitpod node version update. I just tried it out and they do seem to have updated the default node version. So, I believe this PR is not required anymore.
Thank You 🚀

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.

Set Node.js version 22 as the default in Gitpod environment
3 participants