Skip to content

v4: Can now set project ref using the TRIGGER_PROJECT_REF env var #2109

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 4 commits into from
May 27, 2025

Conversation

ericallam
Copy link
Member

No description provided.

Copy link

changeset-bot bot commented May 27, 2025

🦋 Changeset detected

Latest commit: 89e8c7f

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented May 27, 2025

Warning

Rate limit exceeded

@ericallam has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 3 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 592cef6 and 89e8c7f.

📒 Files selected for processing (1)
  • packages/cli-v3/src/dev/devSupervisor.ts (2 hunks)

Walkthrough

A new environment variable, TRIGGER_PROJECT_REF, is introduced to allow setting the project reference via environment configuration. The CLI commands for deploy and development now resolve environment variables from a specified or default .env file using a new utility, resolveLocalEnvVars. These commands prioritize the project reference specified by CLI options, falling back to TRIGGER_PROJECT_REF if not provided. The environment variable is also injected into task run processes within both development and managed execution controllers. Supporting utilities for environment variable resolution and sanitization have been refactored and consolidated. No changes were made to the signatures of exported or public entities.

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
packages/cli-v3/src/dev/devSupervisor.ts (1)

582-590: 🛠️ Refactor suggestion

Remove unused duplicate function.

The gatherProcessEnv function at the bottom of the file appears to be unused after the refactoring. It's now redundant since the same functionality is provided by the gatherProcessEnv function in envVars.ts.

-function gatherProcessEnv() {
-  const $env = {
-    ...process.env,
-    NODE_ENV: "development",
-  };
-
-  // Filter out undefined values
-  return Object.fromEntries(Object.entries($env).filter(([key, value]) => value !== undefined));
-}
🧹 Nitpick comments (1)
packages/cli-v3/src/utilities/envVars.ts (1)

15-23: Consider documenting the NODE_ENV override behavior.

