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

fixed pr workflow which ensures that talawa Api app starts in docker #2653

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

rahulrana701
Copy link

@rahulrana701 rahulrana701 commented Nov 12, 2024

What kind of change does this PR introduce?

refactoring

2638

Fixes #2638

If relevant, did you update the documentation?

Summary

This pr ensures that the pr workflow checks whether the talawa api app starts in docker and the workflow passes

Have you read the contributing guide?

Summary by CodeRabbit

  • New Features

    • Added checks to ensure the Talawa API application starts correctly in Docker.
    • Expanded monitoring for unauthorized changes to sensitive files.
    • Implemented a limit on the number of files that can be changed in a pull request.
    • Added a check for JSDocs comments to maintain documentation standards.
    • Enhanced validation to ensure pull requests target the correct base branch.
    • Introduced a new job, Docker-Check, to improve Docker container management during workflows.
  • Improvements

    • Minor updates for clarity and formatting in existing workflow jobs.

Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes in this pull request enhance the GitHub Actions workflow defined in .github/workflows/pull-request.yml. Key modifications include adding a job to check if the Talawa API application starts correctly in Docker, expanding the list of sensitive files monitored, enforcing a limit on the number of files changed, ensuring JSDocs compliance, and validating that the base branch for pull requests is develop.

Changes

File Change Summary
.github/workflows/pull-request.yml - Added a job Docker-Check to verify if the Talawa API app starts in Docker.
- Updated Check-Sensitive-Files job with a comprehensive list of monitored files.
- Modified File-count-check job to limit changes to 100 files.
- Enhanced JSDocs job to check for the existence of comments.
- Improved Branch-check job to verify the base branch is develop.

Assessment against linked issues

Objective Addressed Explanation
Check if Talawa API app starts in Docker (#2638)

Possibly related PRs

Suggested reviewers

  • palisadoes
  • varshith257

Poem

In the workflow's dance, we hop and play,
With Docker's embrace, our app finds its way.
Sensitive files now under our watch,
Documentation's glow, we won't let it botch.
Branches align, as we leap with glee,
A smoother process, for you and me! 🐇✨


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.

Copy link

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 03bad97 and 7e91ca2.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)

Comment on lines 258 to 265

- name: Checks Talawa API app starts in Docker
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
bash sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build
elif [[ "${{ runner.os }}" == "Windows" ]]; then
docker-compose -f docker-compose.dev.yaml up --build
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

Improve workflow structure to avoid resource conflicts

The current workflow runs both Docker containers and local development server in the same job, which could lead to port conflicts and redundant testing. Consider restructuring the workflow for better separation of concerns.

Suggestions:

  1. Split into separate jobs:
    • Test-Application: Run tests locally (existing)
    • Docker-Check: Run Docker validation (new)
  2. Add job dependency:
    Docker-Check:
      needs: [Test-Application]
      # ... Docker check implementation

This separation will:

  • Prevent port conflicts
  • Make the workflow more maintainable
  • Provide clearer failure points
  • Allow parallel execution if needed

Comment on lines 259 to 265
- name: Checks Talawa API app starts in Docker
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
bash sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build
elif [[ "${{ runner.os }}" == "Windows" ]]; then
docker-compose -f docker-compose.dev.yaml up --build
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

Critical issues in Docker startup check implementation

The current implementation has several issues that need to be addressed:

  1. The Docker Compose command path is incorrect and non-standard
  2. Missing detached mode will cause the workflow to hang
  3. No health check to verify successful startup
  4. No timeout handling
  5. No cleanup of Docker resources
  6. Unnecessary Windows condition (GitHub Actions uses Ubuntu runners)

Replace the implementation with this more robust version:

-      - name: Checks Talawa API app starts in Docker
-        run: |
-          if [[ "${{ runner.os }}" == "Linux" ]]; then
-          bash sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build
-          elif [[ "${{ runner.os }}" == "Windows" ]]; then
-          docker-compose -f docker-compose.dev.yaml up --build
-          fi
+      - name: Check if Talawa API starts in Docker
+        run: |
+          # Start containers in detached mode
+          docker-compose -f docker-compose.dev.yaml up -d --build
+          
+          # Wait for the API to be healthy (max 60 seconds)
+          timeout=60
+          until curl -f http://localhost:4000/health || [ $timeout -eq 0 ]; do
+            echo "Waiting for API to start... ($timeout seconds remaining)"
+            sleep 1
+            ((timeout--))
+          done
+          
+          if [ $timeout -eq 0 ]; then
+            echo "Error: API failed to start within timeout"
+            docker-compose -f docker-compose.dev.yaml logs
+            exit 1
+          fi
+          
+          echo "API started successfully"
+          
+          # Cleanup
+          docker-compose -f docker-compose.dev.yaml down -v

