@@ -2,6 +2,8 @@ package internal
2
2
3
3
import (
4
4
"context"
5
+ "crypto/sha256"
6
+ "encoding/base64"
5
7
"fmt"
6
8
"io"
7
9
"os"
@@ -12,6 +14,8 @@ import (
12
14
"time"
13
15
"unicode"
14
16
17
+ "golang.org/x/mod/sumdb/dirhash"
18
+
15
19
"github.com/golangci/golangci-lint/v2/pkg/logutils"
16
20
)
17
21
@@ -173,15 +177,17 @@ func (b Builder) goModTidy(ctx context.Context) error {
173
177
}
174
178
175
179
func (b Builder ) goBuild (ctx context.Context , binaryName string ) error {
176
- now := time .Now ().UTC ()
180
+ version , err := b .createVersion (b .cfg .Version )
181
+ if err != nil {
182
+ return fmt .Errorf ("custom version: %w" , err )
183
+ }
184
+
185
+ b .log .Infof ("version: %s" , version )
177
186
178
187
//nolint:gosec // the variable is sanitized.
179
188
cmd := exec .CommandContext (ctx , "go" , "build" ,
180
189
"-ldflags" ,
181
- fmt .Sprintf (
182
- "-s -w -X 'main.version=%s' -X 'main.date=%s'" ,
183
- createVersion (b .cfg .Version , now ), now .String (),
184
- ),
190
+ fmt .Sprintf ("-s -w -X 'main.version=%s' -X 'main.date=%s'" , version , time .Now ().UTC ().String ()),
185
191
"-o" , binaryName ,
186
192
"./cmd/golangci-lint" ,
187
193
)
@@ -243,8 +249,28 @@ func (b Builder) getBinaryName() string {
243
249
return name
244
250
}
245
251
246
- func createVersion (orig string , now time.Time ) string {
247
- return fmt .Sprintf ("%s-custom-gcl-%d" , sanitizeVersion (orig ), now .UnixNano ())
252
+ func (b Builder ) createVersion (orig string ) (string , error ) {
253
+ hash := sha256 .New ()
254
+
255
+ for _ , plugin := range b .cfg .Plugins {
256
+ if plugin .Path == "" {
257
+ continue
258
+ }
259
+
260
+ dh , err := dirhash .HashDir (plugin .Path , "" , dirhash .DefaultHash )
261
+ if err != nil {
262
+ return "" , fmt .Errorf ("hash plugin directory: %w" , err )
263
+ }
264
+
265
+ b .log .Infof ("%s: %s" , plugin .Path , dh )
266
+
267
+ hash .Write ([]byte (dh ))
268
+ }
269
+
270
+ return fmt .Sprintf ("%s-custom-gcl-%s" ,
271
+ sanitizeVersion (orig ),
272
+ sanitizeVersion (base64 .URLEncoding .EncodeToString (hash .Sum (nil ))),
273
+ ), nil
248
274
}
249
275
250
276
func sanitizeVersion (v string ) string {
0 commit comments