The function sets NODE_ENV to "development" which overrides any existing value. This might be intentional for dev environments, but consider adding a comment explaining this behavior.

 function gatherProcessEnv() {
   const $env = {
     ...process.env,
+    // Force NODE_ENV to development for dev environments
     NODE_ENV: "development",
   };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e84ede9 and f443887.

⛔ Files ignored due to path filters (2)
  • references/d3-chat/src/trigger/chat.ts is excluded by !references/**
  • references/d3-chat/trigger.config.ts is excluded by !references/**
📒 Files selected for processing (7)
  • .changeset/silly-timers-repair.md (1 hunks)
  • packages/cli-v3/src/commands/deploy.ts (2 hunks)
  • packages/cli-v3/src/commands/dev.ts (3 hunks)
  • packages/cli-v3/src/dev/devSupervisor.ts (2 hunks)
  • packages/cli-v3/src/entryPoints/dev-run-controller.ts (1 hunks)
  • packages/cli-v3/src/entryPoints/managed/execution.ts (1 hunks)
  • packages/cli-v3/src/utilities/envVars.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/cli-v3/src/dev/devSupervisor.ts (1)
packages/cli-v3/src/utilities/envVars.ts (1)
  • resolveEnvVars (4-13)
packages/cli-v3/src/utilities/envVars.ts (1)
packages/cli-v3/src/entryPoints/managed/env.ts (1)
  • gatherProcessEnv (215-226)
packages/cli-v3/src/commands/dev.ts (1)
packages/cli-v3/src/utilities/envVars.ts (1)
  • resolveEnvVars (4-13)
⏰ Context from checks skipped due to timeout of 90000ms (25)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (10, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (9, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 10)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 10)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (12)
packages/cli-v3/src/utilities/envVars.ts (1)

4-13: LGTM! Well-structured environment variable consolidation.

The function properly consolidates environment variables from multiple sources with clear precedence: process environment < additional variables < dotenv variables. The sanitization of all sources ensures consistent handling.

.changeset/silly-timers-repair.md (1)

1-6: LGTM! Clear and concise changeset documentation.

The changeset properly documents the new TRIGGER_PROJECT_REF environment variable feature as a patch-level change.

packages/cli-v3/src/entryPoints/dev-run-controller.ts (1)

615-615: LGTM! Correct implementation of TRIGGER_PROJECT_REF injection.

The environment variable is properly added to the TaskRunProcess environment, making the project reference available to task execution processes.

packages/cli-v3/src/dev/devSupervisor.ts (2)

28-28: LGTM! Proper import of the new utility.

The import correctly brings in the new resolveEnvVars utility for environment variable consolidation.


381-384: Excellent refactoring! Simplified environment variable resolution.

The refactoring successfully replaces the previous multi-step environment variable gathering and sanitization with a single call to resolveEnvVars, improving code maintainability and consistency.

packages/cli-v3/src/entryPoints/managed/execution.ts (1)

589-592: LGTM! Clean injection of project reference into task environment.

The code correctly adds TRIGGER_PROJECT_REF to the environment variables for the task run process, ensuring the project reference is available during task execution. The spread operator maintains existing environment variables while explicitly setting the project reference.

packages/cli-v3/src/commands/deploy.ts (3)

39-39: Good addition of centralized environment variable utility.

The import of resolveEnvVars promotes consistent environment variable handling across the CLI.


211-215: Well-implemented environment variable resolution with helpful debugging.

The code properly resolves environment variables from multiple sources and provides clear debug logging when TRIGGER_PROJECT_REF is detected, which aids in troubleshooting configuration issues.


219-219: Excellent precedence design for project reference resolution.

The fallback pattern options.projectRef ?? envVars.TRIGGER_PROJECT_REF correctly prioritizes explicit CLI options over environment variables, providing a sensible default mechanism while maintaining explicit control.

packages/cli-v3/src/commands/dev.ts (3)

4-9: Good import cleanup and consistent utility usage.

The removal of unused imports (SkipLoggingError, BundleError) and addition of resolveEnvVars improves code maintainability and follows the same pattern established in the deploy command.


131-135: Consistent environment variable resolution pattern.

The implementation mirrors the deploy command's approach, ensuring uniform behavior across CLI commands. The debug logging when TRIGGER_PROJECT_REF is found maintains consistency with other commands.


149-149: Proper fallback mechanism implementation.

The same precedence pattern as the deploy command (options.projectRef ?? envVars.TRIGGER_PROJECT_REF) ensures consistent project reference resolution across all CLI commands.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/cli-v3/src/utilities/localEnvVars.ts (1)

4-16: Add documentation and consider explicit return type.

The function logic is sound, but could benefit from improved documentation and type safety.

+/**
+ * Resolves environment variables from multiple sources with the following precedence:
+ * 1. dotenv file (highest priority)
+ * 2. additional variables (medium priority) 
+ * 3. process environment (lowest priority)
+ */
-export function resolveLocalEnvVars(
+export function resolveLocalEnvVars(
   envFile?: string,
   additionalVariables?: Record<string, string>
-) {
+): Record<string, string> {
   const processEnv = gatherProcessEnv();
   const dotEnvVars = resolveDotEnvVars(undefined, envFile);

   return {
     ...sanitizeEnvVars(processEnv),
     ...sanitizeEnvVars(additionalVariables ?? {}),
     ...sanitizeEnvVars(dotEnvVars),
   };
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f443887 and 592cef6.

📒 Files selected for processing (4)
  • packages/cli-v3/src/commands/deploy.ts (2 hunks)
  • packages/cli-v3/src/commands/dev.ts (3 hunks)
  • packages/cli-v3/src/dev/devSupervisor.ts (2 hunks)
  • packages/cli-v3/src/utilities/localEnvVars.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/cli-v3/src/commands/dev.ts
  • packages/cli-v3/src/commands/deploy.ts
  • packages/cli-v3/src/dev/devSupervisor.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/cli-v3/src/utilities/localEnvVars.ts (1)
packages/cli-v3/src/entryPoints/managed/env.ts (1)
  • gatherProcessEnv (215-226)
⏰ Context from checks skipped due to timeout of 90000ms (25)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (10, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (9, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 10)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/cli-v3/src/utilities/localEnvVars.ts (1)

1-2: LGTM! Clean imports.

The imports are well-organized and properly reference the existing utilities for dotenv resolution and environment variable sanitization.

@ericallam ericallam merged commit c571c5e into main May 27, 2025
33 checks passed
@ericallam ericallam deleted the ea-branch-73 branch May 27, 2025 11:51
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