Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow steps to upload dummy db artifact for tests #2616

Merged
merged 5 commits into from
Nov 25, 2024

Conversation

sainak
Copy link
Member

@sainak sainak commented Nov 25, 2024

Proposed Changes

  • add make targets for creating and loading db dumps
  • Add workflow steps to upload dummy db artifact for tests
  • replace deprecated DOCKER_BUILD_NO_SUMMARY env variable

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

Only PR's with test cases included and passing lint and test pipelines will be reviewed

@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins

Summary by CodeRabbit

  • New Features

    • Added database management capabilities including migration, backup, and restoration processes.
    • Introduced new steps in the workflow for database dumping and artifact handling.
    • New targets in the Makefile for pulling Docker images and managing database operations.
  • Bug Fixes

    • Improved handling of ignored files in the .gitignore to prevent tracking of unnecessary database dump files.
  • Refactor

    • Updated naming conventions for clarity in the Makefile targets.

@sainak sainak requested a review from a team as a code owner November 25, 2024 12:46
Copy link

coderabbitai bot commented Nov 25, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The recent changes encompass updates to the .github/workflows/reusable-test.yml, .gitignore, and Makefile. The workflow file now includes new steps for database management and artifact handling, such as dumping the database and uploading the artifact. The .gitignore file has been modified to ignore the care_db.dump file while keeping .gitkeep tracked. The Makefile has seen the addition of new targets for database operations and a renaming for consistency. These modifications enhance the overall workflow and management processes, because who doesn’t love a little extra organization?

Changes

