Skip to content

fix: Prevent local NuGet modules from running in CI PR builds#1680

Merged
thomhurst merged 1 commit into
mainfrom
fix/pipeline-dev-mode
Dec 30, 2025
Merged

fix: Prevent local NuGet modules from running in CI PR builds#1680
thomhurst merged 1 commit into
mainfrom
fix/pipeline-dev-mode

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

Fixes the pipeline failure where CI incorrectly registers local NuGet modules on PR branches.

Root Cause

The GitHub Actions workflow sets DOTNET_ENVIRONMENT=Development for non-main branches. This caused IsDevelopment() to return true, registering local NuGet modules (UploadPackagesToLocalNuGetModule) that depend on PackagePathsParserModule which wasn't registered in that code path.

Fix

Modified Program.cs to use BuildSystemDetector.Instance.IsKnownBuildAgent to distinguish:

Environment IsDevelopment IsKnownBuildAgent Modules Registered
Local dev true false Local NuGet modules
CI main false true NuGet + Release modules
CI PR true true Neither (just test/build)

The BuildSystemDetector already exists and detects CI via environment variables like GITHUB_ACTIONS, TF_BUILD, GITLAB_CI, etc.

Test plan

🤖 Generated with Claude Code

@thomhurst

Copy link
Copy Markdown
Owner Author

Summary

Fixes CI PR builds by preventing local NuGet modules from being registered when running in CI environments.

Critical Issues

None found ✅

Suggestions

Logic clarity improvement:
The current code at src/ModularPipelines.Build/Program.cs:66-82 has three branches but the third case (CI PR builds) is implicit in the final else comment. Consider making the second condition more explicit by checking both IsKnownBuildAgent and !IsDevelopment(). However, the current implementation is functionally correct.

Minor: Namespace organization
The new using ModularPipelines; statement could be placed alphabetically before using ModularPipelines.Build; for consistency, though this is a style preference.

Verdict

✅ APPROVE - No critical issues

The fix correctly addresses the root cause by distinguishing between local development and CI environments using BuildSystemDetector. The dependency on PackagePathsParserModule will no longer be missing in CI PR builds since those modules will not be registered at all.

@thomhurst

Copy link
Copy Markdown
Owner Author

Summary

Fixes module registration logic to distinguish between local development and CI PR builds by using BuildSystemDetector.

Critical Issues

None found ✅

Suggestions

Logic clarity in edge case: The current implementation has three paths:

  1. Local dev (IsDevelopment + !IsKnownBuildAgent) → registers local NuGet modules
  2. Production (!IsDevelopment) → registers NuGet.org upload + release modules
  3. PR builds in CI (IsDevelopment + IsKnownBuildAgent) → registers nothing

The third case (PR builds) intentionally falls through both conditionals, which is correct but not immediately obvious. The comment "else: CI Development mode (PR builds) - don't register..." helps, but consider explicitly checking for this case to make the intent clearer:

if (isLocalDevelopment)
{
    // Local NuGet modules
}
else if (!context.HostingEnvironment.IsDevelopment())
{
    // Production modules
}
else
{
    // PR builds in CI - explicitly do nothing
    // BuildSystemDetector.Instance.IsKnownBuildAgent is true here
}

This makes it impossible to accidentally break the PR build case when refactoring.

Minor: The variable name isLocalDevelopment is excellent and self-documenting. The comments are also helpful.

Verdict

APPROVE - No critical issues

The logic is sound and correctly handles the three deployment scenarios. The use of BuildSystemDetector.Instance.IsKnownBuildAgent is the right approach given that DOTNET_ENVIRONMENT=Development is set for PR builds in the GitHub workflow (dotnet.yml:77).

The build pipeline was incorrectly registering local NuGet modules when
running in CI on PR branches. This happened because:

1. The GitHub Actions workflow sets DOTNET_ENVIRONMENT=Development for
   non-main branches (PRs)
2. IsDevelopment() returns true in this case
3. Local NuGet modules (which depend on PackagePathsParserModule) were
   registered even though they're meant only for local development

The fix uses BuildSystemDetector.Instance.IsKnownBuildAgent to distinguish
between true local development (no CI system detected) and CI runs with
Development environment. Now:

- Local development: Registers local NuGet modules (dev machine, no CI)
- CI Production (main): Registers NuGet upload and release modules
- CI Development (PRs): Registers neither (just runs tests/build)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@thomhurst

Copy link
Copy Markdown
Owner Author

Summary

Fixes pipeline failures on PR branches by preventing local NuGet modules from being registered when running in CI.

Critical Issues

1. Implementation doesn't match PR description 🚨

The PR description states:

Modified Program.cs to use BuildSystemDetector.Instance.IsKnownBuildAgent

But the actual implementation manually checks environment variables:

var isRunningInCI = \!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI"))
    || \!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"))
    || \!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TF_BUILD"))
    || \!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITLAB_CI"));

This duplicates logic from BuildSystemDetector (src/ModularPipelines/BuildSystemDetector.cs:38-48) which already checks these exact variables.

Recommendation: Use the existing BuildSystemDetector.Instance.IsKnownBuildAgent as described in the PR:

var isLocalDevelopment = context.HostingEnvironment.IsDevelopment() 
    && \!BuildSystemDetector.Instance.IsKnownBuildAgent;

This eliminates duplicate logic and ensures consistency across the codebase.

2. Checking undefined CI environment variable

The code checks for a CI environment variable which is:

  • Not documented in BuildSystemDetector (see src/ModularPipelines/BuildSystemDetector.cs:7-21)
  • Not part of the official build system detection logic
  • May not be set by all CI systems

If BuildSystemDetector should detect this variable, it should be added there, not duplicated here.

Suggestions

Comment clarity: The comment on line 71 says "Production environment (main branch CI)" but this condition (\!context.HostingEnvironment.IsDevelopment()) would also be true for any Production DOTNET_ENVIRONMENT, not just main branch CI. Consider clarifying.

Verdict

⚠️ REQUEST CHANGES - Implementation should use existing BuildSystemDetector infrastructure instead of duplicating environment variable checks.

@thomhurst thomhurst merged commit a1bb75f into main Dec 30, 2025
11 of 12 checks passed
@thomhurst thomhurst deleted the fix/pipeline-dev-mode branch December 30, 2025 16:11
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.

1 participant