Skip to content

feat(cli): add --env-file flag to luca run#88

Merged
albertodebortoli merged 8 commits into
mainfrom
feature/env-file-support
Jun 8, 2026
Merged

feat(cli): add --env-file flag to luca run#88
albertodebortoli merged 8 commits into
mainfrom
feature/env-file-support

Conversation

@albertodebortoli

@albertodebortoli albertodebortoli commented Jun 8, 2026

Copy link
Copy Markdown
Member

Description

  • Adds --env-file <path> option to the run command, defaulting to .env in the current directory when present.
  • Env vars from the file are injected into every task with lower priority than the pipeline/task env: blocks in the YAML: process env → env file → pipeline env → task env.
  • Missing default file is silently skipped; a missing explicitly-passed path fails with a clear error.
  • Env file vars are also available to when: condition evaluation and shown in --dry-run output.

Type of Change

  • Feature

How Has This Been Tested?

  • Added / updated unit tests
  • Manually tested locally (describe)
  • Tested on macOS (arch: arm64)

New tests added:

  • EnvFileLoaderTests (9 tests): valid KEY=VALUE pairs, quoted values, comment lines, empty lines, value with = in it (URL), missing file, line without =, error descriptions.
  • PipelineRunnerTests (6 new tests): env file vars passed to subprocess, pipeline env overrides env file, task env overrides env file, empty env file is a no-op, env file vars visible to when: condition evaluation.

swift test — 504 tests passing.

Checklist

  • Swift code builds locally (swift build)
  • Tests pass locally (swift test)
  • Code style / formatting respected
  • Documentation updated (README / comments)

Breaking Changes?

  • No

Additional Notes

File format — standard dotenv: one KEY=VALUE pair per line, # comments, blank lines ignored, surrounding single/double quotes on values are stripped.

Priority order (lowest → highest): inherited process env → .env file → pipeline YAML env: block → task YAML env: block.

Introduces EnvFileLoader with EnvFileLoading protocol for loading flat
YAML env-var files into [String: String] dictionaries, with typed errors
for missing files and non-flat/non-string YAML content. Includes mock
and full Swift Testing test suite (7 tests).
Introduces EnvFileLoaderFileManaging protocol and injects it into
EnvFileLoader, replacing direct Data(contentsOf:) usage. Extends
FileManager to conform to the protocol. Also adds @testable import
LucaFoundation to the test file and makes EnvFileLoaderMock final.
Adds envFileEnvironment parameter to PipelineRunning protocol required
method and PipelineRunner.run(), with merge order: process env ← env-file
env ← pipeline-level env ← task-level env. Convenience overloads forward
with envFileEnvironment: [:] for backward compatibility.
Wires up EnvFileLoader into RunCommand: resolves the env file path (defaulting to luca-env-vars.yml), passes envFileEnvironment to PipelineRunner, and surfaces it in dry-run output with sorted keys and as the base context layer for when-condition evaluation.
…nv-file loading

- Inject fileManager into EnvFileLoader for consistency with other components
- Remove redundant fileExists pre-check that had TOCTOU race condition
- Catch fileNotFound from load() directly instead of checking file existence first
- Add string-only constraint to --env-file help text noting that unquoted
  numbers and booleans are not accepted
- Remove orphaned EnvFileLoaderMock that was never used by tests
- Add test_load_booleanValue_throwsInvalidFormat to cover YAML boolean
  literals like 'true'/'false'
- Simplify fileNotFound error handling in RunCommand.run() using binding
  pattern with where guard
@albertodebortoli albertodebortoli added this to the 0.20.0 milestone Jun 8, 2026
@albertodebortoli albertodebortoli added the feature New feature or enhancement label Jun 8, 2026
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ipelineCore/Core/EnvFileLoader/EnvFileLoader.swift 96.42% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@albertodebortoli albertodebortoli marked this pull request as ready for review June 8, 2026 11:01
@albertodebortoli albertodebortoli merged commit c34d308 into main Jun 8, 2026
3 checks passed
@albertodebortoli albertodebortoli deleted the feature/env-file-support branch June 8, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant