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

add make-generate to pre-commit #491

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

klinch0
Copy link
Contributor

@klinch0 klinch0 commented Dec 2, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new pre-commit hook (run-make-generate) to automate the generation process in application directories.
  • Documentation

    • Enhanced readability of the Managed NATS Service README by adjusting formatting and removing unnecessary headers.
  • Bug Fixes

    • Corrected JSON structure in the Postgres values schema to ensure validity.
  • Chores

    • Updated pre-commit configuration for improved consistency and functionality.
    • Reorganized properties in the NATS values schema, removing the users property to reflect changes in user management capabilities.

@klinch0 klinch0 requested a review from kvaps as a code owner December 2, 2024 16:09
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 2, 2024
Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

This pull request introduces modifications to the GitHub Actions workflow and pre-commit configuration files. A new step is added to the pre-commit workflow to install a tool called "generate," which involves setting up Node.js, cloning a repository, and compiling a binary. Additionally, a new pre-commit hook is introduced to run a make generate command across application directories. Documentation files are updated for clarity, and changes to JSON schema files reflect a reorganization of properties and the removal of user-related configurations.

Changes

File Path Change Summary
.github/workflows/pre-commit.yml Added a step to install the "generate" tool, including commands for setting up Node.js and cloning a repository.
.pre-commit-config.yaml Introduced a new hook run-make-generate and adjusted indentation for existing hooks.
packages/apps/nats/README.md Modified formatting and structure of the README, removing a header and adjusting table alignment.
packages/apps/nats/values.schema.json Reorganized properties, removed users, and ensured consistent indentation.
packages/apps/postgres/values.schema.json Added a closing brace to complete the JSON structure, ensuring validity.

Possibly related PRs

  • add precommit and fix postgres job #418: The main PR introduces a new pre-commit hook and modifies the .pre-commit-config.yaml file, which is directly related to the changes made in this PR.
  • fix exclude for templates #434: This PR also modifies the .pre-commit-config.yaml file, updating pre-commit hooks, which aligns with the changes made in this PR.
  • revert-precommit #476: This PR involves the removal of several hooks from the .pre-commit-config.yaml, which is relevant to the focus on pre-commit configurations in this PR.

Suggested labels

size:S, lgtm

Suggested reviewers

  • kvaps
  • themoriarti

Poem

🐇 In the garden where code does grow,
New hooks and tools make our workflow glow.
With README's bright and schemas neat,
Our project’s journey is now more sweet!
So hop along, let’s celebrate,
With every change, we elevate! 🌼


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

@dosubot dosubot bot added the documentation Improvements or additions to documentation label Dec 2, 2024
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: 3

🧹 Outside diff range and nitpick comments (1)
.github/workflows/pre-commit.yml (1)

Line range hint 33-47: Consider optimizing pre-commit hook execution

The current implementation runs hooks on all YAML and Markdown files when base commit is not found. This could be inefficient for large repositories.

Consider this optimization:

       - name: Run pre-commit hooks
         run: |
           git fetch origin main || git fetch origin master
-          base_commit=$(git rev-parse --verify origin/main || git rev-parse --verify origin/master || echo "")
+          base_commit=$(git merge-base HEAD origin/main 2>/dev/null || git merge-base HEAD origin/master 2>/dev/null || echo "")
 
           if [ -z "$base_commit" ]; then
-            files=$(git ls-files '*.yaml' '*.md')
+            # Only check files in the current commit
+            files=$(git diff-index --cached --name-only HEAD | grep -E '\.(yaml|md)$')
           else
             files=$(git diff --name-only "$base_commit" -- '*.yaml' '*.md')
           fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between df448b9 and 248d578.

