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

Gcp build npm #1272

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Gcp build npm #1272

wants to merge 21 commits into from

Conversation

Krishna-kommunicate
Copy link
Contributor

@Krishna-kommunicate Krishna-kommunicate commented Dec 17, 2024

What do you want to achieve?

  • made changes in cloudbuild to run successful build

PR Checklist

  • I have tested it locally and all functionalities are working fine.
  • I have compared it with mocks and all design elements are the same.
  • I have tested it in IE Browser.

How was the code tested?

What new thing you came across while writing this code?

In case you fixed a bug then please describe the root cause of it?

Screenshot

NOTE: Make sure you're comparing your branch with the correct base branch

Summary by CodeRabbit

  • Chores
    • Updated dependency installation and build steps for improved efficiency.
    • Enhanced clarity of comments in the build configuration.
    • Corrected project ID reference for Firebase deployment.

Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

The cloudbuild.yaml file has been updated to improve the build and deployment process. The changes primarily involve switching from gcr.io/cloud-builders/npm to node:20 image for dependency installation and build steps. The modifications enhance script clarity by refining comments and updating the Firebase deployment step to use a dynamic project ID. The core build logic remains consistent, with improvements focused on image selection and script readability.

Changes

File Change Summary
cloudbuild.yaml - Replaced npm builder image with node:20
- Updated dependency installation step to clean npm cache
- Refined build step comments
- Modified Firebase deployment to use dynamic project ID

Poem

🐰 In the realm of builds, a rabbit's delight,
Cloudbuild yaml, now shining bright!
Node:20 dancing, dependencies clean,
Firebase deployment, a smoother scene
Code builds faster, with clarity's might! 🚀


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.

Copy link

Warnings
⚠️ Please add the JIRA issue key to the PR title (e.g. FW-123)
Messages
📖 New Files in this PR: - 0

Generated by 🚫 dangerJS against 588d0c5

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

🔭 Outside diff range comments (3)
cloudbuild.yaml (3)

Line range hint 6-7: Fix the substitution syntax for _FIREBASE_SITE_ID

The current string interpolation syntax "${_BUILD_ENV}_site_id" might not work as expected in YAML substitutions. Cloud Build substitutions are performed before the YAML is parsed, so dynamic values should be handled in the steps where they're used.

Consider removing the interpolation and handling it in the relevant steps:

-  _FIREBASE_SITE_ID: "${_BUILD_ENV}_site_id"  # Placeholder for Firebase site ID
+  _FIREBASE_SITE_ID: "kommunicate_site_id"  # Define a static default value
🧰 Tools
🪛 yamllint (1.35.1)

[error] 25-25: trailing spaces

(trailing-spaces)


Line range hint 53-80: Enhance Firebase configuration validation

While the current validation checks for file existence, it should also validate the firebase.json structure and ensure the site ID update succeeds.

         echo "Updating firebase.json with site ID..."
+        if [ ! -f "firebase.json" ]; then
+          echo "Error: firebase.json file does not exist."
+          exit 1
+        fi
+        # Backup the original file
+        cp firebase.json firebase.json.bak
         # Update the site ID dynamically in firebase.json
-        sed -i 's/"site": ".*"/"site": "'"${_FIREBASE_SITE_ID}"'"/' firebase.json
+        if ! sed -i 's/"site": ".*"/"site": "'"${_FIREBASE_SITE_ID}"'"/' firebase.json; then
+          echo "Error: Failed to update site ID in firebase.json"
+          mv firebase.json.bak firebase.json
+          exit 1
+        fi
+        # Validate JSON structure
+        if ! jq empty firebase.json; then
+          echo "Error: Invalid JSON structure in firebase.json"
+          mv firebase.json.bak firebase.json
+          exit 1
+        fi
+        rm firebase.json.bak

Firebase deployment configuration needs updates

The verification revealed several configuration issues that need attention:

  • The _FIREBASE_PROJECT_ID is set to a placeholder value "your-project-id"
  • The _FIREBASE_SITE_ID uses a variable interpolation that might not work as expected
  • The Firebase token is not properly configured in the deployment step

Required actions:

  • Update _FIREBASE_PROJECT_ID in cloudbuild.yaml with the actual Firebase project ID
  • Set _FIREBASE_SITE_ID directly without variable interpolation
  • Add FIREBASE_TOKEN as a secret in Cloud Build and reference it properly in the deployment step
🔗 Analysis chain

Line range hint 81-88: Verify Firebase deployment configuration

The deployment step looks correct, but let's ensure the required secrets are properly configured.


Let me verify the Firebase configuration further by checking the Cloud Build configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Firebase token secret is configured in Cloud Build
gcloud secrets list --filter="name:FIREBASE_TOKEN" --format="get(name)"

# Verify Firebase project configuration
if [ -f "firebase.json" ]; then
  echo "Current Firebase configuration:"
  cat firebase.json
fi

Length of output: 2569


Script:

#!/bin/bash
# Check Cloud Build configuration for Firebase-related substitutions
if [ -f "cloudbuild.yaml" ]; then
  echo "Cloud Build configuration:"
  grep -A 10 "substitutions:" cloudbuild.yaml
fi

# Check if Firebase token is referenced in any environment files
rg -l "FIREBASE_TOKEN|_FIREBASE_PROJECT_ID|_FIREBASE_SITE_ID" --type yaml --type env

Length of output: 619

🧹 Nitpick comments (2)
cloudbuild.yaml (2)

25-25: Remove trailing whitespace

There is a trailing space after node:20.

-  - name: 'node:20'  
+  - name: 'node:20'
🧰 Tools
🪛 yamllint (1.35.1)

[error] 25-25: trailing spaces

(trailing-spaces)


Line range hint 25-52: Simplify build environment handling

The current if-else chain could be simplified, and defaulting to test environment without explicit warning might be risky.

Consider using a more concise approach:

     args:
       - '-c'
       - |
         echo "Build env:" ${_BUILD_ENV}
-        if [ "${_BUILD_ENV}" = "test" ]; then 
-          npm run build-test;
-        elif [ "${_BUILD_ENV}" = "release" ]; then 
-          npm run build-release;
-        # ... more conditions ...
-        else 
-          npm run build-test;
-        fi
+        if [ -z "${_BUILD_ENV}" ]; then
+          echo "Error: _BUILD_ENV is not set"
+          exit 1
+        fi
+        BUILD_SCRIPT="build-${_BUILD_ENV}"
+        if npm run | grep -q "^  ${BUILD_SCRIPT} "; then
+          npm run ${BUILD_SCRIPT}
+        else
+          echo "Error: Unknown build environment: ${_BUILD_ENV}"
+          exit 1
+        fi
🧰 Tools
🪛 yamllint (1.35.1)

[error] 25-25: trailing spaces

(trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eb14fe8 and 588d0c5.

📒 Files selected for processing (1)
  • cloudbuild.yaml (3 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
cloudbuild.yaml

[error] 25-25: trailing spaces

(trailing-spaces)

Comment on lines +10 to +21
# Step 1: Install Node.js dependencies
- name: 'node:20'
entrypoint: 'sh'
args:
- '-c'
- |
echo clean
npm cache clean --force
echo remove
rm -rf node_modules package-lock.json
echo Installing source NPM dependencies...
npm install
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

Optimize dependency installation for better reliability and performance

While the current setup works, consider these improvements:

  1. Use npm ci instead of npm install for more reliable builds
  2. Consider preserving the npm cache between builds
  3. Commit package-lock.json to source control for deterministic builds
-        npm cache clean --force
-        rm -rf node_modules package-lock.json
-        echo Installing source NPM dependencies...
-        npm install
+        rm -rf node_modules
+        echo Installing dependencies from package-lock.json...
+        npm ci
📝 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
# Step 1: Install Node.js dependencies
- name: 'node:20'
entrypoint: 'sh'
args:
- '-c'
- |
echo clean
npm cache clean --force
echo remove
rm -rf node_modules package-lock.json
echo Installing source NPM dependencies...
npm install
# Step 1: Install Node.js dependencies
- name: 'node:20'
entrypoint: 'sh'
args:
- '-c'
- |
echo clean
rm -rf node_modules
echo Installing dependencies from package-lock.json...
npm ci

Copy link

github-actions bot commented Jan 4, 2025

A friendly reminder that this PR had no activity for 15 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants