Skip to content

Commit

Permalink
ci: update go version (#682)
Browse files Browse the repository at this point in the history
* ci: update go version
* fix golangci-lint action
  • Loading branch information
sunny0826 authored Apr 23, 2023
1 parent 6d6467a commit 6a95542
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:

env:
# Common versions
GO_VERSION: '1.18'
GO_VERSION: '1.19'

jobs:
kind:
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ on:
- '**.go'
- '**.yaml'
- '**.mod'

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.18
- name: Set up Go 1.19
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version: 1.19
id: go

- name: Check out code into the Go module directory
Expand All @@ -31,6 +34,11 @@ jobs:
- name: Run test
run: make test

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2

- name: Upload coverage report
uses: codecov/codecov-action@v3.1.2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version: 1.19
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ vet:
lint: golangci
$(GOLANGCILINT) run ./...

test: fmt vet lint
test: fmt vet
go test -race -coverprofile=coverage.txt -covermode=atomic ./cmd/...

doc-gen:
Expand All @@ -81,7 +81,7 @@ endif
doc-run:
docsify serve docs

GOLANGCILINT_VERSION ?= v1.46.2
GOLANGCILINT_VERSION ?= v1.52.2
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
HOSTARCH := $(shell uname -m)
ifeq ($(HOSTARCH),x86_64)
Expand Down
4 changes: 2 additions & 2 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"strconv"

Expand Down Expand Up @@ -49,7 +49,7 @@ func (ac *AddCommand) runAdd(cmd *cobra.Command, args []string) error {

if file == "-" {
// from stdin
contents, err := ioutil.ReadAll(os.Stdin)
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -34,6 +33,7 @@ func (al *AliasCommand) Init() {
_ = al.command.MarkFlagRequired("out")
}

// SourceCmd source command
const SourceCmd = "[[ ! -f ~/.kubecm ]] || source ~/.kubecm"

func (al *AliasCommand) runAlias(command *cobra.Command, args []string) error {
Expand Down Expand Up @@ -79,7 +79,7 @@ alias %s='kubectl --context %s'`
}

func updateFile(cxt, path string) error {
err := ioutil.WriteFile(path, []byte(cxt), 0644)
err := os.WriteFile(path, []byte(cxt), 0644)
if err != nil {
return err
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/alias_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package cmd

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

func Test_updateFile(t *testing.T) {
testFile, _ := ioutil.TempFile("", "")
defer os.Remove(testFile.Name())
temp, err := os.CreateTemp("", "")
if err != nil {
return
}
defer os.Remove(temp.Name())
type args struct {
cxt string
path string
Expand All @@ -23,7 +25,7 @@ func Test_updateFile(t *testing.T) {
name: "test",
args: args{
cxt: "test",
path: testFile.Name(),
path: temp.Name(),
},
},
}
Expand All @@ -44,7 +46,7 @@ func Test_updateFile(t *testing.T) {
}

func Test_writeAppend(t *testing.T) {
bashFile, _ := ioutil.TempFile("", ".bash")
bashFile, _ := os.CreateTemp("", ".bash")
defer os.Remove(bashFile.Name())
type args struct {
context string
Expand Down
5 changes: 2 additions & 3 deletions cmd/clear_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package cmd

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

"k8s.io/client-go/tools/clientcmd"
)

func Test_clearContext(t *testing.T) {
trueFile, _ := ioutil.TempFile("", "")
falseFile, _ := ioutil.TempFile("", "")
trueFile, _ := os.CreateTemp("", "")
falseFile, _ := os.CreateTemp("", "")
defer os.Remove(trueFile.Name())
defer os.Remove(falseFile.Name())
_ = clientcmd.WriteToFile(appendMergeConfig, trueFile.Name())
Expand Down
3 changes: 1 addition & 2 deletions cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"strconv"

Expand Down Expand Up @@ -89,7 +88,7 @@ func loadKubeConfig(yaml string) (*clientcmdapi.Config, error) {
}

func listFile(folder string) []string {
files, _ := ioutil.ReadDir(folder)
files, _ := os.ReadDir(folder)
var fileList []string
for _, file := range files {
if file.Name() == ".DS_Store" {
Expand Down
32 changes: 17 additions & 15 deletions cmd/merge_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -29,23 +28,23 @@ var (
)

func Test_listFile(t *testing.T) {
tempDir, err := ioutil.TempDir("", t.Name())
temp, err := os.MkdirTemp("", t.Name())
if err != nil {
t.Fatalf("TempDir %s: %v", t.Name(), err)
}
defer os.RemoveAll(tempDir)
filename1 := filepath.Join(tempDir, "config1")
filename2 := filepath.Join(tempDir, "config2")
dsStore := filepath.Join(tempDir, ".DS_Store")
err = ioutil.WriteFile(filename1, []byte("shmorp"), 0444)
defer os.RemoveAll(temp)
filename1 := filepath.Join(temp, "config1")
filename2 := filepath.Join(temp, "config2")
dsStore := filepath.Join(temp, ".DS_Store")
err = os.WriteFile(filename1, []byte("shmorp"), 0444)
if err != nil {
t.Fatalf("WriteFile %s: %v", filename1, err)
}
err = ioutil.WriteFile(filename2, []byte("florp"), 0444)
err = os.WriteFile(filename2, []byte("florp"), 0444)
if err != nil {
t.Fatalf("WriteFile %s: %v", filename2, err)
}
err = ioutil.WriteFile(dsStore, []byte("xxxx"), 0444)
err = os.WriteFile(dsStore, []byte("xxxx"), 0444)
if err != nil {
t.Fatalf("WriteFile %s: %v", filename2, err)
}
Expand All @@ -59,7 +58,7 @@ func Test_listFile(t *testing.T) {
want []string
}{
// TODO: Add test cases.
{"testDir", args{folder: tempDir}, []string{filename1, filename2}},
{"testDir", args{folder: temp}, []string{filename1, filename2}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -71,19 +70,22 @@ func Test_listFile(t *testing.T) {
}

func Test_loadKubeConfig(t *testing.T) {
tempDir, err := ioutil.TempDir("", t.Name())
temp, err := os.MkdirTemp("", t.Name())
if err != nil {
return
}
if err != nil {
t.Fatalf("TempDir %s: %v", t.Name(), err)
}
defer os.RemoveAll(tempDir)
defer os.RemoveAll(temp)

merge1 := filepath.Join(tempDir, "merge1")
merge1 := filepath.Join(temp, "merge1")
err = clientcmd.WriteToFile(mergeTestConfig, merge1)
if err != nil {
t.Fatalf("WriteFile %s: %v", merge1, err)
}
mergeFail := filepath.Join(tempDir, "config2")
err = ioutil.WriteFile(mergeFail, []byte("florp"), 0444)
mergeFail := filepath.Join(temp, "config2")
err = os.WriteFile(mergeFail, []byte("florp"), 0444)
if err != nil {
t.Fatalf("WriteFile %s: %v", mergeFail, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Cli struct {
rootCmd *cobra.Command
}

//NewCli returns the cli instance used to register and execute command
// NewCli returns the cli instance used to register and execute command
func NewCli() *Cli {
cli := &Cli{
rootCmd: &cobra.Command{
Expand Down
9 changes: 4 additions & 5 deletions cmd/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"os/user"
"reflect"
Expand Down Expand Up @@ -257,10 +256,10 @@ func checkConfig(want, got *clientcmdapi.Config, t *testing.T) {
}

func Test_getFileName(t *testing.T) {
tempDir, _ := ioutil.TempDir("", "kubecm-get-file-")
defer os.RemoveAll(tempDir)
tempFilePath := fmt.Sprintf("%s/%s", tempDir, "testPath")
_ = ioutil.WriteFile(tempFilePath, []byte{}, 0666)
temp, _ := os.CreateTemp("", "kubecm-get-file-")
defer os.RemoveAll(temp.Name())
tempFilePath := fmt.Sprintf("%s/%s", temp.Name(), "testPath")
_ = os.WriteFile(tempFilePath, []byte{}, 0666)

type args struct {
path string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/sunny0826/kubecm

go 1.18
go 1.19

require (
github.com/alibabacloud-go/cs-20151215/v2 v2.4.5
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
4 changes: 2 additions & 2 deletions pkg/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package update
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -42,7 +42,7 @@ func getLatestReleaseInfo(repo string) (*ReleaseInfo, error) {
}

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 6a95542

Please sign in to comment.