Skip to content

feat(pipeline): add when: conditional task execution#83

Merged
albertodebortoli merged 4 commits into
mainfrom
feature/pipeline-parameters
May 24, 2026
Merged

feat(pipeline): add when: conditional task execution#83
albertodebortoli merged 4 commits into
mainfrom
feature/pipeline-parameters

Conversation

@albertodebortoli
Copy link
Copy Markdown
Member

@albertodebortoli albertodebortoli commented May 24, 2026

Description

Adds an optional when: field to pipeline tasks. When present, the runner evaluates the condition before executing the task — if the condition is false the task is skipped (a notice is printed, no error is thrown). This enables parameter-driven pipelines where certain tasks are optional, e.g. upload only when --param upload=true is passed.

Three expression forms are supported:

tasks:
  - name: Upload artifact
    command: upload --file build.zip
    when: ${upload} == true          # equality

  - name: Clean debug artifacts
    command: rm -rf debug/
    when: ${flavor} != release       # inequality

  - name: Run integration tests
    command: swift test --filter Integration
    when: ${run_integration}         # presence (truthy check)

${name} tokens are resolved from parameters (highest priority), then task env, then pipeline env. Unknown tokens resolve to "" (falsy). Falsy values: "false", "0", "no", empty string.

Dry-run output shows the condition and its evaluated outcome:

  Task 2: Upload
    Command: upload --file build.zip
    Tools:   upload ✓
    When:    ${upload} == true → skip

The pipeline summary counts only executed tasks (skipped tasks excluded).

Builds on the pipeline parameters feature (PR #82--param KEY=VALUE support).

Type of Change

  • Feature

How Has This Been Tested?

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

New test file:

  • Tests/Core/TaskConditionEvaluatorTests.swift — 20 tests covering equality, inequality, presence, substitution, unknown tokens, whitespace trimming, malformed expressions

Extended existing tests:

  • PipelineRunnerTests — 4 new tests: passing condition executes, failing condition skips, mixed skip/execute, nil when always executes
  • PipelineLoaderTestswhen: field decoded from YAML fixture

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

TaskConditionEvaluator is a new standalone component following the protocol-oriented DI pattern. PipelineRunner receives it via an internal init for test injection; the public init(printer:) uses the default implementation.

@albertodebortoli albertodebortoli added this to the 0.19.0 milestone May 24, 2026
@albertodebortoli albertodebortoli added the feature New feature or enhancement label May 24, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@albertodebortoli albertodebortoli force-pushed the feature/pipeline-parameters branch from 1e96614 to 79479dd Compare May 24, 2026 17:22
@albertodebortoli albertodebortoli marked this pull request as ready for review May 24, 2026 17:26
@albertodebortoli albertodebortoli merged commit 3bb73c9 into main May 24, 2026
3 checks passed
@albertodebortoli albertodebortoli deleted the feature/pipeline-parameters branch May 24, 2026 17:27
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