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

feat: Use Nix & Justfile #619

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

feat: Use Nix & Justfile #619

wants to merge 22 commits into from

Conversation

flemzord
Copy link
Member

No description provided.

- Add ginkgo to the list of dependencies in flake.nix
- Remove unnecessary CACHE directives in Earthfile
- Simplify 'compile' section in Earthfile
- Simplify 'tests' section in Earthfile
- Simplify 'lint' section in Earthfile
- Simplify 'pre-commit' section in Earthfile
- Simplify 'pre-commit-nix' section in Earthfile
- Simplify 'tidy' section in Earthfile
- Simplify 'export-docs-events' section in Earthfile

feat/nix
Reworked config to use 'nix develop' with 'earthly' command. Added 'pre-commit-nix'
hook. Removed unnecessary flags and secrets. (feat/nix)
@flemzord flemzord requested a review from a team as a code owner December 17, 2024 20:34
Copy link

coderabbitai bot commented Dec 17, 2024

Walkthrough

This pull request introduces changes to the project's development infrastructure, focusing on environment configuration and build processes. The modifications include adding a .gitignore entry to exclude .env files, updating the Earthfile to use local execution for various build and test processes, and introducing a new flake.nix file to create a Nix-based development environment for Go 1.23. Additionally, updates to various mock testing files include the addition of a new struct field to enhance mock functionality.

Changes

File Change Summary
.gitignore Added .env to ignore environment files and !.envrc to track .envrc files
Earthfile Transitioned build and test processes to local execution, simplified artifact saving
flake.nix New file creating a Nix-flake development environment for Go 1.23
.envrc Added directives use flake --impure and dotenv for environment management
*.go (various mock test files) Added isgomock struct{} to multiple mock controller structs without altering existing functionality
Justfile Introduced new commands for project tasks, including pre-commit, tidy, lint, generate, and tests
deployments/pulumi/Earthfile Deleted file that defined a build process for the project
tools/generator/Earthfile Updated paths for COPY commands and removed tidy and lint sections

Possibly related PRs

Suggested reviewers

  • Dav-14

Poem

🐰 A rabbit's tale of code so bright,
Nix and Earth now dance with might,
.env hidden, builds run free,
Local magic, can't you see?
Development's path, smooth and light! 🚀


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

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link

@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

🧹 Nitpick comments (2)
flake.nix (1)

42-42: Consider upgrading to JDK 17 LTS

The configuration uses JDK 11, which is an older LTS version. Consider upgrading to JDK 17 LTS for better performance, security, and longer support.

-            jdk11
+            jdk17
Earthfile (1)

151-165: Consider simplifying the release mode logic

The current implementation could be simplified by:

  1. Using a more direct condition for docker login
  2. Consolidating the buildArgs logic
     LOCALLY
     ARG mode=local
-    # TODO: Move to function in earthly repostiory
-    LET buildArgs = --clean
-    IF [ "$mode" = "local" ]
-        SET buildArgs = --nightly --skip=publish --clean
-    ELSE IF [ "$mode" = "ci" ]
-        SET buildArgs = --nightly --clean
-    END
-    IF [ "$mode" != "local" ]
+    LET buildArgs = "--nightly --clean"
+    IF [ "$mode" = "local" ]
+        SET buildArgs = "$buildArgs --skip=publish"
+    ELSE
         WITH DOCKER
             RUN --secret GITHUB_TOKEN echo $GITHUB_TOKEN | docker login ghcr.io -u NumaryBot --password-stdin
         END
     END
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a5d23d and d1b9efb.

