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

chore: add postgres db during the startup conditionally #37605

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

AnaghHegde
Copy link
Member

@AnaghHegde AnaghHegde commented Nov 20, 2024

Description

This pull request proposes a change to conditionally add a PostgreSQL database during startup.

Automation

/ok-to-test tags="@tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12064918747
Commit: fbded31
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Thu, 28 Nov 2024 08:44:27 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced conditional PostgreSQL service for CI tests, enhancing database service management.
  • Improvements
    • Refined job conditions for CI tests execution, improving workflow clarity and control.
    • Enhanced error handling and logging for better debugging during test failures.

@AnaghHegde AnaghHegde self-assigned this Nov 20, 2024
@AnaghHegde AnaghHegde requested a review from sharat87 as a code owner November 20, 2024 19:47
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 20, 2024
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The pull request updates the CI workflow configuration to conditionally include a PostgreSQL service while excluding the MongoDB service when PostgreSQL is present. The job execution conditions have been refined to trigger on specific events, and the logic for running tests and restoring cache has been clarified. The handling of Cypress test results and the logging of artifacts upon failure have been preserved, enhancing overall control flow and error handling in the CI process.

Changes

File Path Change Summary
.github/workflows/ci-test-limited.yml - Added PostgreSQL service with conditional inclusion based on branch reference.
- Updated MongoDB service to exclude when PostgreSQL is included.
- Refined job execution conditions for CI tests.
- Clarified logic for running specs and restoring cache.
- Preserved Cypress test steps and adjusted conditions for result tracking.

Possibly related PRs

Suggested labels

CI, Workflows Pod, Workflows Product

Suggested reviewers

  • sharat87
  • pratapaprasanna
  • abhvsn

🎉 In the CI realm, a change takes flight,
PostgreSQL joins, MongoDB takes flight.
Tests now run with clearer intent,
Branches dictate where the services went.
Logs and artifacts, all captured with care,
In the world of workflows, we’re beyond compare! 🚀


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.

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.

@AnaghHegde AnaghHegde added the ok-to-test Required label for CI label Nov 20, 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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 81b7727 and fe4399a.

📒 Files selected for processing (1)
  • .github/workflows/ci-test-limited.yml (1 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/ci-test-limited.yml

52-52: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)


57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

🔇 Additional comments (1)
.github/workflows/ci-test-limited.yml (1)

Line range hint 306-306: Verify application's database selection mechanism

The workflow assumes dynamic database selection, but we need to verify how the application handles this.

Let's check the application configuration:

✅ Verification successful

Let me search for database configuration files to verify the database selection mechanism.


Let me check the database configuration implementation to understand how the database selection works.


The POSTGRES_PASSWORD environment variable is correctly handled by the application's database configuration system

The codebase shows a robust database connection management system through:

  • Dedicated datasource configuration classes that handle database connections
  • Plugin-based architecture where each database type (including Postgres) has its own connection management
  • Environment-aware configuration that can handle dynamic database parameters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for database configuration files
echo "Searching for database configuration files..."
fd -e yml -e yaml -e properties -e xml -e json -e js -e ts | grep -i "database\|config"

# Search for database connection logic
echo "Searching for database connection code..."
rg -l "mongoose\.connect|createConnection|pg\.Pool|new\s+Client" 

Length of output: 34387


Script:

#!/bin/bash
# Search for database configuration files in server code
echo "Searching for database configuration files..."
fd -e yml -e yaml -e properties -e xml -e json -e java | grep -i "database\|datasource"

# Search for database selection logic
echo "Searching for database selection code..."
rg -l "datasource.*config|database.*config" --type java --type ts

Length of output: 22664


Script:

#!/bin/bash
# Check MongoDB configuration
echo "Checking MongoDB configuration..."
rg -A 10 "class MongoConfig" --type java

# Check database connection setup
echo "Checking database connection setup..."
rg -A 10 "datasource.*connection|database.*connection" --type java

Length of output: 116065

🧰 Tools
🪛 actionlint

52-52: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)


57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

mongo:
if: "!contains(github.base_ref, 'pg') && github.ref_name != 'pg'"
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

Fix invalid service-level condition syntax

GitHub Actions doesn't support conditional service execution using the if key. Consider using environment variables or job-level conditions instead.

Consider this alternative approach:

-      mongo:
-        if: "!contains(github.base_ref, 'pg') && github.ref_name != 'pg'"
-        image: mongo
-        ports:
-          - 27017:27017
+      mongo:
+        image: mongo
+        ports:
+          - 27017:27017

Then control the database selection through environment variables in the application configuration.

📝 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
if: "!contains(github.base_ref, 'pg') && github.ref_name != 'pg'"
mongo:
image: mongo
ports:
- 27017:27017
🧰 Tools
🪛 actionlint

57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

Comment on lines 51 to 55
postgres:
if: contains(github.base_ref, 'pg') || github.ref_name == 'pg'
image: postgres:14
ports:
- 5432:5432
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

Add PostgreSQL environment variables and restrict branch conditions

The PostgreSQL service configuration needs attention in two areas:

  1. Missing essential environment variables (POSTGRES_USER, POSTGRES_PASSWORD)
  2. Branch name condition might unintentionally trigger for branches containing 'pg'