File Change Summary
.github/workflows/reusable-test.yml Added steps for database management: "Dump db" for dumping the database and "Upload db artifact" for uploading the dump file. Updated existing step for Docker layers cache to conditionally execute on 'push' events.
.gitignore Added entry to ignore care_db.dump. Retained existing entry care/media/* with exception for .gitkeep.
Makefile Introduced new targets: migrate, dump-db, and load-db for database management. Renamed reset_db to reset-db. Removed migration command from reset-db target.

Sequence Diagram(s)

sequenceDiagram
    participant Workflow
    participant Database
    participant ArtifactStorage
    
    Workflow->>Database: Execute "Dump db"
    Database-->>Workflow: Return care_db.dump
    Workflow->>ArtifactStorage: Upload care_db.dump
    ArtifactStorage-->>Workflow: Confirm upload
Loading

🎉 In the land of code where changes flow,
New steps and targets begin to grow.
With dumps and uploads, the workflow's bright,
Ignoring the clutter, keeping it light.
So here's to the tweaks, both big and small,
A well-organized project, standing tall! 🌟

Warning

Rate limit exceeded

@sainak has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7104019 and 3412a4d.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (4)
Makefile (3)

43-44: Add migrate target to .PHONY list... if you don't mind.

The new migrate target looks fine, but it seems you forgot to add it to the .PHONY list at the top. I'm sure it was just an oversight.

-.PHONY: build, re-build, up, down, list, logs, test, makemigrations, reset_db
+.PHONY: build, re-build, up, down, list, logs, test, makemigrations, reset-db, migrate

54-56: Perhaps consider some improvements to the dump-db target?

While the implementation works, it might benefit from a few enhancements:

  1. Adding a timestamp to prevent accidental overwrites
  2. Including compression to reduce file size
  3. Adding basic error handling
 dump-db:
-	docker compose exec db sh -c "pg_dump -U postgres -Fc care > /tmp/care_db.dump"
-	docker compose cp db:/tmp/care_db.dump care_db.dump
+	@echo "Creating database dump..."
+	@docker compose exec db sh -c "pg_dump -U postgres -Fc -Z9 care > /tmp/care_db.dump" || (echo "Failed to create dump"; exit 1)
+	@docker compose cp db:/tmp/care_db.dump "care_db_$(shell date +%Y%m%d_%H%M%S).dump" || (echo "Failed to copy dump"; exit 1)
+	@echo "Dump created successfully"

Line range hint 43-62: Consider documenting these database operations.

Since these targets are part of the testing workflow enhancement, it might be helpful to:

  1. Add comments explaining each target's purpose
  2. Create a README section about database management
  3. Document the expected sequence of operations (e.g., migrate → dump-db → reset-db → load-db)

This would make it easier for other developers to understand and use these features correctly.

.github/workflows/reusable-test.yml (1)

60-63: Consider moving the dump step after tests

The database dump is created before running tests, which means:

  1. Any test that modifies the database will not be reflected in the dump
  2. The dump operation adds to the time before tests start running

Perhaps we should move this step after the tests? Unless there's a specific reason to capture the pre-test state that I'm not aware of? 🤔

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d23cbcb and 8f3afcf.

📒 Files selected for processing (3)
  • .github/workflows/reusable-test.yml (2 hunks)
  • .gitignore (1 hunks)
  • Makefile (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore

Makefile Outdated Show resolved Hide resolved
.github/workflows/reusable-test.yml Outdated Show resolved Hide resolved
.github/workflows/reusable-test.yml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.55%. Comparing base (d23cbcb) to head (3412a4d).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2616   +/-   ##
========================================
  Coverage    69.55%   69.55%           
========================================
  Files          212      212           
  Lines        11966    11966           
  Branches      1208     1208           
========================================
  Hits          8323     8323           
  Misses        3274     3274           
  Partials       369      369           

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


🚨 Try these New Features:

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 (1)
.github/workflows/reusable-test.yml (1)

84-92: Add error handling for missing dump file

The upload configuration looks quite thorough (and I do appreciate the comment about compression!), but it might be nice to handle the case where the dump file doesn't exist... you know, just in case something goes slightly wrong. 😌

       - name: Upload db artifact
         if: ${{ inputs.event_name == 'push' || github.event_name == 'push' }}
         uses: actions/upload-artifact@v4
         with:
           name: care-db-dump
           path: care_db.dump
           retention-days: 30
           compression-level: 0 # file is already compressed
           overwrite: true # keep only the last artifact
+          if-no-files-found: error # fail fast if dump wasn't created
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8f3afcf and 11676e9.

📒 Files selected for processing (2)
  • .github/workflows/reusable-test.yml (3 hunks)
  • Makefile (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Makefile
🔇 Additional comments (2)
.github/workflows/reusable-test.yml (2)

60-62: Verify the existence and implementation of the dump-db make target

The step looks good, but let's make absolutely sure that make target exists and does what we expect.

✅ Verification successful

The dump-db target exists and seems perfectly fine

The Makefile contains a properly implemented dump-db target that:

  • Uses pg_dump with correct user and format options
  • Dumps the database into a temporary file inside the container
  • Copies the dump file from the container to the host
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the dump-db target exists in Makefile
rg "^dump-db:" Makefile -A 5

# Look for any pg_dump related commands
rg "pg_dump" Makefile

Length of output: 339


41-41: Verify the impact of disabling Docker build summary

I see you're trying to be sneaky by disabling the build summary. While this might make the logs cleaner, it could make debugging more... interesting... when things go wrong. 🤔

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 suggestion.

Files not reviewed (1)
  • Makefile: Language not supported

.github/workflows/reusable-test.yml Show resolved Hide resolved
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 (4)
Makefile (4)

22-24: LGTM! Though some documentation would be nice...

The pull target follows the established pattern for Docker commands. I mean, it would be lovely if there was a comment explaining its purpose, but I suppose we can figure it out ourselves.


46-48: Add prerequisites to ensure database is ready

The migrate target looks fine, but it would be so much better if it had prerequisites to ensure the database is actually running. You know, just to avoid those awkward migration failures.

-migrate:
+migrate: up
 	docker compose exec backend bash -c "python manage.py migrate"

57-60: Add some user feedback, because silence isn't always golden

The dump-db target works, but users might appreciate knowing what's happening. Also, maybe we could handle existing dumps more gracefully?

 dump-db:
+	@echo "Creating database dump..."
 	docker compose exec db sh -c "pg_dump -U postgres -Fc care > /tmp/care_db.dump"
+	@echo "Copying dump file from container..."
 	docker compose cp db:/tmp/care_db.dump care_db.dump
+	@echo "Database dump created successfully at care_db.dump"

65-65: Nice architectural improvement!

The rename to reset-db is more consistent with other targets, and separating the migration into its own target is a much cleaner approach. I suppose sometimes change is good.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7104019 and 3412a4d.

📒 Files selected for processing (1)
  • Makefile (4 hunks)
🔇 Additional comments (2)
Makefile (2)

61-64: The load-db target could use just a tiny bit more polish

I see you've already added the --clean and --if-exists flags (nice!), but those user-friendly messages from the previous review would still be really nice to have. Just saying...


57-64: Verify integration with GitHub Actions workflow

The new database management targets look good for the PR's objective of handling dummy db artifacts. Let's just make sure they're properly integrated with the workflow.

✅ Verification successful

Well, someone did a decent job with the workflow integration

The new database targets are properly integrated into the GitHub Actions workflow, though it's worth noting that only dump-db is being used (after loading dummy data and before running tests). The workflow also includes steps to upload the database dump as an artifact, which is exactly what we'd expect to see. The load-db target isn't used in the workflow, but that's perfectly fine since it's meant for local development anyway.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the workflow integration of new db targets

# Check if the workflow file uses these new targets
rg "make (dump-db|load-db)" .github/workflows/

Length of output: 110


Script:

#!/bin/bash
# Let's see the context of how dump-db is used in the workflow
rg -A 5 -B 5 "make dump-db" .github/workflows/

# Also check if there are any other database-related steps
rg "db|database" .github/workflows/

Length of output: 1102

@vigneshhari vigneshhari merged commit d3d402d into develop Nov 25, 2024
8 checks passed
@vigneshhari vigneshhari deleted the sainak/fix-upload-db-as-srtifact branch November 25, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants