@@ -18,8 +18,9 @@ type BuildGoProgramOptions struct {
18
18
// Directory that will have a temporary directory created underneath
19
19
BaseDir string
20
20
// If not set, not put in go.mod which means go mod tidy will automatically
21
- // use latest. If set and does not start with a "v", it is assumed to be a
22
- // path, otherwise it is a specific version.
21
+ // use latest. If set and contains a slash, it is assumed to be a path,
22
+ // otherwise it is a specific version (with leading "v" is trimmed if
23
+ // present).
23
24
Version string
24
25
// The SDK Repository import to use. If unspecified we default to go.temporal.io/sdk
25
26
// If specified version must also be provided
@@ -79,22 +80,22 @@ func BuildGoProgram(ctx context.Context, options BuildGoProgramOptions) (*GoProg
79
80
goMod := options .GoModContents
80
81
// If a version is specified, overwrite the SDK to use that
81
82
if options .Version != "" || options .SDKRepository != "" {
82
- // If version does not start with a "v " we assume path unless the SDK repository is provided
83
+ // If version has a "/ " we assume path unless the SDK repository is provided
83
84
if options .SDKRepository != "" {
84
85
if options .Version == "" {
85
86
return nil , errors .New ("Version must be provided alongside SDKRepository" )
86
87
}
87
- goMod += fmt .Sprintf ("\n replace %s => %s %s" , sdkImport , options .SDKRepository , options .Version )
88
- } else if strings .HasPrefix (options .Version , "v " ) {
89
- goMod += fmt .Sprintf ("\n replace %s => %s %s" , sdkImport , sdkImport , options .Version )
88
+ goMod += fmt .Sprintf ("\n replace %s => %s v %s" , sdkImport , options .SDKRepository , strings . TrimPrefix ( options .Version , "v" ) )
89
+ } else if ! strings .Contains (options .Version , "/ " ) {
90
+ goMod += fmt .Sprintf ("\n replace %s => %s v %s" , sdkImport , sdkImport , strings . TrimPrefix ( options .Version , "v" ) )
90
91
} else {
91
92
absVersion , err := filepath .Abs (options .Version )
92
93
if err != nil {
93
- return nil , fmt .Errorf ("version does not start with 'v ' and cannot get abs dir: %w" , err )
94
+ return nil , fmt .Errorf ("version has a '/ ' and cannot get abs dir: %w" , err )
94
95
}
95
96
relVersion , err := filepath .Rel (dir , absVersion )
96
97
if err != nil {
97
- return nil , fmt .Errorf ("version does not start with 'v ' and unable to relativize: %w" , err )
98
+ return nil , fmt .Errorf ("version has a '/ ' and unable to relativize: %w" , err )
98
99
}
99
100
goMod += fmt .Sprintf ("\n replace %s => %s" , sdkImport , filepath .ToSlash (relVersion ))
100
101
}
0 commit comments