-
Notifications
You must be signed in to change notification settings - Fork 163
Description
Summary
Currently, run_if_changed and skip_if_only_changed are mutually exclusive in job configuration, enforced by validation in the validateTriggering function. This limitation prevents users from creating more sophisticated job triggering logic that could benefit from combining both conditions.
Current Implementation
As of commit 419f5e43, the validation in pkg/config/config.go prevents jobs from specifying both fields:
if job.RunIfChanged != "" && job.SkipIfOnlyChanged != "" {
return fmt.Errorf("job %s declares run_if_changed and skip_if_only_changed, which are mutually exclusive", job.Name)
}Motivation and Use Case
There are legitimate scenarios where combining both conditions would provide more precise control over job execution:
Example Scenario: A comprehensive test suite that should:
- Run when core application files change (
run_if_changed: "^(src/|tests/)") - BUT skip when only documentation files change (
skip_if_only_changed: "^docs/")
Current Workaround Limitations:
- Using only
run_if_changedcannot exclude documentation-only changes - Using only
skip_if_only_changedcannot ensure the job runs for specific critical paths - Complex regex patterns become unwieldy and hard to maintain
Proposed Enhancement
Remove the mutual exclusivity constraint and implement combined logic where:
-
Both conditions must be satisfied for the job to run:
- At least one changed file matches
run_if_changedpattern - AND NOT all changed files match
skip_if_only_changedpattern
- At least one changed file matches
-
Logical precedence:
- If
run_if_changedis specified, at least one file must match it - If
skip_if_only_changedis specified, not all files should match it - Both conditions are evaluated independently and combined with AND logic
- If
Implementation Considerations
The change would involve:
- Remove validation constraint in
validateTriggeringfunction - Update job execution logic in
RegexpChangeMatchermethods to handle both conditions - Maintain backward compatibility - existing configurations with only one field should continue working unchanged
- Add comprehensive tests for the combined logic scenarios
Benefits
- More granular control over job triggering based on file changes
- Reduced CI resource usage by avoiding unnecessary job runs
- Simplified configuration compared to complex single-regex solutions
- Better developer experience with more intuitive job triggering rules
Backward Compatibility
This change is fully backward compatible as it only removes a restriction. Existing jobs using either run_if_changed or skip_if_only_changed individually will continue to work exactly as before.
Related Work
This enhancement addresses similar needs discussed in issue #151 where users wanted more precise control over when jobs run based on file changes, particularly for skipping CI when only documentation changes are present.