File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -173,12 +173,14 @@ func (b Builder) goModTidy(ctx context.Context) error {
173173}
174174
175175func (b Builder ) goBuild (ctx context.Context , binaryName string ) error {
176+ now := time .Now ().UTC ()
177+
176178 //nolint:gosec // the variable is sanitized.
177179 cmd := exec .CommandContext (ctx , "go" , "build" ,
178180 "-ldflags" ,
179181 fmt .Sprintf (
180- "-s -w -X 'main.version=%s-custom-gcl ' -X 'main.date=%s'" ,
181- sanitizeVersion (b .cfg .Version ), time . Now (). UTC () .String (),
182+ "-s -w -X 'main.version=%s' -X 'main.date=%s'" ,
183+ createVersion (b .cfg .Version , now ), now .String (),
182184 ),
183185 "-o" , binaryName ,
184186 "./cmd/golangci-lint" ,
@@ -241,6 +243,10 @@ func (b Builder) getBinaryName() string {
241243 return name
242244}
243245
246+ func createVersion (orig string , now time.Time ) string {
247+ return fmt .Sprintf ("%s-custom-gcl-%d" , sanitizeVersion (orig ), now .UnixNano ())
248+ }
249+
244250func sanitizeVersion (v string ) string {
245251 fn := func (c rune ) bool {
246252 return ! unicode .IsLetter (c ) && ! unicode .IsNumber (c ) && c != '.' && c != '/'
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ package internal
22
33import (
44 "testing"
5+ "time"
56
67 "github.com/stretchr/testify/assert"
8+ "github.com/stretchr/testify/require"
79)
810
911func Test_sanitizeVersion (t * testing.T ) {
@@ -54,3 +56,12 @@ func Test_sanitizeVersion(t *testing.T) {
5456 })
5557 }
5658}
59+
60+ func Test_createVersion (t * testing.T ) {
61+ parse , err := time .Parse (time .RFC3339Nano , "2010-02-04T21:00:57.123456789+08:00" )
62+ require .NoError (t , err )
63+
64+ version := createVersion ("1.2.3" , parse )
65+
66+ assert .Equal (t , "1.2.3-custom-gcl-1265288457123456789" , version )
67+ }
You can’t perform that action at this time.
0 commit comments