@@ -4,11 +4,14 @@ import (
44 "crypto/sha256"
55 "encoding/binary"
66 "encoding/hex"
7+ "fmt"
8+ "strconv"
79 "strings"
810
911 "golang.org/x/crypto/sha3"
1012)
1113
14+ // Deprecated: Use GenerateExecutionIDWithTriggerIndex instead.
1215func EncodeExecutionID (workflowID , eventID string ) (string , error ) {
1316 s := sha256 .New ()
1417 _ , err := s .Write ([]byte (workflowID ))
@@ -24,6 +27,34 @@ func EncodeExecutionID(workflowID, eventID string) (string, error) {
2427 return hex .EncodeToString (s .Sum (nil )), nil
2528}
2629
30+ func GenerateExecutionIDWithTriggerIndex (workflowID , triggerEventID string , triggerIndex int ) (string , error ) {
31+ s := sha256 .New ()
32+ _ , err := s .Write ([]byte (workflowID ))
33+ if err != nil {
34+ return "" , err
35+ }
36+
37+ _ , err = s .Write ([]byte (triggerEventID ))
38+ if err != nil {
39+ return "" , err
40+ }
41+
42+ _ , err = s .Write ([]byte (strconv .Itoa (triggerIndex )))
43+ if err != nil {
44+ return "" , err
45+ }
46+
47+ return hex .EncodeToString (s .Sum (nil )), nil
48+ }
49+
50+ func GetTriggerReferenceID (triggerIndex int ) string {
51+ return fmt .Sprintf ("trigger_%d" , triggerIndex )
52+ }
53+
54+ func GetTriggerIndexFromReferenceID (referenceID string ) (int , error ) {
55+ return strconv .Atoi (strings .TrimPrefix (referenceID , "trigger_" ))
56+ }
57+
2758func GenerateWorkflowIDFromStrings (owner string , name string , workflow []byte , config []byte , secretsURL string ) (string , error ) {
2859 ownerWithoutPrefix := owner
2960 if strings .HasPrefix (owner , "0x" ) {
0 commit comments