This implementation:

  • Uses standard docker-compose command
  • Runs containers in detached mode
  • Implements proper health check with timeout
  • Shows container logs on failure
  • Cleans up resources after check
📝 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
- name: Checks Talawa API app starts in Docker
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
bash sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build
elif [[ "${{ runner.os }}" == "Windows" ]]; then
docker-compose -f docker-compose.dev.yaml up --build
fi
- name: Check if Talawa API starts in Docker
run: |
# Start containers in detached mode
docker-compose -f docker-compose.dev.yaml up -d --build
# Wait for the API to be healthy (max 60 seconds)
timeout=60
until curl -f http://localhost:4000/health || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
exit 1
fi
echo "API started successfully"
# Cleanup
docker-compose -f docker-compose.dev.yaml down -v

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7e91ca2 and 0fd01f2.

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

299-299: "runs-on" section is missing in job "Docker-Check"

(syntax-check)

🪛 yamllint
.github/workflows/pull-request.yml

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 301-301: trailing spaces

(trailing-spaces)


[error] 305-305: trailing spaces

(trailing-spaces)


[error] 312-312: trailing spaces

(trailing-spaces)


[error] 318-318: trailing spaces

(trailing-spaces)


[error] 320-320: trailing spaces

(trailing-spaces)

Comment on lines 302 to 322
- name: Check if Talawa API starts in Docker
run: |
docker-compose -f docker-compose.dev.yaml up -d --build

timeout=60
until curl -f http://localhost:4000/health || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done

if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
exit 1
fi

echo "API started successfully"

# Cleanup
docker-compose -f docker-compose.dev.yaml down -v
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 Docker check reliability

While the implementation is good, there are a few improvements needed:

  1. Add error handling for docker-compose commands
  2. Use environment variable for health check URL
  3. Ensure no port conflicts with Test-Application job

Apply this diff to enhance the implementation:

+ name: Check if Talawa API starts in Docker
  run: |
+   # Ensure no containers are running
+   docker-compose -f docker-compose.dev.yaml down -v || true
+
+   # Start containers
    docker-compose -f docker-compose.dev.yaml up -d --build
+   if [ $? -ne 0 ]; then
+     echo "Failed to start containers"
+     exit 1
+   fi

    timeout=60
-   until curl -f http://localhost:4000/health || [ $timeout -eq 0 ]; do
+   until curl -f "${HEALTH_CHECK_URL:-http://localhost:4000}/health" || [ $timeout -eq 0 ]; do
      echo "Waiting for API to start... ($timeout seconds remaining)"
      sleep 1
      ((timeout--))
    done
    
    if [ $timeout -eq 0 ]; then
      echo "Error: API failed to start within timeout"
      docker-compose -f docker-compose.dev.yaml logs
+     docker-compose -f docker-compose.dev.yaml down -v
      exit 1
    fi
    
    echo "API started successfully"
    
    # Cleanup
    docker-compose -f docker-compose.dev.yaml down -v
+   if [ $? -ne 0 ]; then
+     echo "Failed to cleanup containers"
+     exit 1
+   fi

Additionally, consider adding these environment variables to the job:

env:
  HEALTH_CHECK_URL: http://localhost:4000
  COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}

The COMPOSE_PROJECT_NAME ensures unique container names per PR, preventing conflicts with other jobs.

🧰 Tools
🪛 yamllint

[error] 305-305: trailing spaces

(trailing-spaces)


[error] 312-312: trailing spaces

(trailing-spaces)


[error] 318-318: trailing spaces

(trailing-spaces)


[error] 320-320: trailing spaces

(trailing-spaces)

Comment on lines 299 to 301
Docker-Check:
needs: Test-Application
steps:
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing required "runs-on" field

The job definition is missing the required "runs-on" field which specifies the runner environment. This will cause the workflow to fail.

Apply this diff to fix the job definition:

  Docker-Check:
    needs: Test-Application
+   runs-on: ubuntu-latest
    steps:
📝 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
Docker-Check:
needs: Test-Application
steps:
Docker-Check:
needs: Test-Application
runs-on: ubuntu-latest
steps:
🧰 Tools
🪛 actionlint

299-299: "runs-on" section is missing in job "Docker-Check"

(syntax-check)

🪛 yamllint

[error] 301-301: trailing spaces

(trailing-spaces)

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0fd01f2 and 8952134.

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

304-304: shellcheck reported issue in this script: SC2181:style:6:7: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


304-304: shellcheck reported issue in this script: SC2181:style:29:7: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint
.github/workflows/pull-request.yml

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)