Apply this diff to enhance the configuration:

 postgres:
   if: contains(github.base_ref, 'pg') || github.ref_name == 'pg'
   image: postgres:14
+  env:
+    POSTGRES_USER: postgres
+    POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
   ports:
     - 5432:5432

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

🧰 Tools
🪛 actionlint

52-52: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

Copy link
Contributor

@abhvsn abhvsn left a comment

Choose a reason for hiding this comment

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

Minor comment except for the ones provided by bot.

@AnaghHegde AnaghHegde requested a review from abhvsn November 26, 2024 06:00
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 and nitpick comments (1)
.github/workflows/ci-test-limited.yml (1)

51-57: Consider using environment files for database selection

To improve the workflow's maintainability and avoid service-level conditions, consider using environment files to control database selection.

Example approach:

  1. Create a step that determines which database to use
  2. Set environment variables based on the branch
  3. Use these variables in subsequent steps
steps:
  - name: Set database type
    run: |
      if [[ "${{ github.ref }}" == "refs/heads/pg" ]]; then
        echo "USE_POSTGRES=true" >> $GITHUB_ENV
        echo "USE_MONGO=false" >> $GITHUB_ENV
      else
        echo "USE_POSTGRES=false" >> $GITHUB_ENV
        echo "USE_MONGO=true" >> $GITHUB_ENV
      fi
🧰 Tools
🪛 actionlint (1.7.4)

52-52: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)


57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fe4399a and 49f4d3b.

📒 Files selected for processing (1)
  • .github/workflows/ci-test-limited.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/ci-test-limited.yml

52-52: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)


57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

🔇 Additional comments (1)
.github/workflows/ci-test-limited.yml (1)

57-57: ⚠️ Potential issue

Fix invalid MongoDB service condition syntax

GitHub Actions doesn't support conditional service execution using the if key at the service level.

The previous review comment about moving conditions to job-level environment variables is still valid. This ensures proper control over which database service to use during the workflow execution.

🧰 Tools
🪛 actionlint (1.7.4)

57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

mongo:
if: "!contains(github.base_ref, 'pg') && github.ref_name != 'pg'"
Copy link
Contributor

Choose a reason for hiding this comment

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

@AnaghHegde can we remove the contains here as well?

@AnaghHegde AnaghHegde requested a review from abhvsn November 28, 2024 08:12
@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Nov 28, 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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 49f4d3b and fbded31.

📒 Files selected for processing (1)
  • .github/workflows/ci-test-limited.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/ci-test-limited.yml

52-52: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)


57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

🔇 Additional comments (2)
.github/workflows/ci-test-limited.yml (2)

57-57: ⚠️ Potential issue

Fix invalid service-level condition syntax for MongoDB

GitHub Actions doesn't support conditional service execution using the if key.

Move the condition logic to the job level using environment variables:

jobs:
  ci-test-limited:
    env:
      USE_MONGO: ${{ github.base_ref == 'release' || github.ref_name == 'release' }}
🧰 Tools
🪛 actionlint (1.7.4)

57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)


51-57: Verify database service configuration

Let's verify the database service configuration across the codebase to ensure proper integration.

✅ Verification successful

Let me gather more specific information about the database configurations in the workflow files.

The initial results show both MongoDB and PostgreSQL usage, but I need to verify the specific configurations in the workflow files and their alignment with the codebase setup.


Database service configuration is correctly aligned

The workflow configuration for both PostgreSQL and MongoDB services is properly aligned with the codebase's requirements. The conditional service activation (if: github.base_ref == 'pg' for PostgreSQL and if: github.base_ref == 'release' for MongoDB) matches the application's dual database support, as evidenced by:

  • MongoDB configuration in dev/test environments (mongodb://localhost:27017/appsmith)
  • PostgreSQL plugin implementation with proper connection handling
  • Presence of both database plugins and their respective connection utilities
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for database configuration and usage patterns

# Check for database configuration patterns
echo "Checking for database configuration patterns..."
rg -l "mongodb://" || echo "No MongoDB connection strings found"
rg -l "postgresql://" || echo "No PostgreSQL connection strings found"

# Check for database environment variables
echo "Checking for database environment variables..."
rg -l "POSTGRES_" || echo "No PostgreSQL environment variables found"
rg -l "MONGO_" || echo "No MongoDB environment variables found"

# Check for database dependencies
echo "Checking for database dependencies..."
fd -t f "package.json" -x jq -r '.dependencies | select(.mongoose or .pg)'

Length of output: 4797


Script:

#!/bin/bash
# Check workflow files for database service configurations
echo "Checking workflow files for database configurations..."
fd -e yml -e yaml -p ".github/workflows" -x cat {}

# Check for database-related environment files
echo "Checking database configuration in environment files..."
fd -e env -e "env.example" -x cat {}

# Check for database connection setup in server code
echo "Looking for database connection setup..."
rg -A 5 "createConnection|DatabaseConfig" app/server/

Length of output: 18430

🧰 Tools
🪛 actionlint (1.7.4)

52-52: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)


57-57: unexpected key "if" for "services" section. expected one of "credentials", "env", "image", "options", "ports", "volumes"

(syntax-check)

@AnaghHegde AnaghHegde merged commit 7099113 into release Dec 2, 2024
46 of 48 checks passed
@AnaghHegde AnaghHegde deleted the chore/ci-test-limit-pg branch December 2, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants