@@ -53,9 +53,9 @@ func (b Builder) Build(ctx context.Context) error {
53
53
54
54
b .log .Infof ("Adding replace directives" )
55
55
56
- err = b .addReplaceDirectives (ctx )
56
+ err = b .addToGoMod (ctx )
57
57
if err != nil {
58
- return fmt .Errorf ("add replace directives : %w" , err )
58
+ return fmt .Errorf ("add to go.mod : %w" , err )
59
59
}
60
60
61
61
b .log .Infof ("Running go mod tidy" )
@@ -103,25 +103,56 @@ func (b Builder) clone(ctx context.Context) error {
103
103
return nil
104
104
}
105
105
106
- func (b Builder ) addReplaceDirectives (ctx context.Context ) error {
106
+ func (b Builder ) addToGoMod (ctx context.Context ) error {
107
107
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
+
109
114
continue
110
115
}
111
116
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
+ }
113
125
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
116
130
117
- b .log .Infof ("run: %s" , strings .Join (cmd .Args , " " ))
131
+ b .log .Infof ("run: %s" , strings .Join (cmd .Args , " " ))
118
132
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 ))
122
136
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 )
125
156
}
126
157
127
158
return nil
0 commit comments