@@ -53,9 +53,9 @@ func (b Builder) Build(ctx context.Context) error {
5353
5454	b .log .Infof ("Adding replace directives" )
5555
56- 	err  =  b .addReplaceDirectives (ctx )
56+ 	err  =  b .addToGoMod (ctx )
5757	if  err  !=  nil  {
58- 		return  fmt .Errorf ("add replace directives : %w" , err )
58+ 		return  fmt .Errorf ("add to go.mod : %w" , err )
5959	}
6060
6161	b .log .Infof ("Running go mod tidy" )
@@ -103,25 +103,56 @@ func (b Builder) clone(ctx context.Context) error {
103103	return  nil 
104104}
105105
106- func  (b  Builder ) addReplaceDirectives (ctx  context.Context ) error  {
106+ func  (b  Builder ) addToGoMod (ctx  context.Context ) error  {
107107	for  _ , plugin  :=  range  b .cfg .Plugins  {
108- 		if  plugin .Path  ==  ""  {
108+ 		if  plugin .Path  !=  ""  {
109+ 			err  :=  b .addReplaceDirective (ctx , plugin )
110+ 			if  err  !=  nil  {
111+ 				return  err 
112+ 			}
113+ 
109114			continue 
110115		}
111116
112- 		replace  :=  fmt .Sprintf ("%s=%s" , plugin .Module , plugin .Path )
117+ 		err  :=  b .goGet (ctx , plugin )
118+ 		if  err  !=  nil  {
119+ 			return  err 
120+ 		}
121+ 	}
122+ 
123+ 	return  nil 
124+ }
113125
114- 		cmd  :=  exec .CommandContext (ctx , "go" , "mod" , "edit" , "-replace" , replace )
115- 		cmd .Dir  =  b .repo 
126+ func  (b  Builder ) goGet (ctx  context.Context , plugin  * Plugin ) error  {
127+ 	//nolint:gosec // the variables are user related. 
128+ 	cmd  :=  exec .CommandContext (ctx , "go" , "get" , plugin .Module + "@" + plugin .Version )
129+ 	cmd .Dir  =  b .repo 
116130
117- 		 b .log .Infof ("run: %s" , strings .Join (cmd .Args , " " ))
131+ 	b .log .Infof ("run: %s" , strings .Join (cmd .Args , " " ))
118132
119- 		 output , err  :=  cmd .CombinedOutput ()
120- 		 if  err  !=  nil  {
121- 			 b .log .Warnf (string (output ))
133+ 	output , err  :=  cmd .CombinedOutput ()
134+ 	if  err  !=  nil  {
135+ 		b .log .Warnf (string (output ))
122136
123- 			return  fmt .Errorf ("%s: %w" , strings .Join (cmd .Args , " " ), err )
124- 		}
137+ 		return  fmt .Errorf ("%s: %w" , strings .Join (cmd .Args , " " ), err )
138+ 	}
139+ 
140+ 	return  nil 
141+ }
142+ 
143+ func  (b  Builder ) addReplaceDirective (ctx  context.Context , plugin  * Plugin ) error  {
144+ 	replace  :=  fmt .Sprintf ("%s=%s" , plugin .Module , plugin .Path )
145+ 
146+ 	cmd  :=  exec .CommandContext (ctx , "go" , "mod" , "edit" , "-replace" , replace )
147+ 	cmd .Dir  =  b .repo 
148+ 
149+ 	b .log .Infof ("run: %s" , strings .Join (cmd .Args , " " ))
150+ 
151+ 	output , err  :=  cmd .CombinedOutput ()
152+ 	if  err  !=  nil  {
153+ 		b .log .Warnf (string (output ))
154+ 
155+ 		return  fmt .Errorf ("%s: %w" , strings .Join (cmd .Args , " " ), err )
125156	}
126157
127158	return  nil 
0 commit comments