⛔ Files ignored due to path filters (2)
  • .github/workflows/main.yml is excluded by !**/*.yml
  • flake.lock is excluded by !**/*.lock, !**/*.lock
📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • Earthfile (7 hunks)
  • flake.nix (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🔇 Additional comments (3)
flake.nix (2)

39-39: Verify goreleaser-pro license and availability

The configuration uses goreleaser-pro from NUR. Please ensure:

  1. The team has the necessary licenses for goreleaser-pro
  2. The CI environment has access to the required license key

5-5: Consider pinning the nixpkgs version for reproducible builds

Using a wildcard version (0.1.*) could lead to inconsistent builds across different environments. Consider pinning to a specific version or commit hash.

Earthfile (1)

205-207: LGTM!

The change to run docs events generation locally is straightforward and correct.

flake.nix Show resolved Hide resolved
Earthfile Outdated Show resolved Hide resolved
Earthfile Outdated Show resolved Hide resolved
Reworked config to use 'nix develop' with 'earthly' command. Added 'pre-commit-nix'
hook. Removed unnecessary flags and secrets. (feat/nix)
Reworked config to use 'nix develop' with 'earthly' command. Added 'pre-commit-nix'
hook. Removed unnecessary flags and secrets. (feat/nix)
Reworked config to use 'nix develop' with 'earthly' command. Added 'pre-commit-nix'
hook. Removed unnecessary flags and secrets. (feat/nix)
Reworked config to use 'nix develop' with 'earthly' command. Added 'pre-commit-nix'
hook. Removed unnecessary flags and secrets. (feat/nix)
Reworked config to use 'nix develop' with 'earthly' command. Added 'pre-commit-nix'
hook. Removed unnecessary flags and secrets. (feat/nix)
Reworked config to use 'nix develop' with 'earthly' command. Added
'pre-commit-nix' hook. Removed unnecessary flags and secrets. (feat/nix)
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@8cf1718). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #619   +/-   ##
=======================================
  Coverage        ?   64.96%           
=======================================
  Files           ?        8           
  Lines           ?      314           
  Branches        ?        0           
=======================================
  Hits            ?      204           
  Misses          ?       97           
  Partials        ?       13           

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

Earthfile Outdated Show resolved Hide resolved
Reworked config to use 'nix develop' with 'earthly' command. Added
'pre-commit-nix' hook. Removed unnecessary flags and secrets. (feat/nix)
Added a new .envrc file with configuration for direnv and updated .gitignore to include .envrc while still ignoring .env files. This ensures proper local environment setup using direnv without accidentally committing sensitive .env files.
This change ensures all mock test files include the `isgomock` struct, standardizing the structure of generated mocks. This addition aligns with gomock's conventions and facilitates internal consistency across mock definitions.
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 UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe5cbec and 6721cc2.

📒 Files selected for processing (19)
  • .envrc (1 hunks)
  • .gitignore (1 hunks)
  • Earthfile (8 hunks)
  • internal/api/bulking/mocks_ledger_controller_test.go (2 hunks)
  • internal/api/common/mocks_ledger_controller_test.go (2 hunks)
  • internal/api/common/mocks_system_controller_test.go (2 hunks)
  • internal/api/v1/mocks_ledger_controller_test.go (2 hunks)
  • internal/api/v1/mocks_system_controller_test.go (2 hunks)
  • internal/api/v2/mocks_ledger_controller_test.go (2 hunks)
  • internal/api/v2/mocks_system_controller_test.go (2 hunks)
  • internal/controller/ledger/controller_generated_test.go (2 hunks)
  • internal/controller/ledger/controller_with_too_many_client_handling_generated_test.go (2 hunks)
  • internal/controller/ledger/listener_generated_test.go (2 hunks)
  • internal/controller/ledger/numscript_parser_generated_test.go (2 hunks)
  • internal/controller/ledger/numscript_runtime_generated_test.go (2 hunks)
  • internal/controller/ledger/store_generated_test.go (2 hunks)
  • internal/storage/driver/buckets_generated_test.go (3 hunks)
  • internal/storage/driver/ledger_generated_test.go (2 hunks)
  • internal/storage/driver/system_generated_test.go (2 hunks)
✅ Files skipped from review due to trivial changes (11)
  • internal/storage/driver/ledger_generated_test.go
  • internal/controller/ledger/numscript_parser_generated_test.go
  • internal/storage/driver/system_generated_test.go
  • internal/controller/ledger/controller_generated_test.go
  • internal/api/common/mocks_ledger_controller_test.go
  • internal/api/v2/mocks_system_controller_test.go
  • internal/controller/ledger/store_generated_test.go
  • internal/api/v1/mocks_system_controller_test.go
  • internal/controller/ledger/controller_with_too_many_client_handling_generated_test.go
  • internal/controller/ledger/listener_generated_test.go
  • internal/storage/driver/buckets_generated_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • .gitignore
  • Earthfile
🔇 Additional comments (5)
internal/controller/ledger/numscript_runtime_generated_test.go (1)

21-21: LGTM! Standard gomock upgrade change.

The addition of the isgomock field is a standard change from upgrading to a newer version of go.uber.org/mock. This is a non-functional change that helps gomock with internal type assertions.

internal/api/common/mocks_system_controller_test.go (1)

24-24: LGTM! Consistent mock upgrade change.

The addition of the isgomock field matches the expected changes from the gomock upgrade across all mock files.

internal/api/v1/mocks_ledger_controller_test.go (2)

6-7: LGTM: Mockgen command is properly configured.

The mockgen command is correctly configured with appropriate flags for generating the mock implementation.


26-26: Verify mockgen version compatibility.

The addition of the isgomock field suggests a different version of mockgen is being used. This is likely due to the Nix environment setup.

✅ Verification successful

Let me try a different approach to gather the necessary information.


Let me check other mock files to verify if this is a consistent pattern with the current mockgen version.


The isgomock field is consistent across mock implementations and is part of the current mockgen version.

The verification shows that:

  1. The isgomock struct{} field is present in other mock files (confirmed in v2 implementation)
  2. All mock files are generated using the same mockgen configuration with consistent flags
  3. This is a standard field added by the current version of mockgen and not a version compatibility issue
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check mockgen version and configuration across the project

# Find all mock files and check for isgomock field consistency
echo "Checking mock files for isgomock field consistency..."
rg -l "isgomock struct{}" --type go

# Look for mockgen version specification in project files
echo "Looking for mockgen version specifications..."
rg -l "mockgen" --type nix

Length of output: 408


Script:

#!/bin/bash
# Check mockgen version in flake.nix
echo "Checking mockgen version in flake.nix..."
cat flake.nix | grep -A 5 mockgen

# Find all mock files
echo -e "\nListing all mock files..."
fd -t f "mock.*\.go$"

# Check the content of the specific mock file
echo -e "\nChecking the specific mock file..."
cat internal/api/v1/mocks_ledger_controller_test.go

Length of output: 17052


Script:

#!/bin/bash
# Check the content of another mock file for comparison
echo "Checking another mock file..."
cat internal/api/v2/mocks_ledger_controller_test.go | grep -A 5 "type LedgerController struct"

# Check mockgen command used in other files
echo -e "\nChecking mockgen commands in other files..."
rg "mockgen.*-source.*-destination" --type go

Length of output: 8710

internal/api/bulking/mocks_ledger_controller_test.go (1)

26-26: LGTM: Consistent mock implementation.

The changes are consistent with other mock files, maintaining uniformity across the codebase.

.envrc Show resolved Hide resolved
@@ -0,0 +1,2 @@
use flake --impure
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Add documentation and .env.example for development setup

The verification revealed:

  1. The CI workflows use --impure flag in a controlled environment with proper secrets management
  2. No documentation exists about Nix setup or required environment variables
  3. No .env.example template is present, only .envrc exists

Please add:

  • Documentation in README.md about the Nix-based development setup and the implications of using --impure
  • An .env.example file listing all required environment variables for development
🔗 Analysis chain

Consider security implications of using --impure flag

The --impure flag allows the Nix environment to access network and mutable state, which could potentially introduce non-deterministic builds or security risks. While this is often necessary for development environments, please ensure:

  1. This is documented in the project's development setup guide
  2. CI/CD pipelines use pure evaluation for reproducible builds

Let's verify if there's documentation about this:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for development setup documentation
rg -i "nix|flake|direnv" README.md || echo "No documentation found about Nix setup"

# Check if CI/CD uses pure evaluation
rg --type yaml "use flake" .github/

Length of output: 161


Script:

#!/bin/bash
# Let's check for any Nix-related documentation in other common locations
fd -t f -e md . | xargs rg -i "nix|flake|direnv" || echo "No Nix docs found"

# Check if flake.nix exists and its contents
if [ -f "flake.nix" ]; then
    echo "=== flake.nix contents ==="
    cat flake.nix
else
    echo "flake.nix not found"
fi

# Check for CI workflow files
fd -t f . .github/workflows/ || echo "No workflow files found"

Length of output: 1550


Script:

#!/bin/bash
# Let's check CI workflows for Nix-related configuration
echo "=== Checking CI workflows for Nix usage ==="
cat .github/workflows/main.yml
cat .github/workflows/releases.yml
cat .github/workflows/benchmark.yml

# Check for any .env related files
echo -e "\n=== Checking for .env related files ==="
fd -H "\.env" || echo "No .env files found"

Length of output: 8036

This change replaces Earthly with Just by removing Earthfiles and
introducing a Justfile. Benefits include streamlining the dependency
management, simplifying workflow automation, and improving build
process readability.

Build and CI workflows (e.g., pre-commit, tests, linting) have been
adapted to utilize Just commands, ensuring consistency across
development processes.
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

🧹 Nitpick comments (3)
flake.nix (1)

32-44: Consider adding essential development tools

The development shell includes a good set of tools, but consider adding:

  • delve for debugging
  • gopls for IDE support
  • air for live reload during development
 packages = with pkgs; [
   go
   gotools
   golangci-lint
   ginkgo
   yq
   jq
   pkgs.nur.repos.goreleaser.goreleaser-pro
   mockgen
   gomarkdoc
   jdk11
   just
+  delve
+  gopls
+  air
 ];
Justfile (2)

6-9: Consider adding validation to pre-commit

The pre-commit chain looks good but consider adding:

  • tests to ensure changes don't break existing functionality
  • A command to verify the Nix environment is properly set up
-pre-commit: tidy lint generate export-docs-events earthly
+pre-commit: verify-env tidy lint generate export-docs-events tests earthly

+verify-env:
+    @command -v nix >/dev/null 2>&1 || { echo "Nix is not installed. Please install Nix first."; exit 1; }
+    @nix flake check

28-39: Consider improving test coverage reporting

The test configuration is good but could be enhanced:

  • Add minimum coverage threshold
  • Generate HTML coverage report for better visualization
tests:
  @go test -race -covermode=atomic \
    -coverpkg=github.com/formancehq/ledger/internal/... \
    -coverpkg=github.com/formancehq/ledger/pkg/events/... \
    -coverpkg=github.com/formancehq/ledger/pkg/accounts/... \
    -coverpkg=github.com/formancehq/ledger/pkg/assets/... \
    -coverpkg=github.com/formancehq/ledger/cmd/... \
    -coverprofile coverage.txt \
    -tags it \
    ./...
  @cat coverage.txt | grep -v debug.go | grep -v "/machine/" > coverage2.txt
  @mv coverage2.txt coverage.txt
+ @go tool cover -html=coverage.txt -o coverage.html
+ @go tool cover -func=coverage.txt | grep total | awk '{print $3}' | sed 's/%//' | awk '{if ($1 < 80) exit 1}'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6721cc2 and 5988029.

⛔ Files ignored due to path filters (1)
  • .github/workflows/main.yml is excluded by !**/*.yml
