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

Improve setup.sh script with better error handling and user feedback #6758

Open
wants to merge 1 commit into
base: preview
Choose a base branch
from

Conversation

biaoma-ty
Copy link

@biaoma-ty biaoma-ty commented Mar 17, 2025

Description

This PR enhances the setup.sh script to provide better feedback during the environment setup process. The current script runs silently without any output, making it difficult for new contributors to know if the setup completed successfully or troubleshoot any issues that might occur. The improved script includes color-coded output messages, proper error handling, and verification of all created environment files to make the onboarding process smoother.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Effects

Before:

$ ./setup.sh
$

After:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                   Plane - Project Management Tool                    
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Setting up your development environment...

Setting up environment files...
✓ Copied ./.env
✓ Copied ./web/.env
✓ Copied ./apiserver/.env
✓ Copied ./space/.env
✓ Copied ./admin/.env
✓ Copied ./live/.env

Generating Django SECRET_KEY...
✓ Added SECRET_KEY to apiserver/.env

Setup status:
✓ Environment setup completed successfully!

Next steps:
1. Review the .env files in each folder if needed
2. Start the services with: docker compose -f docker-compose-local.yml up -d

Happy coding! 🚀

Test Scenarios

  • Tested on Ubuntu 22.04 to ensure the script works correctly on Linux
  • Tested on macOS to verify compatibility with the character encoding settings
  • Tested in Windows WSL2 (Ubuntu) to ensure broad compatibility

References

Fixes #[6757]

@CLAassistant
Copy link

CLAassistant commented Mar 17, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented Mar 17, 2025

Walkthrough

The setup.sh script has been updated to enhance robustness and user feedback. A new function, copy_env_file, now handles file copying with error checking. The script introduces color-coded messages and a header for improved readability. It replaces hardcoded copying commands with a loop over service names, streamlining the process. Additionally, a section to generate a Django SECRET_KEY has been added, complete with error handling and a summary of the setup outcome.

Changes

File(s) Change Summary
setup.sh - Added copy_env_file(source, destination) for error-checked file copying.
- Introduced color-coded output messages and a header message.
- Replaced hardcoded file copy commands with a loop over service names.
- Implemented Django SECRET_KEY generation with error handling.
- Added a summary section with next steps.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant U as User
    participant S as setup.sh
    participant FS as File System

    U->>S: Execute setup.sh
    S->>S: Print header with color-coded messages
    S->>FS: For each service, check if env file exists
    FS-->>S: Return file exists or error
    S->>S: Call copy_env_file() for file copying
    S->>FS: Attempt copying file with verification
    S->>S: Generate Django SECRET_KEY (if needed)
    S->>U: Display setup summary and next steps

Poem

I'm a bunny with a hop in my code,
Skipping along where new functions rode.
Colorful messages light up my day,
Looping through services in a clever way.
A secret key sprouts with a gentle cheer,
Hopping to success with each script endear!
🐇💻 Happy coding, my friend!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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
Contributor

@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: 0

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

59-75: Django SECRET_KEY Generation with Enhanced Error Handling
The SECRET_KEY generation using /dev/urandom, tr, and head is effective and includes proper error handling with detailed messages.
A good-to-have improvement would be to ensure idempotency—if the script is re-run, appending a new SECRET_KEY might lead to duplicate entries in apiserver/.env. Consider checking whether a SECRET_KEY already exists before appending it. For example:

-        echo -e "SECRET_KEY=\"$SECRET_KEY\"" >> ./apiserver/.env
-        echo -e "${GREEN}✓${NC} Added SECRET_KEY to apiserver/.env"
+        if grep -q "^SECRET_KEY=" ./apiserver/.env; then
+            echo -e "${YELLOW}SECRET_KEY already exists in ./apiserver/.env, skipping generation.${NC}"
+        else
+            echo -e "SECRET_KEY=\"$SECRET_KEY\"" >> ./apiserver/.env
+            echo -e "${GREEN}✓${NC} Added SECRET_KEY to apiserver/.env"
+        fi
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d14c9d and ac59b77.

📒 Files selected for processing (1)
  • setup.sh (1 hunks)
🔇 Additional comments (6)
setup.sh (6)

3-6: Informative Header & Script Introduction
The introductory comments clearly explain the purpose of the script and reference the project repository. This provides good context for contributors.


7-13: Well-defined Output Colors
The definition of color variables (GREEN, BLUE, YELLOW, RED, BOLD, NC) is clear and helps in producing a friendly, color-coded CLI output for user feedback.


15-19: Clear & Aesthetic Header Printing
The header printed with bold and blue colors uses visual separators effectively. It enhances readability and provides a welcoming introduction to the setup process.


21-39: Robust File Copy Functionality
The copy_env_file function is well encapsulated with proper error checking. It verifies the source file’s presence and provides clear, color-coded feedback for both success and failure cases.
Consider capturing the exit code of the cp command in a variable for slightly improved clarity, though checking $? immediately is acceptable.


41-57: Environment Configuration & Scalable File Copy Loop
Exporting locale settings (LC_ALL, LC_CTYPE) aids macOS compatibility, and the echo message sets an appropriate context.
The loop over the services array for copying .env.example files is scalable and avoids code duplication. The use of an empty string in the array to handle the root directory is a neat trick.


77-89: Comprehensive Setup Summary and Guidance
The summary section effectively communicates the overall setup status and next steps for the user. It smartly uses conditionals to display success messages and exits with an error code if issues occurred. This clear guidance enhances the user experience.

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.

2 participants