Skip to content

Commit 6593ff3

Browse files
authored
chore: update to Go 1.24 [IDE-1377] (#110)
Update pact-go to 2.4.1. Update golangci-lint to 1.64.8. Lint project with updated lint rules. Fix issues with incorrect pact make targets. Improve updating of golangci-lint, pact-standalone, and pact-go, now they will be automatically updated if needed before use. Update semver rules to always at least increment patch on each commit to main, since chores previously weren't. Update CircleCI Go base image to 1.24.
1 parent c859b56 commit 6593ff3

File tree

16 files changed

+302
-137
lines changed

16 files changed

+302
-137
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ orbs:
66
executors:
77
default:
88
docker:
9-
- image: cimg/go:1.21.1
9+
- image: cimg/go:1.24
1010

1111
# Define the jobs we want to run for this project
1212
jobs:

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
with:
4040
token: ${{ github.token }}
4141
branch: main
42+
noVersionBumpBehavior: patch
4243

4344
- name: Create tag
4445
run: git tag ${{ steps.semver.outputs.next }}

.golangci.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ run:
33
- integration
44
concurrency: 4
55
issues-exit-code: 1
6-
skip-dirs:
7-
- "licenses"
8-
- "pact"
9-
- ".bin"
10-
- ".github"
11-
- ".vscode"
12-
- "build"
136
tests: true
147
timeout: 5m
158

@@ -38,7 +31,6 @@ linters-settings:
3831
gosimple:
3932
checks: ['all']
4033
govet:
41-
check-shadowing: true
4234
enable-all: true
4335
disable:
4436
- fieldalignment
@@ -110,7 +102,7 @@ linters:
110102
# TODO(errorlint): revisit
111103
#- errorlint
112104
- exhaustive
113-
- exportloopref
105+
- copyloopvar
114106
# TODO(forbidigo): revisit
115107
#- forbidigo
116108
# TODO(forcetypeassert): revisit this one! beware fragile asserts in this codebase
@@ -157,7 +149,6 @@ linters:
157149
# TODO(stylecheck): revisit in a followup; some breaking API changes
158150
#- stylecheck
159151
# NOTE: removed tagliatelle as it conflicts too much with existing API wireformats
160-
- tenv
161152
# TODO(testpackage): improve open vs closed-box testing in a followup
162153
#- testpackage
163154
- thelper
@@ -166,12 +157,21 @@ linters:
166157
# TODO(unparam): revisit
167158
#- unparam
168159
- usestdlibvars
160+
- usetesting
169161
- wastedassign
170162
- whitespace
171163
# TODO(wrapcheck): wrap errors in a followup
172164
#- wrapcheck
173165

174166
issues:
167+
exclude-dirs:
168+
- "licenses"
169+
- "pact"
170+
- ".bin"
171+
- ".github"
172+
- ".vscode"
173+
- "build"
174+
175175
exclude-rules:
176176
- path: _test\.go
177177
linters:

Makefile

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,54 @@ GOARCH = $(shell go env GOARCH)
44

55
TOOLS_BIN := $(shell pwd)/.bin
66

7-
OVERRIDE_GOCI_LINT_V := v1.60.1
7+
OVERRIDE_GOCI_LINT_V := v1.64.8
8+
GOCI_LINT_TARGETS := $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/.golangci-lint_$(OVERRIDE_GOCI_LINT_V)
9+
10+
PACT_CLI_V := v2.4.4
11+
PACT_CLI_TARGETS := $(TOOLS_BIN)/pact/bin/pact-broker $(TOOLS_BIN)/.pact_$(PACT_CLI_V)
12+
PACT_GO_V := v2.4.1
13+
PACT_GO_LIB_TARGETS := /tmp/.libpact-ffi_$(PACT_GO_V) # Only use a marker file since lib extension is either .so or .dll
14+
815
SHELL:=env PATH=$(TOOLS_BIN)/go:$(TOOLS_BIN)/pact/bin:$(PATH) $(SHELL)
916

1017
## tools: Install required tooling.
1118
.PHONY: tools
12-
tools: $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/go
13-
$(TOOLS_BIN)/golangci-lint:
14-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(OVERRIDE_GOCI_LINT_V)/install.sh | sh -s -- -b $(TOOLS_BIN)/ $(OVERRIDE_GOCI_LINT_V)
19+
tools: $(TOOLS_BIN)/go $(GOCI_LINT_TARGETS) $(PACT_CLI_TARGETS) $(PACT_GO_LIB_TARGETS)
20+
21+
$(TOOLS_BIN):
22+
@mkdir -p $(TOOLS_BIN)
1523

16-
$(TOOLS_BIN)/pact-broker:
17-
@cd $(TOOLS_BIN); curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=v2.4.4 bash; cd ../
24+
$(GOCI_LINT_TARGETS): $(TOOLS_BIN)
25+
@rm -f $(TOOLS_BIN)/.golangci-lint_*
26+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(OVERRIDE_GOCI_LINT_V)/install.sh | sh -s -- -b $(TOOLS_BIN) $(OVERRIDE_GOCI_LINT_V)
27+
@touch $(TOOLS_BIN)/.golangci-lint_$(OVERRIDE_GOCI_LINT_V)
28+
29+
$(PACT_CLI_TARGETS): $(TOOLS_BIN)
30+
@rm -f $(TOOLS_BIN)/.pact_*
31+
@cd $(TOOLS_BIN); curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=$(PACT_CLI_V) bash; cd ../
32+
@touch $(TOOLS_BIN)/.pact_$(PACT_CLI_V)
1833

1934
$(TOOLS_BIN)/go:
2035
mkdir -p ${TOOLS_BIN}/go
2136
@cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % sh -c 'GOBIN=${TOOLS_BIN}/go go install %'
37+
38+
$(PACT_GO_LIB_TARGETS): $(TOOLS_BIN)/go
39+
@rm -f /tmp/.libpact-ffi_*
2240
@GOBIN=${TOOLS_BIN}/go ${TOOLS_BIN}/go/pact-go -l DEBUG install -d /tmp
41+
@touch /tmp/.libpact-ffi_$(PACT_GO_V)
2342

2443
.PHONY: format
25-
format:
44+
format: $(GOCI_LINT_TARGETS)
2645
@gofmt -w -l -e .
27-
@$(TOOLS_BIN)/golangci-lint run --fix -v ./...
46+
@$(TOOLS_BIN)/golangci-lint run --fix ./...
2847

2948
.PHONY: lint
30-
lint: $(TOOLS_BIN)/golangci-lint
49+
lint: $(GOCI_LINT_TARGETS)
3150
ifdef CI
3251
mkdir -p test/results
3352
@$(TOOLS_BIN)/golangci-lint run --out-format junit-xml ./... > test/results/lint-tests.xml
3453
else
35-
@$(TOOLS_BIN)/golangci-lint run -v ./...
54+
@$(TOOLS_BIN)/golangci-lint run ./...
3655
endif
3756

3857
.PHONY: build
@@ -45,6 +64,8 @@ clean:
4564
@echo "Cleaning up..."
4665
@GOOS=$(GOOS) GOARCH=$(GOARCH) go clean -testcache
4766
@rm -rf $(TOOLS_BIN)
67+
@rm -f /tmp/.libpact-ffi_*
68+
@rm -f /tmp/libpact_ffi.*
4869

4970
.PHONY: test
5071
test:
@@ -62,12 +83,12 @@ smoke-test:
6283
@go test -tags=smoke
6384

6485
.PHONY: contract-test
65-
contract-test: $(TOOLS_BIN)
86+
contract-test: $(PACT_GO_LIB_TARGETS)
6687
@echo "Contract testing..."
6788
@go test -tags=contract ./...
6889

6990
.PHONY: publish-contract
70-
publish-contract: $(TOOLS_BIN)/pact-broker
91+
publish-contract: $(PACT_CLI_TARGETS)
7192
./scripts/publish-contract.sh
7293

7394
.PHONY: generate

bundle/bundle_manager_test.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package bundle_test
1818

1919
import (
2020
"bytes"
21-
"context"
2221
"os"
2322
"path/filepath"
2423
"strings"
@@ -69,7 +68,7 @@ func Test_Create(t *testing.T) {
6968
require.NoError(t, err)
7069

7170
var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
72-
bundle, err := bundleManager.Create(context.Background(),
71+
bundle, err := bundleManager.Create(t.Context(),
7372
"testRequestId",
7473
dir,
7574
sliceToChannel([]string{file}),
@@ -109,7 +108,7 @@ func Test_Create(t *testing.T) {
109108
require.NoError(t, err)
110109

111110
var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
112-
bundle, err := bundleManager.Create(context.Background(),
111+
bundle, err := bundleManager.Create(t.Context(),
113112
"testRequestId",
114113
dir,
115114
sliceToChannel([]string{file}),
@@ -153,7 +152,7 @@ func Test_Create(t *testing.T) {
153152
require.NoError(t, err)
154153

155154
var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
156-
bundle, err := bundleManager.Create(context.Background(),
155+
bundle, err := bundleManager.Create(t.Context(),
157156
"testRequestId",
158157
dir,
159158
sliceToChannel([]string{file}),
@@ -196,7 +195,7 @@ func Test_Create(t *testing.T) {
196195
)
197196
require.NoError(t, err)
198197
var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
199-
bundle, err := bundleManager.Create(context.Background(),
198+
bundle, err := bundleManager.Create(t.Context(),
200199
"testRequestId",
201200
dir,
202201
sliceToChannel([]string{file}),
@@ -234,7 +233,7 @@ func Test_Create(t *testing.T) {
234233
assert.Nil(t, err)
235234

236235
var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
237-
bundle, err := bundleManager.Create(context.Background(),
236+
bundle, err := bundleManager.Create(t.Context(),
238237
"testRequestId",
239238
tempDir,
240239
sliceToChannel([]string{file}),
@@ -287,7 +286,7 @@ func Test_Create(t *testing.T) {
287286
}
288287

289288
var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
290-
bundle, err := bundleManager.Create(context.Background(),
289+
bundle, err := bundleManager.Create(t.Context(),
291290
"testRequestId",
292291
tempDir,
293292
sliceToChannel(filesFullPaths),
@@ -340,7 +339,7 @@ func Test_Create(t *testing.T) {
340339
}
341340

342341
var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
343-
bundle, err := bundleManager.Create(context.Background(),
342+
bundle, err := bundleManager.Create(t.Context(),
344343
"testRequestId",
345344
tempDir,
346345
sliceToChannel(filesFullPaths),
@@ -391,7 +390,7 @@ func Test_Upload(t *testing.T) {
391390
bundleFileMap[documentURI] = bundleFile
392391

393392
_, err := bundleManager.Upload(
394-
context.Background(),
393+
t.Context(),
395394
"testRequestId",
396395
bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &logger, "rootPath", "bundleHash", bundleFileMap, []string{}, []string{documentURI}),
397396
bundleFileMap)
@@ -440,7 +439,7 @@ func Test_Upload(t *testing.T) {
440439
missingFiles = append(missingFiles, path)
441440

442441
_, err := bundleManager.Upload(
443-
context.Background(),
442+
t.Context(),
444443
"testRequestId",
445444
bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &logger, "rootPath", "bundleHash", bundleFileMap, []string{}, missingFiles),
446445
bundleFileMap)
@@ -470,19 +469,19 @@ func Test_IsSupported_Extensions(t *testing.T) {
470469
bundler := bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
471470

472471
t.Run("should return true for supported languages", func(t *testing.T) {
473-
supported, _ := bundler.IsSupported(context.Background(), "C:\\some\\path\\Test.java")
472+
supported, _ := bundler.IsSupported(t.Context(), "C:\\some\\path\\Test.java")
474473
assert.True(t, supported)
475474
})
476475

477476
t.Run("should return false for unsupported languages", func(t *testing.T) {
478-
supported, _ := bundler.IsSupported(context.Background(), "C:\\some\\path\\Test.rs")
477+
supported, _ := bundler.IsSupported(t.Context(), "C:\\some\\path\\Test.rs")
479478
assert.False(t, supported)
480479
})
481480

482481
t.Run("should cache supported extensions", func(t *testing.T) {
483482
path := "C:\\some\\path\\Test.rs"
484-
_, _ = bundler.IsSupported(context.Background(), path)
485-
_, _ = bundler.IsSupported(context.Background(), path)
483+
_, _ = bundler.IsSupported(t.Context(), path)
484+
_, _ = bundler.IsSupported(t.Context(), path)
486485
})
487486
}
488487

@@ -514,34 +513,33 @@ func Test_IsSupported_ConfigFiles(t *testing.T) {
514513
t.Run("should return true for supported config files", func(t *testing.T) {
515514
for _, file := range expectedConfigFiles {
516515
path := filepath.Join(dir, file)
517-
supported, _ := bundler.IsSupported(context.Background(), path)
516+
supported, _ := bundler.IsSupported(t.Context(), path)
518517
assert.True(t, supported)
519518
}
520519
})
521520
t.Run("should exclude .gitignore and .dcignore", func(t *testing.T) {
522521
for _, file := range []string{".gitignore", ".dcignore"} {
523522
path := filepath.Join(dir, file)
524-
supported, _ := bundler.IsSupported(context.Background(), path)
523+
supported, _ := bundler.IsSupported(t.Context(), path)
525524
assert.False(t, supported)
526525
}
527526
})
528527
t.Run("should return false for unsupported config files", func(t *testing.T) {
529528
path := "C:\\some\\path\\.unsupported"
530-
supported, _ := bundler.IsSupported(context.Background(), path)
529+
supported, _ := bundler.IsSupported(t.Context(), path)
531530
assert.False(t, supported)
532531
})
533532

534533
t.Run("should cache supported extensions", func(t *testing.T) {
535534
path := "C:\\some\\path\\Test.rs"
536-
_, _ = bundler.IsSupported(context.Background(), path)
537-
_, _ = bundler.IsSupported(context.Background(), path)
535+
_, _ = bundler.IsSupported(t.Context(), path)
536+
_, _ = bundler.IsSupported(t.Context(), path)
538537
})
539538
}
540539

541540
func setup(t *testing.T) string {
542541
t.Helper()
543-
dir, err := os.MkdirTemp("", "createFileOfSize")
544-
require.NoError(t, err)
542+
dir := t.TempDir()
545543
return dir
546544
}
547545

bundle/bundle_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ package bundle_test
1818

1919
import (
2020
"bytes"
21-
"context"
2221
"crypto/sha256"
2322
"encoding/hex"
2423
"fmt"
25-
"golang.org/x/net/html/charset"
2624
"io"
2725
"os"
2826
"testing"
@@ -31,6 +29,7 @@ import (
3129
"github.com/rs/zerolog"
3230
"github.com/stretchr/testify/assert"
3331
"github.com/stretchr/testify/require"
32+
"golang.org/x/net/html/charset"
3433

3534
"github.com/snyk/code-client-go/bundle"
3635
"github.com/snyk/code-client-go/internal/deepcode"
@@ -83,7 +82,7 @@ func Test_UploadBatch(t *testing.T) {
8382
b := bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &testLogger, "testRootPath", "testBundleHash", map[string]deepcode.BundleFile{}, []string{}, []string{})
8483

8584
emptyBundle := &bundle.Batch{}
86-
err := b.UploadBatch(context.Background(), "testRequestId", emptyBundle)
85+
err := b.UploadBatch(t.Context(), "testRequestId", emptyBundle)
8786
assert.NoError(t, err)
8887
})
8988

@@ -102,7 +101,7 @@ func Test_UploadBatch(t *testing.T) {
102101
mockErrorReporter := mocks.NewMockErrorReporter(ctrl)
103102
b := bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &testLogger, "testRootPath", "testBundleHash", map[string]deepcode.BundleFile{}, []string{}, []string{})
104103

105-
err := b.UploadBatch(context.Background(), "testRequestId", bundleWithFiles)
104+
err := b.UploadBatch(t.Context(), "testRequestId", bundleWithFiles)
106105
assert.NoError(t, err)
107106
})
108107

@@ -125,10 +124,10 @@ func Test_UploadBatch(t *testing.T) {
125124
mockErrorReporter := mocks.NewMockErrorReporter(ctrl)
126125
b := bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &testLogger, "testRootPath", "testBundleHash", map[string]deepcode.BundleFile{}, []string{}, []string{})
127126

128-
err := b.UploadBatch(context.Background(), "testRequestId", bundleWithFiles)
127+
err := b.UploadBatch(t.Context(), "testRequestId", bundleWithFiles)
129128
require.NoError(t, err)
130129
oldHash := b.GetBundleHash()
131-
err = b.UploadBatch(context.Background(), "testRequestId", bundleWithMultipleFiles)
130+
err = b.UploadBatch(t.Context(), "testRequestId", bundleWithMultipleFiles)
132131
require.NoError(t, err)
133132
newHash := b.GetBundleHash()
134133
assert.NotEqual(t, oldHash, newHash)
@@ -153,7 +152,7 @@ func Test_RawContentBatch(t *testing.T) {
153152

154153
require.NoError(t, batchErr)
155154
oldHash := b.GetBundleHash()
156-
err := b.UploadBatch(context.Background(), "testRequestId", bundleFromRawContent)
155+
err := b.UploadBatch(t.Context(), "testRequestId", bundleFromRawContent)
157156
require.NoError(t, err)
158157
newHash := b.GetBundleHash()
159158
assert.NotEqual(t, oldHash, newHash)

0 commit comments

Comments
 (0)