📒 Files selected for processing (5)
  • Earthfile (1 hunks)
  • Justfile (1 hunks)
  • deployments/pulumi/Earthfile (0 hunks)
  • flake.nix (1 hunks)
  • tools/generator/Earthfile (2 hunks)
💤 Files with no reviewable changes (1)
  • deployments/pulumi/Earthfile
🚧 Files skipped from review as they are similar to previous changes (1)
  • Earthfile
🔇 Additional comments (5)
flake.nix (2)

14-14: Go 1.23 is not yet released

The specified Go version (23) corresponds to Go 1.23, which is not yet released. The current stable version is Go 1.21.5.


16-24: LGTM: Comprehensive system architecture support

The system configuration correctly handles multiple architectures (x86_64 and aarch64) for both Linux and Darwin, with proper overlay configuration and unfree package support.

Justfile (1)

1-4: LGTM: Environment configuration

The dotenv-load setting and default task listing provide good developer experience.

tools/generator/Earthfile (2)

14-19: LGTM: Simplified COPY commands

The path simplification for COPY commands improves readability while maintaining functionality.


41-41: Verify image repository configuration

Ensure the repository configuration aligns with the new Nix-based development environment.

✅ Verification successful

The verification results show consistent usage of ghcr.io across different files in the repository, including Earthfiles, Dockerfiles, and deployment configurations. The repository configuration in tools/generator/Earthfile matches the pattern used in other files and is properly aligned with the build system. There's no indication of any Nix-specific repository configuration that would conflict with the current setup.

Repository configuration is correctly aligned

The REPOSITORY argument defaulting to ghcr.io in the generator Earthfile is consistent with the project-wide container registry configuration, and there are no conflicts with development environments.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the repository configuration is consistent across files
rg -g '!.git' -l "ghcr.io" | while read -r file; do
  echo "Found repository reference in: $file"
  rg "ghcr.io" "$file" -C 2
done

Length of output: 1621

Replaced complex earthly-based release command with a `just` target in
the CI workflow for better maintainability. Added new `release`
commands to the Justfile for local, CI, and standard releases. This
streamlines the release process and enhances clarity.
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

🧹 Nitpick comments (4)
Justfile (4)

6-9: Consider preserving Earthly output for debugging

The @ prefix in the earthly command suppresses all output. This might make it difficult to debug issues when they occur.

-  @earthly --no-output +pre-commit
+  earthly --no-output +pre-commit

17-20: Consider adding error handling and path validation

The tidy task assumes the directories exist and the commands succeed. Consider adding error checking and making the paths configurable.

 tidy:
-  @go mod tidy
-  @cd {{justfile_directory()}}/tools/generator && go mod tidy
-  @cd {{justfile_directory()}}/deployments/pulumi && go mod tidy
+  #!/usr/bin/env sh
+  set -e
+  go mod tidy
+  for dir in tools/generator deployments/pulumi; do
+    if [ -d "$dir" ]; then
+      cd "$dir" && go mod tidy && cd {{justfile_directory()}}
+    else
+      echo "Warning: Directory $dir not found"
+    fi
+  done