[error] 320-320: trailing spaces

(trailing-spaces)


[error] 339-339: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/pull-request.yml (1)

299-340: Verify workflow execution order and failure handling

The job integration looks good, but let's verify the workflow execution order and failure handling.

✅ Verification successful

Workflow execution order and failure handling are correctly implemented

  • Docker-Check job properly depends on Test-Application.
  • Cleanup steps are executed in case of failure.
  • Proper error handling with exit 1 is in place.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify workflow execution order and failure handling
# Expected: Docker-Check job should run after Test-Application and handle failures correctly

# Check if Docker-Check depends on Test-Application
rg -A 5 "Docker-Check:" .github/workflows/pull-request.yml

# Check if cleanup is performed in case of failure
rg -A 10 "docker-compose.*down" .github/workflows/pull-request.yml

# Check for proper error handling
rg "exit 1" .github/workflows/pull-request.yml

Length of output: 1357

🧰 Tools
🪛 actionlint

304-304: shellcheck reported issue in this script: SC2181:style:6:7: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


304-304: shellcheck reported issue in this script: SC2181:style:29:7: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint

[error] 302-302: trailing spaces

(trailing-spaces)


[error] 320-320: trailing spaces

(trailing-spaces)


[error] 339-339: trailing spaces

(trailing-spaces)

Comment on lines 303 to 336
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true

# Start containers
docker-compose -f docker-compose.dev.yaml up -d --build
if [ $? -ne 0 ]; then
echo "Failed to start containers"
exit 1
fi

timeout=60
until curl -f "${HEALTH_CHECK_URL:-http://localhost:4000}/health" || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done

if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi

echo "API started successfully"

# Cleanup
docker-compose -f docker-compose.dev.yaml down -v
if [ $? -ne 0 ]; then
echo "Failed to cleanup containers"
exit 1
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

Improve shell script robustness

While the implementation is good, there are some improvements needed:

  1. Use direct command checking instead of $?
  2. Fix indentation inconsistencies
  3. Add error handling for curl command

Apply this diff:

       - name: Check if Talawa API starts in Docker
         run: |
           # Ensure no containers are running
           docker-compose -f docker-compose.dev.yaml down -v || true

           # Start containers
-          docker-compose -f docker-compose.dev.yaml up -d --build
-          if [ $? -ne 0 ]; then
+          if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
             echo "Failed to start containers"
             exit 1
           fi

           timeout=60
-          until curl -f "${HEALTH_CHECK_URL:-http://localhost:4000}/health" || [ $timeout -eq 0 ]; do
+          until curl -sf "${HEALTH_CHECK_URL:-http://localhost:4000}/health" 2>/dev/null || [ $timeout -eq 0 ]; do
             echo "Waiting for API to start... ($timeout seconds remaining)"
             sleep 1
             ((timeout--))
           done      

           if [ $timeout -eq 0 ]; then
             echo "Error: API failed to start within timeout"
             docker-compose -f docker-compose.dev.yaml logs
             docker-compose -f docker-compose.dev.yaml down -v
             exit 1
           fi

           echo "API started successfully"

           # Cleanup
-          docker-compose -f docker-compose.dev.yaml down -v
-          if [ $? -ne 0 ]; then
+          if ! docker-compose -f docker-compose.dev.yaml down -v; then
             echo "Failed to cleanup containers"
             exit 1
           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
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true
# Start containers
docker-compose -f docker-compose.dev.yaml up -d --build
if [ $? -ne 0 ]; then
echo "Failed to start containers"
exit 1
fi
timeout=60
until curl -f "${HEALTH_CHECK_URL:-http://localhost:4000}/health" || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "API started successfully"
# Cleanup
docker-compose -f docker-compose.dev.yaml down -v
if [ $? -ne 0 ]; then
echo "Failed to cleanup containers"
exit 1
fi
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true
# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi
timeout=60
until curl -sf "${HEALTH_CHECK_URL:-http://localhost:4000}/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "API started successfully"
# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
fi
🧰 Tools
🪛 actionlint

304-304: shellcheck reported issue in this script: SC2181:style:6:7: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)


304-304: shellcheck reported issue in this script: SC2181:style:29:7: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint

[error] 320-320: trailing spaces

(trailing-spaces)

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

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

298-337: Remove trailing spaces

There are trailing spaces on several lines that should be removed:

  • Line 298: Empty line with spaces
  • Line 302: After steps:
  • Line 319: After done
  • Line 337: After number }}

Remove trailing spaces to improve code cleanliness.

🧰 Tools
🪛 yamllint

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)


[error] 319-319: trailing spaces

