Verified Solution

[gitlab-org/gitlab] Revisit include merging behaviour for spec.inputs

Sponsored Content
### ROOT CAUSE The issue arises because the current implementation of `include` in `spec.inputs` does not allow overriding or deleting keys from included configurations. This results in a `DuplicateInputError` when duplicate keys are encountered, which is not intuitive and limits flexibility. The behavior is inconsistent with the workflow's `include` directive, which allows merging with overrides. The root cause is the lack of a mechanism to handle key conflicts during inclusion. ### CODE FIX Modify the `InputSpec` class to allow overrides and deletions during inclusion. Introduce a new option, `merge_strategy`, which can be set to `:override` or `:delete` to handle conflicts. Here's the fix: ```ruby # lib/gitlab/ci/configuration/specs/inputs_spec.rb class InputSpec < BaseSpec # ... existing code ... def self.merge(inputs, other_inputs, merge_strategy: :error) merged = {} inputs.each do |key, value| merged[key] = value end other_inputs.each do |key, value| case merge_strategy when :override merged[key] = value when :delete merged.delete(key) if merged.key?(key) when :error raise DuplicateInputError, "Duplicate input definition for #{key}" if merged.key?(key) merged[key] = value end end merged end end ``` Update the `parse` method to handle the `merge_strategy` option in the `include` directive: ```ruby # lib/gitlab/ci/configuration/specs/inputs_spec.rb def parse_include(node) # ... existing code ... # Add handling for merge_strategy if node.has_key?(:merge_strategy) @merge_strategy = node[:merge_strategy] end # ... rest of the code ... ``` This change allows users to specify how to handle conflicts during inclusion, providing more flexibility and resolving the issue.
Deploy on DigitalOcean ($200 Credit)

Related Fixes

[golang/go] runtime: Windows crash with Go 1.26.0, 1.26.1
[StackOverflow/docker] Best practice to build flutter docker image on mac non-x86 for use on x86-64 machine
[golang/go] cmd/cgo/internal/test: build error on macOS 26 in Go 1.25 [1.25 backport]