22-26: Consider making the documentation path configurable

The documentation export path is hardcoded. Consider making it configurable through an environment variable for flexibility.

 export-docs-events:
-  @go run . docs events --write-dir docs/events
+  @go run . docs events --write-dir ${DOCS_DIR:-docs/events}

41-48: Consider adding release validation checks

The release tasks could benefit from pre-release validation checks to ensure all conditions are met before releasing.

 release:
+  #!/usr/bin/env sh
+  if [ -n "$(git status --porcelain)" ]; then
+    echo "Error: Working directory is not clean"
+    exit 1
+  fi
+  if [ -z "${GITHUB_TOKEN}" ]; then
+    echo "Error: GITHUB_TOKEN is not set"
+    exit 1
+  fi
   @goreleaser release --clean
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5988029 and 148930c.

⛔ Files ignored due to path filters (1)
  • .github/workflows/main.yml is excluded by !**/*.yml
📒 Files selected for processing (2)
  • Earthfile (1 hunks)
  • Justfile (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Earthfile
🔇 Additional comments (2)
Justfile (2)

1-4: Verify .env file handling

The dotenv-load directive is enabled, which is good for local development. However, let's ensure proper safeguards are in place.

✅ Verification successful

Environment variable handling is properly configured

The verification confirms that:

  • .env is correctly listed in .gitignore
  • No .env files are currently committed to the repository
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify .env is properly gitignored and no .env files are committed

# Check if .env is in .gitignore
rg "^\.env$" .gitignore

# Verify no .env files are committed
git ls-files | rg "\.env$"

Length of output: 59


11-15: Review auto-fix behavior in linting

The --fix flag automatically modifies code. This could be risky in CI environments or when running pre-commit hooks, as it might introduce unexpected changes.

Consider:

  1. Making auto-fix optional
  2. Running lint check first, then fix separately
  3. Verifying if the 5m timeout is sufficient

Comment on lines +28 to +39
tests:
@go test -race -covermode=atomic \
-coverpkg=github.com/formancehq/ledger/internal/... \
-coverpkg=github.com/formancehq/ledger/pkg/events/... \
-coverpkg=github.com/formancehq/ledger/pkg/accounts/... \
-coverpkg=github.com/formancehq/ledger/pkg/assets/... \
-coverpkg=github.com/formancehq/ledger/cmd/... \
-coverprofile coverage.txt \
-tags it \
./...
@cat coverage.txt | grep -v debug.go | grep -v "/machine/" > coverage2.txt
@mv coverage2.txt coverage.txt
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 coverage file handling

The current coverage file manipulation using grep and mv could fail silently. Consider using a more robust approach.

 tests:
   @go test -race -covermode=atomic \
     -coverpkg=github.com/formancehq/ledger/internal/... \
     -coverpkg=github.com/formancehq/ledger/pkg/events/... \
     -coverpkg=github.com/formancehq/ledger/pkg/accounts/... \
     -coverpkg=github.com/formancehq/ledger/pkg/assets/... \
     -coverpkg=github.com/formancehq/ledger/cmd/... \
     -coverprofile coverage.txt \
     -tags it \
     ./...
-  @cat coverage.txt | grep -v debug.go | grep -v "/machine/" > coverage2.txt
-  @mv coverage2.txt coverage.txt
+  @if [ -f coverage.txt ]; then \
+    grep -v 'debug\.go\|/machine/' coverage.txt > coverage.tmp && \
+    mv coverage.tmp coverage.txt || \
+    echo "Failed to process coverage file"; \
+  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
tests:
@go test -race -covermode=atomic \
-coverpkg=github.com/formancehq/ledger/internal/... \
-coverpkg=github.com/formancehq/ledger/pkg/events/... \
-coverpkg=github.com/formancehq/ledger/pkg/accounts/... \
-coverpkg=github.com/formancehq/ledger/pkg/assets/... \
-coverpkg=github.com/formancehq/ledger/cmd/... \
-coverprofile coverage.txt \
-tags it \
./...
@cat coverage.txt | grep -v debug.go | grep -v "/machine/" > coverage2.txt
@mv coverage2.txt coverage.txt
tests:
@go test -race -covermode=atomic \
-coverpkg=github.com/formancehq/ledger/internal/... \
-coverpkg=github.com/formancehq/ledger/pkg/events/... \
-coverpkg=github.com/formancehq/ledger/pkg/accounts/... \
-coverpkg=github.com/formancehq/ledger/pkg/assets/... \
-coverpkg=github.com/formancehq/ledger/cmd/... \
-coverprofile coverage.txt \
-tags it \
./...
@if [ -f coverage.txt ]; then \
grep -v 'debug\.go\|/machine/' coverage.txt > coverage.tmp && \
mv coverage.tmp coverage.txt || \
echo "Failed to process coverage file"; \
fi

@flemzord flemzord changed the title (WIP) feat: Use Nix feat: Use Nix & Justfile Dec 18, 2024
tools/generator/Earthfile Outdated Show resolved Hide resolved
Justfile Outdated Show resolved Hide resolved
ARG mode=local
COPY --dir . /src
DO core+GORELEASER --mode=$mode

generate-client:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this target can be extracted in the Justfile too?

- Removed unused 'group' annotation in Justfile to enhance clarity.
- Consolidated COPY commands in Earthfile for better maintainability.
- Updated 'compile' stage in Earthfile to use 'sources' for consistency.

These changes reduce redundancy, improve readability, and ensure less
complexity in maintenance.
Reordered tasks in the pre-commit command to ensure `generate` and
`earthly` execute before `tidy`, `lint`, and `export-docs-events`.
This improves maintainability and ensures prerequisites are met.
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

🧹 Nitpick comments (3)
Justfile (3)

11-14: Consider making lint timeout configurable

The 5-minute timeout is hardcoded. Consider making it configurable through an environment variable for flexibility in different environments.

 lint:
-  @golangci-lint run --fix --build-tags it --timeout 5m
-  @cd {{justfile_directory()}}/tools/generator && golangci-lint run --fix --build-tags it --timeout 5m
-  @cd {{justfile_directory()}}/deployments/pulumi && golangci-lint run --fix --build-tags it --timeout 5m
+  @golangci-lint run --fix --build-tags it --timeout ${LINT_TIMEOUT:-5m}
+  @cd {{justfile_directory()}}/tools/generator && golangci-lint run --fix --build-tags it --timeout ${LINT_TIMEOUT:-5m}
+  @cd {{justfile_directory()}}/deployments/pulumi && golangci-lint run --fix --build-tags it --timeout ${LINT_TIMEOUT:-5m}

24-25: Consider making docs directory configurable

The documentation output directory is hardcoded. Consider making it configurable through an environment variable.

 export-docs-events:
-  @go run . docs events --write-dir docs/events
+  @go run . docs events --write-dir ${DOCS_DIR:-docs/events}

40-47: Add release command validation and documentation

Consider:

  1. Adding environment validation before releases
  2. Adding comments to clarify the differences between release commands
+# Local release for testing, skips publishing
 release-local:
+  @[ -n "$(git status --porcelain)" ] && echo "Working directory not clean" && exit 1
   @goreleaser release --nightly --skip=publish --clean

+# CI release with nightly tag
 release-ci:
+  @[ -n "${CI}" ] || (echo "Not in CI environment" && exit 1)
   @goreleaser release --nightly --clean

+# Production release
 release:
+  @[ -n "$(git tag --points-at HEAD)" ] || (echo "No tag found" && exit 1)
   @goreleaser release --clean
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 148930c and 7695dd4.

📒 Files selected for processing (2)
  • Justfile (1 hunks)
  • tools/generator/Earthfile (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/generator/Earthfile
🔇 Additional comments (2)
Justfile (2)

1-4: LGTM! Good configuration setup

The dotenv-load setting and default command listing provide good developer experience.


27-38: Improve coverage file handling

The current coverage file manipulation using grep and mv could fail silently. Consider using a more robust approach.

Justfile Outdated
Comment on lines 6 to 9
pre-commit: generate earthly tidy lint export-docs-events

earthly:
@earthly --no-output +pre-commit
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 potential infinite recursion in pre-commit workflow

There's a circular dependency:

  • pre-commit includes earthly in its sequence
  • earthly command runs +pre-commit target

This could lead to infinite recursion. Consider either:

  1. Removing earthly from the pre-commit sequence, or
  2. Having earthly run a different target that doesn't include pre-commit

Comment on lines +16 to +19
tidy:
@go mod tidy
@cd {{justfile_directory()}}/tools/generator && go mod tidy
@cd {{justfile_directory()}}/deployments/pulumi && go mod tidy
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for directory changes

The cd commands should handle errors and ensure we return to the original directory.

 tidy:
   @go mod tidy
-  @cd {{justfile_directory()}}/tools/generator && go mod tidy
-  @cd {{justfile_directory()}}/deployments/pulumi && go mod tidy
+  @cd {{justfile_directory()}}/tools/generator && go mod tidy || exit 1
+  @cd {{justfile_directory()}}/deployments/pulumi && go mod tidy || exit 1
📝 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
tidy:
@go mod tidy
@cd {{justfile_directory()}}/tools/generator && go mod tidy
@cd {{justfile_directory()}}/deployments/pulumi && go mod tidy
tidy:
@go mod tidy
@cd {{justfile_directory()}}/tools/generator && go mod tidy || exit 1
@cd {{justfile_directory()}}/deployments/pulumi && go mod tidy || exit 1

flemzord and others added 4 commits December 19, 2024 09:07
Replaced `earthly` with `nix` and `just` in the release workflow.
This improves build consistency and leverages flakes for reproducibility.
* feat: improve queries performance and refactor storage read part

* fix: post commit effective volumes rendering

* fix: from review
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

♻️ Duplicate comments (4)
flake.nix (1)

14-14: ⚠️ Potential issue

Go 1.23 is not yet released

The specified Go version (23) corresponds to Go 1.23, which is not yet released. The current stable version is Go 1.21.5.

Apply this fix:

-      goVersion = 23; # Change this to update the whole stack
+      goVersion = 21; # Change this to update the whole stack
Justfile (3)

9-10: ⚠️ Potential issue

Fix potential infinite recursion in pre-commit workflow

The earthly command runs +pre-commit target which could create an infinite loop.

Consider either:

  1. Removing earthly from the pre-commit sequence, or
  2. Having earthly run a different target that doesn't include pre-commit

31-42: 🛠️ Refactor suggestion

Improve coverage file handling

The current coverage file manipulation using grep and mv could fail silently.

Apply this fix:

 tests:
   @go test -race -covermode=atomic \
     -coverpkg=github.com/formancehq/ledger/internal/... \
     -coverpkg=github.com/formancehq/ledger/pkg/events/... \
     -coverpkg=github.com/formancehq/ledger/pkg/accounts/... \
     -coverpkg=github.com/formancehq/ledger/pkg/assets/... \
     -coverpkg=github.com/formancehq/ledger/cmd/... \
     -coverprofile coverage.txt \
     -tags it \
     ./...
-  @cat coverage.txt | grep -v debug.go | grep -v "/machine/" > coverage2.txt
-  @mv coverage2.txt coverage.txt
+  @if [ -f coverage.txt ]; then \
+    grep -v 'debug\.go\|/machine/' coverage.txt > coverage.tmp && \
+    mv coverage.tmp coverage.txt || \
+    echo "Failed to process coverage file"; \
+  fi

17-20: 🛠️ Refactor suggestion

Add error handling for directory changes

The cd commands should handle errors and ensure we return to the original directory.

Apply this fix:

 tidy:
   @go mod tidy
-  @cd {{justfile_directory()}}/tools/generator && go mod tidy
-  @cd {{justfile_directory()}}/deployments/pulumi && go mod tidy
+  @cd {{justfile_directory()}}/tools/generator && go mod tidy || exit 1
+  @cd {{justfile_directory()}}/deployments/pulumi && go mod tidy || exit 1
🧹 Nitpick comments (2)
flake.nix (1)

32-44: Consider adding essential Go development tools

The development shell includes a good set of tools, but could benefit from additional essential Go development tools.

Consider adding these commonly used tools:

           packages = with pkgs; [
             go
             gotools
             golangci-lint
             ginkgo
             yq-go
             jq
             pkgs.nur.repos.goreleaser.goreleaser-pro
             mockgen
             gomarkdoc
             jdk11
             just
+            delve # Go debugger
+            gopls # Go language server
+            go-tools # Additional analysis tools
           ];
Earthfile (1)

78-78: Simplify client generation path handling

The client generation path could be simplified by using relative paths.

Apply this change:

-    COPY openapi.yaml openapi.yaml
+    COPY (+openapi/openapi.yaml) ./
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between df81dba and 33d6eab.

⛔ Files ignored due to path filters (1)
  • openapi.yaml is excluded by !**/*.yaml