(trailing-spaces)


[error] 337-337: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8952134 and 2288116.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
.github/workflows/pull-request.yml

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)


[error] 319-319: trailing spaces

(trailing-spaces)


[error] 337-337: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/pull-request.yml (1)

299-337: Verify Docker configuration and test data setup

Let's verify the Docker configuration and ensure test data setup is handled properly.

🧰 Tools
🪛 yamllint

[error] 302-302: trailing spaces

(trailing-spaces)


[error] 319-319: trailing spaces

(trailing-spaces)


[error] 337-337: trailing spaces

(trailing-spaces)

Comment on lines 299 to 302
Docker-Check:
needs: Test-Application
runs-on: ubuntu-latest
steps:
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing required steps

The job is missing critical setup steps:

  1. Repository checkout to access docker-compose files
  2. Node.js setup for environment consistency with other jobs

Add these steps before the Docker check:

 Docker-Check:
   needs: Test-Application
   runs-on: ubuntu-latest
   steps:
+    - name: Checkout repository
+      uses: actions/checkout@v4
+
+    - name: Set up Node.js
+      uses: actions/setup-node@v4
+      with:
+        node-version: '22.x'
📝 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
Docker-Check:
needs: Test-Application
runs-on: ubuntu-latest
steps:
Docker-Check:
needs: Test-Application
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
🧰 Tools
🪛 yamllint

[error] 302-302: trailing spaces

(trailing-spaces)

Comment on lines 335 to 337
env:
HEALTH_CHECK_URL: http://localhost:4000
COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing required environment variables

The Docker environment is missing critical variables that are required for the application to start properly. These variables are present in the Test-Application job but missing here.

Add these environment variables:

   env:
     HEALTH_CHECK_URL: http://localhost:4000
-    COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}      
+    COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
+    MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db
+    REDIS_HOST: redis
+    REDIS_PORT: 6379
+    ACCESS_TOKEN_SECRET: ${{ env.ACCESS_TOKEN_SECRET }}
+    REFRESH_TOKEN_SECRET: ${{ env.REFRESH_TOKEN_SECRET }}
+    LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]"
+    COLORIZE_LOGS: "true"
+    LOG_LEVEL: "info"

Note: The MongoDB and Redis hostnames are changed to match the service names in docker-compose.

📝 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
env:
HEALTH_CHECK_URL: http://localhost:4000
COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
env:
HEALTH_CHECK_URL: http://localhost:4000
COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db
REDIS_HOST: redis
REDIS_PORT: 6379
ACCESS_TOKEN_SECRET: ${{ env.ACCESS_TOKEN_SECRET }}
REFRESH_TOKEN_SECRET: ${{ env.REFRESH_TOKEN_SECRET }}
LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]"
COLORIZE_LOGS: "true"
LOG_LEVEL: "info"
🧰 Tools
🪛 yamllint

[error] 337-337: trailing spaces

(trailing-spaces)

Comment on lines 303 to 334
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true

# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi

timeout=60
until curl -sf "${HEALTH_CHECK_URL:-http://localhost:4000}/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done

if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi

echo "API started successfully"

# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
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

Enhance Docker health check implementation

The current implementation has several issues:

  1. No verification that required services (MongoDB, Redis) are running
  2. Health check might fail due to container networking
  3. Missing proper error handling and logging

Replace the implementation with this more robust version:

 - name: Check if Talawa API starts in Docker
   run: |
     # Ensure no containers are running
     docker-compose -f docker-compose.dev.yaml down -v || true

     # Start containers
     if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
       echo "Failed to start containers"
       docker-compose -f docker-compose.dev.yaml logs
       exit 1
     fi

     # Wait for MongoDB and Redis to be ready
+    echo "Waiting for MongoDB..."
+    timeout=30
+    until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
+      sleep 1
+      ((timeout--))
+    done
+
+    echo "Waiting for Redis..."
+    timeout=30
+    until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
+      sleep 1
+      ((timeout--))
+    done

     # Wait for API to be healthy
     timeout=60
-    until curl -sf "${HEALTH_CHECK_URL:-http://localhost:4000}/health" 2>/dev/null || [ $timeout -eq 0 ]; do
+    until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://localhost:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
       echo "Waiting for API to start... ($timeout seconds remaining)"
       sleep 1
       ((timeout--))
     done

     if [ $timeout -eq 0 ]; then
       echo "Error: API failed to start within timeout"
       docker-compose -f docker-compose.dev.yaml logs
       docker-compose -f docker-compose.dev.yaml down -v
       exit 1
     fi

     echo "API started successfully"

     # Cleanup
     if ! docker-compose -f docker-compose.dev.yaml down -v; then
       echo "Failed to cleanup containers"
       exit 1
     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
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true
# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi
timeout=60
until curl -sf "${HEALTH_CHECK_URL:-http://localhost:4000}/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "API started successfully"
# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
fi
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true
# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
docker-compose -f docker-compose.dev.yaml logs
exit 1
fi
# Wait for MongoDB and Redis to be ready
echo "Waiting for MongoDB..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
echo "Waiting for Redis..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
# Wait for API to be healthy
timeout=60
until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://localhost:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "API started successfully"
# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
fi
🧰 Tools
🪛 yamllint

