-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmerge.go
More file actions
56 lines (50 loc) · 2.02 KB
/
Copy pathmerge.go
File metadata and controls
56 lines (50 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package sequenceutils
import (
"fmt"
"reflect"
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
"github.com/smartcontractkit/chainlink-deployments-framework/operations"
)
// ExecuteOnChainSequenceAndMerge executes a sequence and merges the output into the given OnChainOutput.
// On error, the accumulated agg is returned unchanged.
//
// Env metadata is a single record per deployment. If both agg and the sequence output set env metadata
// with different values, merge fails with deployment.ErrInvalidConfig rather than silently overwriting.
// Re-merging the same env (shared pointer or equal Metadata value) is allowed.
func ExecuteOnChainSequenceAndMerge[IN any, DEP any](
b operations.Bundle,
deps DEP,
seq *operations.Sequence[IN, OnChainOutput, DEP],
input IN,
agg OnChainOutput,
) (OnChainOutput, error) {
if seq == nil {
return agg, fmt.Errorf("%w: sequence is required", deployment.ErrInvalidConfig)
}
report, err := operations.ExecuteSequence(b, seq, deps, input)
if err != nil {
return agg, fmt.Errorf("failed to execute %s: %w", seq.ID(), err)
}
if envMetadataConflicts(agg.Metadata.Env, report.Output.Metadata.Env) {
return agg, fmt.Errorf("%w: conflicting env metadata from sequence %s",
deployment.ErrInvalidConfig, seq.ID())
}
agg.BatchOps = append(agg.BatchOps, report.Output.BatchOps...)
agg.Metadata.Addresses = append(agg.Metadata.Addresses, report.Output.Metadata.Addresses...)
agg.Metadata.Contracts = append(agg.Metadata.Contracts, report.Output.Metadata.Contracts...)
agg.Metadata.Chains = append(agg.Metadata.Chains, report.Output.Metadata.Chains...)
if report.Output.Metadata.Env != nil {
agg.Metadata.Env = report.Output.Metadata.Env
}
return agg, nil
}
func envMetadataConflicts(existing, incoming *datastore.EnvMetadata) bool {
if existing == nil || incoming == nil {
return false
}
if existing == incoming {
return false
}
return !reflect.DeepEqual(existing.Metadata, incoming.Metadata)
}