📒 Files selected for processing (5)
  • .gitignore (1 hunks)
  • Earthfile (2 hunks)
  • Justfile (1 hunks)
  • flake.nix (1 hunks)
  • internal/controller/ledger/store_generated_test.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .gitignore
  • internal/controller/ledger/store_generated_test.go
🔇 Additional comments (1)
Earthfile (1)

24-24: Verify local compilation environment requirements

The switch to LOCALLY directive means the compilation will happen on the developer's machine instead of in a controlled Docker environment.

Run this script to check if all required tools are available in the Nix environment:

✅ Verification successful

Based on the examination of the codebase, I can now provide a final response:

The LOCALLY directive is safe as build tools are managed through flake.nix

The project uses Nix for development environment management through flake.nix, which ensures consistent tooling across developers' machines. The local compilation is intentional and properly supported:

  • The repository contains flake.nix for Nix-based environment management
  • Required Go tools are defined and managed through the Nix configuration
  • The project documentation mentions using Earthly with local development setup
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all tools required for local compilation are available in the Nix environment

# Check if we're in a Nix shell
if ! command -v nix-shell >/dev/null 2>&1; then
  echo "Not in a Nix shell environment"
  exit 1
fi

# Check for required Go tools
tools=("go" "golangci-lint" "mockgen" "goreleaser")
for tool in "${tools[@]}"; do
  if ! command -v "$tool" >/dev/null 2>&1; then
    echo "Missing required tool: $tool"
    exit 1
  fi
done

Length of output: 102


Script:

#!/bin/bash
# Let's check if there's a shell.nix or flake.nix file that defines the development environment
fd "shell.nix|flake.nix" --type f

# Also check if there are any other files that might specify the build environment
fd "default.nix" --type f

# Let's also look for any documentation about development setup
fd "README.md|CONTRIBUTING.md|DEVELOPMENT.md" --type f --exec cat {} \; | grep -i "nix\|development\|setup\|prerequisites"

Length of output: 795


Script:

#!/bin/bash
# Let's examine the Earthfile to understand the build setup and requirements
cat Earthfile

# Also check if there are any Go-specific build requirements
fd "go.mod|go.sum" --type f --exec cat {} \;

# Look for any Docker-related files that might be relevant
fd "Dockerfile|.dockerignore" --type f --exec cat {} \;

Length of output: 112085

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

Successfully merging this pull request may close these issues.

2 participants