[error] 319-319: trailing spaces

(trailing-spaces)

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.74%. Comparing base (03bad97) to head (9f67cd0).
Report is 8 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2653   +/-   ##
========================================
  Coverage    97.74%   97.74%           
========================================
  Files          358      358           
  Lines        18114    18114           
  Branches      2600     2599    -1     
========================================
  Hits         17706    17706           
  Misses         404      404           
  Partials         4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@palisadoes
Copy link
Contributor

  1. Please make sure coderabbit approves the PR.
  2. Your test is also failing

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

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

298-302: Fix formatting issues in job definition

Remove trailing spaces from lines 298 and 302 to maintain consistent formatting.

-  
+
  Docker-Check:
    needs: Test-Application
    runs-on: ubuntu-latest
-         
+
    steps:
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2288116 and b1c77da.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.3)
.github/workflows/pull-request.yml

309-309: "with" section should not be empty. please remove this section if it's unnecessary

(syntax-check)


310-310: unexpected key "node-version" for "step" section. expected one of "continue-on-error", "env", "id", "if", "name", "run", "shell", "timeout-minutes", "uses", "with", "working-directory"

(syntax-check)


366-366: context "env" is not allowed here. available contexts are "github", "inputs", "matrix", "needs", "secrets", "strategy", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details

(expression)


367-367: context "env" is not allowed here. available contexts are "github", "inputs", "matrix", "needs", "secrets", "strategy", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details

(expression)

🪛 yamllint (1.29.0-1)
.github/workflows/pull-request.yml

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)


[error] 303-303: trailing spaces

(trailing-spaces)


[error] 337-337: trailing spaces

(trailing-spaces)


[error] 344-344: trailing spaces

(trailing-spaces)


[error] 370-370: trailing spaces

(trailing-spaces)

Comment on lines 307 to 311
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix Node.js setup step syntax

The with section has incorrect indentation and syntax.

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
-        node-version: '22.x'
+          node-version: '22.x'
📝 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
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
🧰 Tools
🪛 actionlint (1.7.3)

309-309: "with" section should not be empty. please remove this section if it's unnecessary

(syntax-check)


310-310: unexpected key "node-version" for "step" section. expected one of "continue-on-error", "env", "id", "if", "name", "run", "shell", "timeout-minutes", "uses", "with", "working-directory"

(syntax-check)

Comment on lines 360 to 370
env:
HEALTH_CHECK_URL: http://localhost:4000
COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db
REDIS_HOST: redis
REDIS_PORT: 6379
ACCESS_TOKEN_SECRET: ${{ env.ACCESS_TOKEN_SECRET }}
REFRESH_TOKEN_SECRET: ${{ env.REFRESH_TOKEN_SECRET }}
LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]"
COLORIZE_LOGS: "true"
LOG_LEVEL: "info"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix environment variables configuration

  1. Replace env context with github context for token secrets
  2. Remove trailing spaces
    env:
      HEALTH_CHECK_URL: http://localhost:4000
      COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
      MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db
      REDIS_HOST: redis
      REDIS_PORT: 6379
-     ACCESS_TOKEN_SECRET: ${{ env.ACCESS_TOKEN_SECRET }}
-     REFRESH_TOKEN_SECRET: ${{ env.REFRESH_TOKEN_SECRET }}
+     ACCESS_TOKEN_SECRET: ${{ github.event.repository.name }}_access_${{ github.sha }}
+     REFRESH_TOKEN_SECRET: ${{ github.event.repository.name }}_refresh_${{ github.sha }}
      LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]"
      COLORIZE_LOGS: "true"
-     LOG_LEVEL: "info"      
+     LOG_LEVEL: "info"
📝 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
env:
HEALTH_CHECK_URL: http://localhost:4000
COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db
REDIS_HOST: redis
REDIS_PORT: 6379
ACCESS_TOKEN_SECRET: ${{ env.ACCESS_TOKEN_SECRET }}
REFRESH_TOKEN_SECRET: ${{ env.REFRESH_TOKEN_SECRET }}
LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]"
COLORIZE_LOGS: "true"
LOG_LEVEL: "info"
env:
HEALTH_CHECK_URL: http://localhost:4000
COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db
REDIS_HOST: redis
REDIS_PORT: 6379
ACCESS_TOKEN_SECRET: ${{ github.event.repository.name }}_access_${{ github.sha }}
REFRESH_TOKEN_SECRET: ${{ github.event.repository.name }}_refresh_${{ github.sha }}
LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]"
COLORIZE_LOGS: "true"
LOG_LEVEL: "info"
🧰 Tools
🪛 actionlint (1.7.3)

366-366: context "env" is not allowed here. available contexts are "github", "inputs", "matrix", "needs", "secrets", "strategy", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details

(expression)


367-367: context "env" is not allowed here. available contexts are "github", "inputs", "matrix", "needs", "secrets", "strategy", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details

(expression)

🪛 yamllint (1.29.0-1)

[error] 370-370: trailing spaces

(trailing-spaces)

Comment on lines 312 to 359
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true

# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi

# Wait for MongoDB and Redis to be ready
echo "Waiting for MongoDB..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done

echo "Waiting for Redis..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done

# Wait for API to be healthy
timeout=60
until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://localhost:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done

if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi

echo "API started successfully"

# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
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 Docker health check implementation

The implementation needs improvements in error handling and container networking:

  1. Add timeout handling for MongoDB and Redis checks
  2. Use container DNS names instead of localhost
         # Wait for MongoDB and Redis to be ready
         echo "Waiting for MongoDB..."
         timeout=30
         until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
-         sleep 1
-          ((timeout--))
+           sleep 1
+           ((timeout--))
         done
+         if [ $timeout -eq 0 ]; then
+           echo "Error: MongoDB failed to start within timeout"
+           docker-compose -f docker-compose.dev.yaml logs mongodb
+           docker-compose -f docker-compose.dev.yaml down -v
+           exit 1
+         fi

         echo "Waiting for Redis..."
         timeout=30
         until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
-         sleep 1
-         ((timeout--))
+           sleep 1
+           ((timeout--))
         done
+         if [ $timeout -eq 0 ]; then
+           echo "Error: Redis failed to start within timeout"
+           docker-compose -f docker-compose.dev.yaml logs redis
+           docker-compose -f docker-compose.dev.yaml down -v
+           exit 1
+         fi

         # Wait for API to be healthy
         timeout=60
-         until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://localhost:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
+         until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://api:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
📝 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
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true
# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi
# Wait for MongoDB and Redis to be ready
echo "Waiting for MongoDB..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
echo "Waiting for Redis..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
# Wait for API to be healthy
timeout=60
until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://localhost:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "API started successfully"
# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
fi
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true
# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi
# Wait for MongoDB and Redis to be ready
echo "Waiting for MongoDB..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: MongoDB failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs mongodb
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "Waiting for Redis..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: Redis failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs redis
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
# Wait for API to be healthy
timeout=60
until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://api:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "API started successfully"
# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
fi
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 337-337: trailing spaces

(trailing-spaces)


[error] 344-344: trailing spaces

(trailing-spaces)

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

🧹 Outside diff range and nitpick comments (3)
.github/workflows/pull-request.yml (3)

298-303: Fix formatting issues in job configuration

Remove trailing spaces from the following lines:

  • Line 298: Empty line with trailing space
  • Line 302: After ubuntu-latest
  • Line 303: Before steps:
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)


[error] 303-303: trailing spaces

(trailing-spaces)


304-310: Add caching for node_modules

Consider adding caching for node_modules to improve workflow execution time. This is especially important since the job depends on Test-Application which already has the cache.

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22.x'
+
+      - name: Restore node_modules from cache
+        id: cache-npm
+        uses: actions/cache@v4
+        env:
+          cache-name: cache-node-modules
+        with:
+          path: |
+            ~/.npm
+            node_modules
+          key: ${{ runner.os }}-docker-check-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
+          restore-keys: |
+            ${{ runner.os }}-docker-check-${{ env.cache-name }}-
+            ${{ runner.os }}-docker-check-
+            ${{ runner.os }}-

372-382: Fix environment variables configuration

  1. Remove trailing spaces from line 382
  2. Consider adding comments to document the purpose of each environment variable
  3. The HEALTH_CHECK_URL is not used in the script as it uses the container DNS name
     env:
-      HEALTH_CHECK_URL: http://localhost:4000
       COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
+      # MongoDB connection string using container DNS name
       MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db
+      # Redis connection details using container DNS names
       REDIS_HOST: redis
       REDIS_PORT: 6379
+      # Dynamic secrets using repository name and commit SHA
       ACCESS_TOKEN_SECRET: ${{ github.event.repository.name }}_access_${{ github.sha }}
       REFRESH_TOKEN_SECRET: ${{ github.event.repository.name }}_refresh_${{ github.sha }}
+      # Application configuration
       LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]"
       COLORIZE_LOGS: "true"
-      LOG_LEVEL: "info"      
+      LOG_LEVEL: "info"
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 382-382: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b1c77da and 11f54b1.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.29.0-1)
.github/workflows/pull-request.yml

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)


[error] 303-303: trailing spaces

(trailing-spaces)


[error] 335-335: trailing spaces

(trailing-spaces)


[error] 349-349: trailing spaces

(trailing-spaces)


[error] 356-356: trailing spaces

(trailing-spaces)


[error] 382-382: trailing spaces

(trailing-spaces)

Comment on lines 312 to 371
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true

# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi

# Wait for MongoDB and Redis to be ready
echo "Waiting for MongoDB..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: MongoDB failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs mongodb
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi

echo "Waiting for Redis..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: Redis failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs redis
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi

# Wait for API to be healthy
timeout=60
until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://api:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done

if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi

echo "API started successfully"

# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
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

Fix shell script implementation issues

  1. The shell script has inconsistent indentation which makes it harder to read
  2. Missing verification for docker-compose.dev.yaml
  3. Cleanup step could fail silently in some cases
       - name: Check if Talawa API starts in Docker
         run: |
           # Ensure no containers are running
           docker-compose -f docker-compose.dev.yaml down -v || true

+          # Verify docker-compose file exists
+          if [ ! -f "docker-compose.dev.yaml" ]; then
+            echo "Error: docker-compose.dev.yaml not found"
+            exit 1
+          fi
+
           # Start containers
           if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
             echo "Failed to start containers"
             exit 1
           fi

           # Wait for MongoDB and Redis to be ready
           echo "Waiting for MongoDB..."
           timeout=30
           until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
             sleep 1
             ((timeout--))
           done
           if [ $timeout -eq 0 ]; then
             echo "Error: MongoDB failed to start within timeout"
             docker-compose -f docker-compose.dev.yaml logs mongodb
             docker-compose -f docker-compose.dev.yaml down -v
             exit 1
           fi

           echo "Waiting for Redis..."
           timeout=30
           until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
             sleep 1
             ((timeout--))
           done
           if [ $timeout -eq 0 ]; then
             echo "Error: Redis failed to start within timeout"
             docker-compose -f docker-compose.dev.yaml logs redis
             docker-compose -f docker-compose.dev.yaml down -v
             exit 1
           fi

           # Wait for API to be healthy
           timeout=60
           until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://api:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
             echo "Waiting for API to start... ($timeout seconds remaining)"
             sleep 1
             ((timeout--))
           done

           if [ $timeout -eq 0 ]; then
             echo "Error: API failed to start within timeout"
             docker-compose -f docker-compose.dev.yaml logs
             docker-compose -f docker-compose.dev.yaml down -v
             exit 1
           fi

           echo "API started successfully"

           # Cleanup
-          if ! docker-compose -f docker-compose.dev.yaml down -v; then
-          echo "Failed to cleanup containers"
-          exit 1
-          fi
+          # Ensure cleanup runs even if the script fails
+          cleanup() {
+            echo "Cleaning up containers..."
+            if ! docker-compose -f docker-compose.dev.yaml down -v; then
+              echo "Warning: Failed to cleanup containers"
+            fi
+          }
+          trap cleanup EXIT
📝 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
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true
# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi
# Wait for MongoDB and Redis to be ready
echo "Waiting for MongoDB..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: MongoDB failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs mongodb
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "Waiting for Redis..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: Redis failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs redis
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
# Wait for API to be healthy
timeout=60
until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://api:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "API started successfully"
# Cleanup
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Failed to cleanup containers"
exit 1
fi
- name: Check if Talawa API starts in Docker
run: |
# Ensure no containers are running
docker-compose -f docker-compose.dev.yaml down -v || true
# Verify docker-compose file exists
if [ ! -f "docker-compose.dev.yaml" ]; then
echo "Error: docker-compose.dev.yaml not found"
exit 1
fi
# Start containers
if ! docker-compose -f docker-compose.dev.yaml up -d --build; then
echo "Failed to start containers"
exit 1
fi
# Wait for MongoDB and Redis to be ready
echo "Waiting for MongoDB..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok" >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: MongoDB failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs mongodb
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "Waiting for Redis..."
timeout=30
until docker-compose -f docker-compose.dev.yaml exec -T redis redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: Redis failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs redis
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
# Wait for API to be healthy
timeout=60
until docker-compose -f docker-compose.dev.yaml exec -T api curl -sf "http://api:4000/health" 2>/dev/null || [ $timeout -eq 0 ]; do
echo "Waiting for API to start... ($timeout seconds remaining)"
sleep 1
((timeout--))
done
if [ $timeout -eq 0 ]; then
echo "Error: API failed to start within timeout"
docker-compose -f docker-compose.dev.yaml logs
docker-compose -f docker-compose.dev.yaml down -v
exit 1
fi
echo "API started successfully"
# Cleanup
# Ensure cleanup runs even if the script fails
cleanup() {
echo "Cleaning up containers..."
if ! docker-compose -f docker-compose.dev.yaml down -v; then
echo "Warning: Failed to cleanup containers"
fi
}
trap cleanup EXIT
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 335-335: trailing spaces

(trailing-spaces)


[error] 349-349: trailing spaces

(trailing-spaces)


[error] 356-356: trailing spaces

(trailing-spaces)

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

🧹 Outside diff range and nitpick comments (3)
.github/workflows/pull-request.yml (3)

298-311: Fix formatting and optimize Node.js setup

  1. Remove trailing spaces on lines 298, 302, and 303
  2. Consider caching Node.js dependencies for faster builds

Add the cache step after Node.js setup:

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22.x'
+      
+      - name: Cache Node.js dependencies
+        uses: actions/cache@v4
+        with:
+          path: |
+            ~/.npm
+            node_modules
+          key: ${{ runner.os }}-docker-check-${{ hashFiles('**/package-lock.json') }}
+          restore-keys: |
+            ${{ runner.os }}-docker-check-
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)


[error] 303-303: trailing spaces

(trailing-spaces)


375-385: Add missing environment variables and fix formatting

  1. Remove trailing spaces on line 385
  2. Add missing environment variables for complete configuration

Add these environment variables:

    env:
      HEALTH_CHECK_URL: http://localhost:4000
      COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }}
      MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db
      REDIS_HOST: redis
      REDIS_PORT: 6379
      ACCESS_TOKEN_SECRET: ${{ github.event.repository.name }}_access_${{ github.sha }}
      REFRESH_TOKEN_SECRET: ${{ github.event.repository.name }}_refresh_${{ github.sha }}
      LAST_RESORT_SUPERADMIN_EMAIL: "[email protected]"
      COLORIZE_LOGS: "true"
-     LOG_LEVEL: "info"      
+     LOG_LEVEL: "info"
+     RECAPTCHA_SITE_KEY: ${{secrets.RECAPTCHA_SITE_KEY}}
+     RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}}
+     MAIL_USERNAME: ${{secrets.MAIL_USERNAME}}
+     MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}}
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 385-385: trailing spaces

(trailing-spaces)


299-386: Overall implementation meets requirements

The Docker-Check job successfully implements the PR objective of verifying that the Talawa API starts correctly in Docker. The implementation includes:

  1. Proper dependency on Test-Application job
  2. Robust health checks for all services
  3. Proper cleanup handling
  4. Appropriate environment configuration

Please address the suggested improvements in the previous comments for better reliability and maintainability.

Consider adding these enhancements in future PRs:

  1. Parallel execution of Test-Application and Docker-Check jobs
  2. Reusable workflow for Docker checks
  3. Artifact sharing between jobs for test results
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 302-302: trailing spaces

(trailing-spaces)


[error] 303-303: trailing spaces

(trailing-spaces)


[error] 335-335: trailing spaces

(trailing-spaces)


[error] 349-349: trailing spaces

(trailing-spaces)


[error] 356-356: trailing spaces

(trailing-spaces)


[error] 385-385: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 11f54b1 and 9f67cd0.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.29.0-1)
.github/workflows/pull-request.yml

[error] 298-298: trailing spaces

(trailing-spaces)


[error] 302-302: trailing spaces

(trailing-spaces)


[error] 303-303: trailing spaces

(trailing-spaces)


[error] 335-335: trailing spaces

(trailing-spaces)


[error] 349-349: trailing spaces

(trailing-spaces)


[error] 356-356: trailing spaces

(trailing-spaces)


[error] 385-385: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/pull-request.yml (1)

312-374: LGTM with existing suggestions

The implementation is fundamentally sound. Please refer to the existing review comments for improvements in:

  1. Shell script robustness
  2. Error handling
  3. Container networking
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 335-335: trailing spaces

(trailing-spaces)


[error] 349-349: trailing spaces

(trailing-spaces)


[error] 356-356: trailing spaces

(trailing-spaces)

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