From cd2cc02814299e8d15110b095f6f0b2fd1fd0b6e Mon Sep 17 00:00:00 2001 From: Fabio Bonelli Date: Tue, 20 Feb 2024 11:54:11 +0100 Subject: [PATCH] feat: use Go 1.21 and adapt code --- .github/workflows/lint.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/test_and_publish_docker_image.yml | 2 +- Dockerfile | 2 +- cmd/download_publishers.go | 6 +++--- common/lists_test.go | 4 ++-- common/publisher.go | 4 ++-- git/repo_activity.go | 3 +-- go.mod | 2 +- go.sum | 1 + 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 553f354d..ec9ec038 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,5 +7,5 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '1.18' + go-version: '1.21' - uses: golangci/golangci-lint-action@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7013e521..23a7a5c4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: ^1.18 + go-version: ^1.21 id: go - name: Checkout diff --git a/.github/workflows/test_and_publish_docker_image.yml b/.github/workflows/test_and_publish_docker_image.yml index 177863a8..75dae3e9 100644 --- a/.github/workflows/test_and_publish_docker_image.yml +++ b/.github/workflows/test_and_publish_docker_image.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-go@v3 with: - go-version: '1.18' + go-version: '1.21' - run: go build - run: go test -race ./... diff --git a/Dockerfile b/Dockerfile index aa9f1f05..102a857f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18 as build +FROM golang:1.21 as build WORKDIR /src COPY . . diff --git a/cmd/download_publishers.go b/cmd/download_publishers.go index d1de5b19..12a29090 100644 --- a/cmd/download_publishers.go +++ b/cmd/download_publishers.go @@ -1,7 +1,7 @@ package cmd import ( - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -33,7 +33,7 @@ var downloadPublishersCmd = &cobra.Command{ Run: func(_ *cobra.Command, args []string) { var publishers []common.Publisher if _, err := os.Stat(args[1]); err == nil { - data, err := ioutil.ReadFile(args[1]) + data, err := os.ReadFile(args[1]) if err != nil { log.Fatalf("error in reading %s: %v", args[1], err) } @@ -45,7 +45,7 @@ var downloadPublishersCmd = &cobra.Command{ log.Fatal(err) } defer resp.Body.Close() - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) } diff --git a/common/lists_test.go b/common/lists_test.go index 6c5a054e..7468850d 100644 --- a/common/lists_test.go +++ b/common/lists_test.go @@ -2,7 +2,7 @@ package common import ( "bytes" - "io/ioutil" + "io" "testing" "github.com/stretchr/testify/assert" @@ -16,7 +16,7 @@ type FakeReadFiler struct { func (f FakeReadFiler) ReadFile(filename string) ([]byte, error) { buf := bytes.NewBufferString(f.Str) - return ioutil.ReadAll(buf) + return io.ReadAll(buf) } func TestReadPublishers(t *testing.T) { diff --git a/common/publisher.go b/common/publisher.go index aef03f56..b7a13275 100644 --- a/common/publisher.go +++ b/common/publisher.go @@ -2,13 +2,13 @@ package common import ( "fmt" - "io/ioutil" + "os" url "github.com/italia/publiccode-crawler/v4/internal" "gopkg.in/yaml.v2" ) -var fileReaderInject = ioutil.ReadFile +var fileReaderInject = os.ReadFile type Publisher struct { ID string `yaml:"id"` diff --git a/git/repo_activity.go b/git/repo_activity.go index a9ddbf9f..0d595876 100644 --- a/git/repo_activity.go +++ b/git/repo_activity.go @@ -2,7 +2,6 @@ package git import ( "errors" - "io/ioutil" "os" "path/filepath" "time" @@ -242,7 +241,7 @@ func extractOldestCommitDate(cIter object.CommitIter) time.Time { } func ranges(name string, value float64) float64 { - data, err := ioutil.ReadFile("vitality-ranges.yml") + data, err := os.ReadFile("vitality-ranges.yml") if err != nil { log.Error(err) } diff --git a/go.mod b/go.mod index d5cba91c..5bff3a25 100644 --- a/go.mod +++ b/go.mod @@ -73,4 +73,4 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect ) -go 1.18 +go 1.21 diff --git a/go.sum b/go.sum index 569ad0cd..904d911d 100644 --- a/go.sum +++ b/go.sum @@ -1427,6 +1427,7 @@ golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=