📒 Files selected for processing (5)
  • .github/workflows/pre-commit.yml (1 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • packages/apps/nats/README.md (1 hunks)
  • packages/apps/nats/values.schema.json (1 hunks)
  • packages/apps/postgres/values.schema.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/apps/postgres/values.schema.json
  • packages/apps/nats/README.md

Comment on lines +5 to +19
"external": {
"type": "boolean",
"description": "Enable external access from outside the cluster",
"default": false
},
"default": {}
}
"replicas": {
"type": "number",
"description": "Persistent Volume size for NATS",
"default": 2
},
"storageClass": {
"type": "string",
"description": "StorageClass used to store the data",
"default": ""
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Removal of users property from schema conflicts with active usage

The users property is actively used in both values.yaml (as a default empty configuration) and templates/nats.yaml (for generating credentials and NATS configuration). Removing it from the schema while keeping the functionality in the templates would lead to:

  • Undocumented but required configuration option
  • Potential breaking changes for existing deployments using user authentication
  • Schema validation errors for valid configurations

Locations needing attention:

  • values.schema.json: Keep the users property in the schema
  • If removal is intended, corresponding changes are needed in:
    • values.yaml: Remove the users configuration
    • templates/nats.yaml: Remove the user authentication logic
🔗 Analysis chain

Schema structure looks good but verify impact of users removal

The schema properties are well-structured with clear descriptions and appropriate types. However, the removal of the users property might impact existing configurations.

Let's verify the impact of removing the users configuration:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any references to NATS users configuration
rg -l "users:" ./packages/apps/nats/

Length of output: 110


Script:

#!/bin/bash
# Check the content of values.yaml and templates/nats.yaml to understand the usage of users configuration
echo "=== values.yaml ==="
cat ./packages/apps/nats/values.yaml

echo -e "\n=== templates/nats.yaml ==="
cat ./packages/apps/nats/templates/nats.yaml

Length of output: 2449

Comment on lines +11 to +23
- id: run-make-generate
name: Run 'make generate' in all app directories
entry: |
/bin/bash -c '
for dir in ./packages/apps/*/; do
if [ -d "$dir" ]; then
echo "Running make generate in $dir"
(cd "$dir" && make generate)
fi
done
'
language: script
files: ^.*$
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling and documentation for make-generate hook

The new hook implementation has several areas for improvement:

  1. No error handling for make generate failures
  2. Runs on all files (^.*$) which might impact performance
  3. Missing documentation about what 'make generate' does

Consider this improved implementation:

     - id: run-make-generate
       name: Run 'make generate' in all app directories
       entry: |
         /bin/bash -c '
+          set -e  # Exit on any error
+          if ! command -v make >/dev/null 2>&1; then
+            echo "Error: make is not installed"
+            exit 1
+          fi
           for dir in ./packages/apps/*/; do
             if [ -d "$dir" ]; then
               echo "Running make generate in $dir"
-              (cd "$dir" && make generate)
+              (cd "$dir" && make generate) || {
+                echo "Error: make generate failed in $dir"
+                exit 1
+              }
             fi
           done
         '
       language: script
-      files: ^.*$
+      files: ^packages/apps/.*$

Also, please add documentation about what 'make generate' does and its purpose.

📝 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
- id: run-make-generate
name: Run 'make generate' in all app directories
entry: |
/bin/bash -c '
for dir in ./packages/apps/*/; do
if [ -d "$dir" ]; then
echo "Running make generate in $dir"
(cd "$dir" && make generate)
fi
done
'
language: script
files: ^.*$
- id: run-make-generate
name: Run 'make generate' in all app directories
entry: |
/bin/bash -c '
set -e # Exit on any error
if ! command -v make >/dev/null 2>&1; then
echo "Error: make is not installed"
exit 1
fi
for dir in ./packages/apps/*/; do
if [ -d "$dir" ]; then
echo "Running make generate in $dir"
(cd "$dir" && make generate) || {
echo "Error: make generate failed in $dir"
exit 1
}
fi
done
'
language: script
files: ^packages/apps/.*$

Comment on lines +20 to +30
- name: Install generate
run: |
sudo apt update
sudo apt install curl -y
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install nodejs -y
git clone https://github.com/bitnami/readme-generator-for-helm
cd ./readme-generator-for-helm
npm install
npm install -g pkg
pkg . -o /usr/local/bin/readme-generator
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security and stability improvements needed for generate tool installation

Several concerns with the current implementation:

  1. Using Node.js 16 which is approaching EOL
  2. No version pinning for the external repository
  3. Direct sudo usage in GitHub Actions
  4. No verification of downloaded content

Consider these improvements:

       - name: Install generate
         run: |
-          sudo apt update
-          sudo apt install curl -y
-          curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
-          sudo apt install nodejs -y
-          git clone https://github.com/bitnami/readme-generator-for-helm
+          sudo apt-get update
+          sudo apt-get install -y curl
+          curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
+          sudo apt-get install -y nodejs
+          # Clone specific version and verify
+          git clone --depth 1 --branch v1.0.0 https://github.com/bitnami/readme-generator-for-helm
           cd ./readme-generator-for-helm
+          # Verify repository content
+          git verify-commit HEAD || echo "Warning: Commit signature verification failed"
           npm install
           npm install -g pkg
           pkg . -o /usr/local/bin/readme-generator

Also consider:

  1. Using GitHub's official Node.js setup action instead of manual installation
  2. Caching npm dependencies
  3. Adding SHA256 verification for downloaded content

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

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 2, 2024
@kvaps kvaps merged commit f73a5a0 into aenix-io:main Dec 2, 2024
1 check passed
klinch0 added a commit to klinch0/cozystack that referenced this pull request Dec 5, 2024
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

- **New Features**
- Introduced a new pre-commit hook (`run-make-generate`) to automate the
generation process in application directories.

- **Documentation**
- Enhanced readability of the Managed NATS Service README by adjusting
formatting and removing unnecessary headers.

- **Bug Fixes**
- Corrected JSON structure in the Postgres values schema to ensure
validity.

- **Chores**
- Updated pre-commit configuration for improved consistency and
functionality.
- Reorganized properties in the NATS values schema, removing the `users`
property to reflect changes in user management capabilities.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants