Skip to content

Commit

Permalink
Update Go version to 1.19 (#85)
Browse files Browse the repository at this point in the history
* ci: update action versions
* build: update go version to 1.18
* chore(deps): update dependencies to make build pass on Go 1.18
* ci: update Go to 1.18
* ci: update golangci-lint to make lint pass on Go 1.18
* chore: fix lint violations
* ci: drop deprecated golint
* build: update Go to 1.19
* chore: fix lint violations

Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark authored Aug 24, 2022
1 parent 95ff401 commit 8feeb81
Show file tree
Hide file tree
Showing 28 changed files with 535 additions and 218 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: docs
submodules: true
Expand All @@ -21,9 +21,9 @@ jobs:
cp .all-contributorsrc docs/data/contributors.json
- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: 1.14.x
go-version: 1.19.x

- name: Generate CLI docs
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Unshallow
run: git fetch --prune --unshallow

- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: 1.14.x
go-version: 1.19.x

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
19 changes: 6 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: 1.14
go-version: 1.19

- name: Checkout code
uses: actions/checkout@v2

- name: Install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.33.0

- name: Install golint
run: go get -u golang.org/x/lint/golint
uses: actions/checkout@v3

- name: Run golangci-lint
run: $(go env GOPATH)/bin/golangci-lint run ./... --timeout 5m

- name: Run golint
run: $(go env GOPATH)/bin/golint ./...
uses: golangci/golangci-lint-action@v3
with:
version: v1.48
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ jobs:
tests:
strategy:
matrix:
go-version: [1.14.x]
go-version: [1.19.x]
platform: [macos-latest, ubuntu-latest] # , windows-latest // TODO: Review Tests on windows
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Test
run: |
Expand All @@ -41,12 +41,12 @@ jobs:
needs: tests
steps:
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- run: git fetch --prune --unshallow

- name: Download coverage report
Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ linters-settings:
ignore-words:
- konstellation
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
Expand Down
7 changes: 3 additions & 4 deletions cmd/hostctl/actions/gen_md_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package actions
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -57,7 +56,7 @@ Creates full markdown documentation and store it on the given path.
fname := path.Base(src)

dst := strings.Replace(src, "hostctl_", "", 1)
if fname == "hostctl.md" { // nolint: goconst
if fname == "hostctl.md" { //nolint: goconst
dst = path.Join(output, "_index.md")
err = fixContent(rootCmd.Long, src)
} else {
Expand All @@ -83,7 +82,7 @@ func fixContent(desc, dst string) error {
autoRe := regexp.MustCompile("###### Auto generated by spf13/cobra on .*")
alsoRe := regexp.MustCompile(also)

data, err := ioutil.ReadFile(dst)
data, err := os.ReadFile(dst)
if err != nil {
return fmt.Errorf("%s: %w", ErrReadingFile.Error(), err)
}
Expand All @@ -94,7 +93,7 @@ func fixContent(desc, dst string) error {
wrapped := fmt.Sprintf("```\n%s\n```\n", desc)
final := strings.Replace(string(data), desc, wrapped, 1)

return ioutil.WriteFile(dst, []byte(final), 0666) // nolint: gosec
return os.WriteFile(dst, []byte(final), 0666) //nolint: gosec,gomnd
}

func filePrepender(filename string) string {
Expand Down
7 changes: 3 additions & 4 deletions cmd/hostctl/actions/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -82,7 +81,7 @@ func containsDefault(args []string) error {

func getDefaultHostFile() string {
if runtime.GOOS == "linux" {
return "/etc/hosts" // nolint: goconst
return "/etc/hosts" //nolint: goconst
}

envHostFile := os.Getenv("HOSTCTL_FILE")
Expand Down Expand Up @@ -125,7 +124,7 @@ func readerFromURL(ctx context.Context, url string) (io.Reader, error) {

defer resp.Body.Close()

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)

return bytes.NewReader(b), err
}
Expand All @@ -147,7 +146,7 @@ func getRenderer(cmd *cobra.Command, opts *render.TableRendererOptions) types.Re
opts.Writer = cmd.OutOrStdout()
}

// nolint: goconst
//nolint: goconst
switch {
case raw || out == "raw":
return render.NewRawRenderer(opts)
Expand Down
8 changes: 4 additions & 4 deletions cmd/hostctl/actions/integration_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package actions
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *cmdRunner) Run(cmd string) Runner {
err := c.root.Execute()
assert.NoError(err)

out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
assert.NoError(err)

c.out = "\n" + string(out)
Expand All @@ -132,7 +132,7 @@ func (c *cmdRunner) RunE(cmd string, expectedErr error) Runner {
actualErr := c.root.Execute()
assert.EqualError(actualErr, expectedErr.Error())

out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
assert.NoError(err)

c.out = "\n" + string(out)
Expand All @@ -141,7 +141,7 @@ func (c *cmdRunner) RunE(cmd string, expectedErr error) Runner {
}

func (c *cmdRunner) TempHostfile(pattern string) *os.File {
file, err := ioutil.TempFile("/tmp", fmt.Sprintf("%s_%s_", c.root.Name(), pattern))
file, err := os.CreateTemp("/tmp", fmt.Sprintf("%s_%s_", c.root.Name(), pattern))
as.NoError(c.t, err)

_, _ = file.WriteString(`
Expand Down
2 changes: 1 addition & 1 deletion cmd/hostctl/actions/post_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func waitSignalOrDuration(d time.Duration) <-chan struct{} {
d = longWaitTime * time.Hour
}

signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) //nolint: govet

go func() {
for {
Expand Down
7 changes: 3 additions & 4 deletions cmd/hostctl/actions/restore_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package actions

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -17,7 +16,7 @@ func Test_Restore(t *testing.T) {
from := r.TempHostfile("restoreFrom")
defer os.Remove(from.Name())

to, err := ioutil.TempFile("/tmp", "restoreTo")
to, err := os.CreateTemp("/tmp", "restoreTo")
assert.NoError(t, err)

defer os.Remove(to.Name())
Expand All @@ -41,7 +40,7 @@ func Test_Restore(t *testing.T) {
+----------+--------+-----------+------------+
`, to.Name(), from.Name())

toData, _ := ioutil.ReadFile(to.Name())
fromData, _ := ioutil.ReadFile(from.Name())
toData, _ := os.ReadFile(to.Name())
fromData, _ := os.ReadFile(from.Name())
assert.Equal(t, string(toData), string(fromData))
}
4 changes: 2 additions & 2 deletions cmd/hostctl/actions/sync_docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package actions

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -45,7 +45,7 @@ func newClientWithResponse(t *testing.T, resp map[string]string) *client.Client
}
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte(b))),
Body: io.NopCloser(bytes.NewReader([]byte(b))),
}, nil
}),
},
Expand Down
48 changes: 32 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
module github.com/guumaster/hostctl

go 1.14
go 1.19

require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v17.12.1-ce+incompatible
github.com/docker/docker v20.10.17+incompatible
github.com/guumaster/cligger v0.1.1
github.com/guumaster/tablewriter v0.0.10
github.com/spf13/afero v1.9.2
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/guumaster/cligger v0.1.1
github.com/guumaster/tablewriter v0.0.9
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/guumaster/logsymbols v0.3.1 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/afero v1.3.2
github.com/spf13/cobra v1.0.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.3.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666 // indirect
golang.org/x/text v0.3.3 // indirect
gopkg.in/yaml.v2 v2.3.0
golang.org/x/net v0.0.0-20220809012201-f428fae20770 // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/gookit/color.v1 v1.1.6 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
gotest.tools/v3 v3.3.0 // indirect
)
Loading

0 comments on commit 8feeb81

Please sign in to comment.