Skip to content

chore: use nix just #119

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

Merged
merged 7 commits into from
Jul 9, 2025
Merged

chore: use nix just #119

merged 7 commits into from
Jul 9, 2025

Conversation

Dav-14
Copy link
Contributor

@Dav-14 Dav-14 commented Apr 30, 2025

No description provided.

Copy link

coderabbitai bot commented Apr 30, 2025

Walkthrough

This update introduces a Nix flake-based development environment, adds a Justfile for task automation, and simplifies the Earthfile by removing operator-related logic and auxiliary targets. The .envrc is configured to use the Nix flake impurely. Test CRD preparation is automated with go:generate directives, and minor formatting is applied to .gitignore. Test CRD paths are updated to use freshly cloned operator manifests.

Changes

File(s) Change Summary
.envrc New file: Configures environment to use Nix flake in impure mode.
.gitignore Adds a newline at the end of the file.
Earthfile Removes operator imports and auxiliary build/test targets; renames build-image to build; simplifies source copying.
Justfile New file: Defines recipes for generation, linting, testing, releases, and Kubernetes/Helm tasks using just.
flake.nix New file: Introduces a Nix flake with Go 1.23 devShells, overlays, and tool dependencies for multiple systems.
tests/main_test.go Adds go:generate directives to automate operator CRD fetching; updates CRD path accordingly.
internal/membership_listener_test.go Adds go:generate directives for operator CRD fetching; updates CRD path accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Shell
    participant Justfile
    participant TestSuite

    Developer->>Shell: Enter directory (.envrc triggers)
    Shell->>Shell: Setup environment with Nix flake (impure mode)
    Developer->>Justfile: just pre-commit
    Justfile->>Justfile: Run generate, tidy, lint
    Developer->>Justfile: just tests-all
    Justfile->>TestSuite: Run unit and integration tests
    TestSuite->>TestSuite: go:generate clones operator CRDs
    TestSuite->>TestSuite: Run tests using updated CRDs
Loading

Possibly related PRs

Suggested reviewers

  • gfyrag

Poem

🐇
A flake now brings our tools to play,
With Justfile tasks to guide the way.
The Earthfile’s lighter, tests prepared,
Operator CRDs fetched and shared.
In Nix and Go, we hop along—
A tidy warren, swift and strong!

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/use-just-nix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this 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.

@Dav-14 Dav-14 marked this pull request as ready for review April 30, 2025 12:49
@Dav-14 Dav-14 requested a review from a team as a code owner April 30, 2025 12:49
@Dav-14 Dav-14 enabled auto-merge (squash) April 30, 2025 12:49
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: 4

🔭 Outside diff range comments (1)
internal/grpcclient/connection_generated.go (1)

1-153: 💡 Verification agent

🧩 Analysis chain

Verify mock generation is included in CI

Since this is an auto-generated file, ensure that mock generation is part of your CI process or that developers know to run the generate task when interface changes occur.


🏁 Script executed:

#!/bin/bash
# Check if the Justfile's generate task includes go generate for mocks

echo "Verifying that the generate task in Justfile includes commands to generate mocks"
grep -A 5 "generate:" Justfile

echo "Checking if there are any go:generate directives in the connection_adapter.go file"
grep -A 3 "//go:generate" internal/grpcclient/connection_adapter.go || echo "No go:generate directives found"

Length of output: 920


Ensure mock generation runs in CI
Verified that:

  • Your Justfile’s generate task invokes go generate ./…, covering all //go:generate mockgen… directives.
  • internal/grpcclient/connection_adapter.go includes the necessary //go:generate mockgen comments for both Connection and ConnectionAdapter.

Please update your CI pipeline to run the generate task (e.g. just generate or go generate ./…) on every build to guarantee mocks stay in sync when these interfaces change.

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

51-67: Dev-shell package list contains duplicates and potentially non-redistributable software
gotools and go-tools are synonyms – include one.
pkgs.nur.repos.goreleaser.goreleaser-pro is the commercial edition; it requires a licence and will 404 for public users.
nodejs_22 may not yet be packaged; prefer nodejs_20 (current LTS) to avoid breakage.

Recommended tidy-up:

-              gotools
-              go-tools
+              gotools     # only once
...
-              pkgs.nur.repos.goreleaser.goreleaser-pro
+              goreleaser
...
-              nodejs_22
+              nodejs_20
Justfile (1)

27-28: Consider adding race detection to unit tests

The unit tests task looks good, but adding the -race flag could help detect potential race conditions.

-  go test ./internal/...
+  go test -race ./internal/...
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e8457be and a527178.

⛔ Files ignored due to path filters (6)
  • .github/actions/default/action.yml is excluded by !**/*.yml
  • .github/workflows/main.yml is excluded by !**/*.yml
  • .github/workflows/releases.yml is excluded by !**/*.yml
  • flake.lock is excluded by !**/*.lock, !**/*.lock
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (10)
  • .envrc (1 hunks)
  • .gitignore (1 hunks)
  • Earthfile (3 hunks)
  • Justfile (1 hunks)
  • flake.nix (1 hunks)
  • internal/grpcclient/connection_adapter.go (1 hunks)
  • internal/grpcclient/connection_generated.go (1 hunks)
  • internal/membership_client_generated.go (2 hunks)
  • internal/membership_listener.go (1 hunks)
  • tests/main_test.go (2 hunks)
🔇 Additional comments (20)
.gitignore (1)

10-10: Add newline consistency
The newline at the end of .gitignore ensures POSIX compliance and avoids diff noise.

internal/membership_listener.go (1)

35-35: Relative path in go:generate is correct
The directive now uses a relative source and destination, aligning with project conventions. No further action needed.

.envrc (1)

1-1: Enable Nix flake environment
Introduced use flake --impure for direnv integration with the new flake.nix. This streamlines setting up the development environment.

internal/membership_client_generated.go (3)

2-2: Updated source header
The generated code now references the relative source membership_listener.go. Auto-generated file—skipping detailed review.


6-6: Updated generate command in documentation
Reflects the new relative paths in the mockgen invocation. Auto-generated file—skipping detailed review.


23-23: New unexported field in mock struct
The isgomock marker field is added by GoMock to prevent collisions. Auto-generated file—skipping detailed review.

tests/main_test.go (1)

42-44: Path now anchored to the test file – verify it matches the generate location
filepath.Join(filepath.Dir(filename), "dist", "operator", …) correctly resolves relative to the test file, but it only works if go generate ./... is executed from the same directory before go test. CI workflows that run go test ./... without a prior generate step will still break.

Please ensure your CI/Make/Just recipe invokes go generate ./tests/... (or a global just generate) before running the suite.

Earthfile (3)

10-11: COPY --dir with multiple source paths may not do what you expect
Earthly’s COPY --dir flag is documented to accept one directory tree to copy. Supplying multiple sources (cmd internal pkg) could silently ignore some paths or flatten the structure, depending on the Earthly version.

If you need three directories preserved, emit three COPYs or create a single parent dir:

-    COPY --dir cmd internal pkg .
+    COPY --dir cmd .
+    COPY --dir internal .
+    COPY --dir pkg .

or

    COPY --dir . .

after pruning unrelated files.


21-28: Target rename to +build looks good – downstream references updated
The rename streamlines the pipeline, and subsequent references (BUILD --pass-args +build) have been adjusted accordingly. No further action required.


44-45: Confirm WAIT/BUILD indentation still passes syntax validation
Earthly is indentation-sensitive. Double-check that the inner BUILD --pass-args +build --tag=$tag line is indented exactly one tab under WAIT; inconsistent spacing will cause a parse error at build time.

Justfile (6)

1-4: Well structured configuration setup

The Justfile is properly configured with dotenv-load enabled and a helpful default task that lists all available commands.


6-8: Good task organization

The alias and task grouping provides convenient shortcuts and logical organization of tasks.


13-18: Excellent concurrent dependency management

The tidy task efficiently runs go mod tidy in parallel for both the root and tests directory with proper error handling via set -euo pipefail.


20-25: Well-structured linting setup

The lint task properly depends on prerequisite tasks and runs linting concurrently with appropriate timeout and build tags.


30-35: Well-implemented integration test environment setup

The integration tests task correctly sets up the Kubernetes test environment with a specific version of envtest and runs tests in parallel.


46-50: Kubernetes connection and cleanup tasks work well together

The connect-dev and uninstall tasks are well-structured with proper dependency relationships and error handling.

internal/grpcclient/connection_generated.go (4)

1-8: Correctly auto-generated mock file

This is an auto-generated mock file created by MockGen, as indicated by the header. The generation command is correctly specified.


9-18: Proper package and import setup

The package declaration and imports are correctly organized for the generated mocks.


20-86: MockConnection implementation follows best practices

The MockConnection implementation correctly implements the Connection interface with proper helper methods, recorder setup, and type assertions.


87-152: MockConnectionAdapter implementation follows best practices

The MockConnectionAdapter implementation correctly implements the ConnectionAdapter interface with proper context handling in each method.

Comment on lines 17 to 24
//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcclient . Connection
type Connection interface {
CloseSend() error
Send(*generated.Message) error
Recv() (*generated.Order, error)
}

//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcserver . ConnectionAdapter
//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcclient . ConnectionAdapter
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Duplicate mock generation destination
Both go:generate directives write to the same file (connection_generated.go), so the second will overwrite the first. Merge interfaces into one invocation or target separate destinations. For example:

-//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcclient . Connection
-//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcclient . ConnectionAdapter
+//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcclient . Connection,ConnectionAdapter
📝 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
//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcclient . Connection
type Connection interface {
CloseSend() error
Send(*generated.Message) error
Recv() (*generated.Order, error)
}
//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcserver . ConnectionAdapter
//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcclient . ConnectionAdapter
//go:generate mockgen -source=connection_adapter.go -destination=connection_generated.go -package grpcclient . Connection,ConnectionAdapter
type Connection interface {
CloseSend() error
Send(*generated.Message) error
Recv() (*generated.Order, error)
}
// …rest of file (e.g. ConnectionAdapter interface/implementation)…
🤖 Prompt for AI Agents (early access)
In internal/grpcclient/connection_adapter.go around lines 17 to 24, the two go:generate directives for mockgen both output to the same file connection_generated.go, causing the second to overwrite the first. To fix this, either combine the interfaces into a single mockgen command or change the destination file names so each interface's mock is generated into a separate file, preventing overwrites.

@Dav-14 Dav-14 force-pushed the feat/use-just-nix branch 2 times, most recently from 4d5b457 to 9d6d8f4 Compare April 30, 2025 14:18
@Dav-14 Dav-14 force-pushed the feat/use-just-nix branch from 9d6d8f4 to f7ef744 Compare July 9, 2025 08:41
cursor[bot]

This comment was marked as outdated.

@Dav-14 Dav-14 force-pushed the feat/use-just-nix branch from 25d3d9a to 748911e Compare July 9, 2025 09:30
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Workflow Tests Job Issues

The Tests job in the workflow contains three issues:

  1. YAML Indentation Error: Its steps are incorrectly indented with 4 spaces instead of 6, which will cause a YAML parsing error and workflow failure.
  2. Misleading Step Name: The step named "Pre-commit" is mislabeled, as it executes just tests-all (tests) instead of pre-commit checks.
  3. Missing Job Dependency: The job's dependency on the Dirty job was removed, allowing tests to run concurrently with the dirty check and potentially on uncommitted changes.

.github/workflows/main.yml#L52-L66

Tests:
runs-on: shipfox-4vcpu-ubuntu-2404
steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
- name: Setup Nix
uses: ./.github/actions/default
with:
token: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- name: Pre-commit
run: nix develop --impure --command just tests-all

Fix in CursorFix in Web


Bug: Missing Secrets in GitHub Actions Jobs

The GoReleaser and Release GitHub Actions jobs are missing required environment variables. SPEAKEASY_API_KEY and FURY_TOKEN were removed from both jobs, and GORELEASER_KEY was removed from the Release job in releases.yml. These secrets may still be required by the underlying goreleaser process.

.github/workflows/main.yml#L88-L91

env:
GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

.github/workflows/releases.yml#L26-L29

- name: Release
run: nix develop --impure --command just release
env:
GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }}

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b58cab and 86e3f08.

📒 Files selected for processing (2)
  • Justfile (1 hunks)
  • internal/membership_listener_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Justfile
🔇 Additional comments (1)
internal/membership_listener_test.go (1)

44-45: Path construction looks correct but verify the directory structure.

The CRD path update correctly points to the cloned operator directory structure. The use of filepath.Join and filepath.Dir(filename) ensures proper path construction across different operating systems.

The implementation properly constructs the path to the CRD bases directory within the cloned operator repository.

Comment on lines +33 to +34
//go:generate rm -rf ./dist/operator
//go:generate git clone --depth 1 --branch main https://github.com/formancehq/operator.git ./dist/operator
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider the implications of introducing network dependency and potential race conditions.

The go:generate directives introduce a network dependency for tests and could cause issues in CI/CD environments or when running tests concurrently. The rm -rf ./dist/operator command could also be risky if executed from an unexpected working directory.

Consider these potential improvements:

  • Add error handling for git clone failures
  • Use a more specific cleanup pattern to avoid accidental deletions
  • Consider caching the cloned repository to reduce build time
  • Document the network requirement for running tests

Run the following script to verify how this affects test execution:


🏁 Script executed:

#!/bin/bash
# Description: Check if tests can run without network access and verify concurrent execution safety

# Test 1: Check if any other tests also use similar go:generate directives
rg -A 3 -B 1 "go:generate.*git clone" 

# Test 2: Check if there are any cleanup or setup scripts that might conflict
fd -t f -e go -x rg -l "dist/operator" {}

# Test 3: Check if there are any CI configuration files that might need updates
fd -t f -e yml -e yaml -x rg -l "test" {} | head -5

Length of output: 985


Review go:generate directives for operator clone in tests

The new //go:generate lines in both

  • internal/membership_listener_test.go (lines 33–34)
  • tests/main_test.go

introduce a network dependency at test-time and use an unscoped rm -rf ./dist/operator, which can be unsafe if the working directory changes.

Recommended fixes:

  • Wrap the git clone in a small shell script or Makefile target that checks for errors and prints a clear failure message.
  • Scope cleanup to only the expected path (e.g. use a temp directory or verify that ./dist/operator exists before removing).
  • Cache or vendor the cloned repo (for example, clone once in CI and mount it, or use go:embed/a git submodule) to avoid repeated network fetches.
  • Document the requirement for network access (and any authentication) in your CONTRIBUTING.md or test README.
  • Update CI workflows to prepare ./dist/operator ahead of test runs, so tests don’t depend on live cloning.
🤖 Prompt for AI Agents
In internal/membership_listener_test.go at lines 33-34, the go:generate
directives currently perform an unsafe unscoped rm -rf on ./dist/operator and
clone the operator repo directly during test generation, causing network
dependency and potential data loss. To fix this, replace the direct rm and git
clone commands with a shell script or Makefile target that first checks if
./dist/operator exists before removing it, handles errors gracefully with clear
messages, and caches or vendors the cloned repo to avoid repeated network
fetches. Also, document the network access requirement in CONTRIBUTING.md or
test README and update CI workflows to prepare ./dist/operator before tests run,
eliminating live cloning during test generation.

@Dav-14 Dav-14 merged commit 8d09f72 into main Jul 9, 2025
7 checks passed
@Dav-14 Dav-14 deleted the feat/use-just-nix branch July 9, 2025 10:52
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