Skip to content

Commit

Permalink
Fix lint issues and enable lint in GHA (#45)
Browse files Browse the repository at this point in the history
* Update all the deprecated references to ioutil so that lint passes
  • Loading branch information
jlewi committed Sep 21, 2023
1 parent 933642d commit 1e90dca
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ jobs:
go-version: '1.19.2' # The Go version to download (if necessary) and use.
- run: go test ./...
- run: go build ./cmd/...
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
# https://github.com/golangci/golangci-lint/releases
version: v1.50
# These options work around the errors in this issue
# https://github.com/golangci/golangci-lint-action/issues/244
skip-pkg-cache: true
skip-build-cache: true
7 changes: 3 additions & 4 deletions pkg/gitops/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gitops
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -99,7 +98,7 @@ func NewSyncer(m *v1alpha1.ManifestSync, manager *github.TransportManager, opts
}
s.log.Info("Creating NewSyncer", "manifest", m)
if s.workDir == "" {
newDir, err := ioutil.TempDir("", "manifestSync")
newDir, err := os.MkdirTemp("", "manifestSync")
if err != nil {
return nil, errors.Wrapf(err, "Failed to create a temporary working directorry")
}
Expand Down Expand Up @@ -1192,7 +1191,7 @@ func (s *Syncer) buildImages(sourcePath string, sourceCommit string) error {

if missingImages {
// Since the skaffold config could have been modified to change the registry we need to write it back out
f, err := ioutil.TempFile("", "skaffold.*.yaml")
f, err := os.CreateTemp("", "skaffold.*.yaml")

newFile := f.Name()

Expand Down Expand Up @@ -1324,7 +1323,7 @@ func findKustomizationFiles(root string, repoRoot string, excludes []string, log

// readKustomization will read a kustomization.yaml and return the kustomize object
func readKustomization(kfDefFile string) (*kustomize.Kustomization, error) {
data, err := ioutil.ReadFile(kfDefFile)
data, err := os.ReadFile(kfDefFile)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/gitutil/gitutil_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gitutil

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -41,7 +40,7 @@ func Test_LocateRoot(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
outDir, err := ioutil.TempDir("", "LocateRoot")
outDir, err := os.MkdirTemp("", "LocateRoot")
if err != nil {
t.Errorf("Failed to create temporary directory; %v", err)
return
Expand Down
7 changes: 3 additions & 4 deletions pkg/kustomize/dispatcher_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kustomize

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -38,7 +37,7 @@ func Test_runOnDir(t *testing.T) {
sourceDir := path.Join(testDir, "source")

// Create a temporary directory because the function will modify the directory.
outDir, err := ioutil.TempDir("", "runOnDir")
outDir, err := os.MkdirTemp("", "runOnDir")
if err != nil {
t.Errorf("Failed to create temporary directory; %v", err)
return
Expand Down Expand Up @@ -71,7 +70,7 @@ func Test_runOnDir(t *testing.T) {

for _, n := range names {
p := path.Join(outDir, n)
actualB, err := ioutil.ReadFile(p)
actualB, err := os.ReadFile(p)
if err != nil {
t.Errorf("Failed to read file: %v; error %v", p, err)
continue
Expand All @@ -82,7 +81,7 @@ func Test_runOnDir(t *testing.T) {
}

ePath := path.Join(testDir, "expected", n)
expectedB, err := ioutil.ReadFile(ePath)
expectedB, err := os.ReadFile(ePath)
if err != nil {
t.Errorf("Failed to read file: %v; error %v", ePath, err)
continue
Expand Down
5 changes: 2 additions & 3 deletions pkg/s3assets/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -17,7 +16,7 @@ import (

// Load reads s3 assets from an S3AssetsList yaml file.
func Load(assetsFile string) ([]string, error) {
data, err := ioutil.ReadFile(assetsFile)
data, err := os.ReadFile(assetsFile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -397,7 +396,7 @@ func (m *uploadManager) Run(asset string) (err error) {
}
fmt.Printf("Uploading %s\n", asset)
sPath := s3.Path{Bucket: m.Bucket, Key: asset}
bytes, err := ioutil.ReadFile(filepath.Join(m.absAssetDir, asset))
bytes, err := os.ReadFile(filepath.Join(m.absAssetDir, asset))
if err != nil {
m.err = err
return
Expand Down
3 changes: 1 addition & 2 deletions pkg/s3assets/io_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package s3assets

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -55,7 +54,7 @@ func (s *S3IOTestSuite) TestMakeLocalWriter() {
},
}
for name, tc := range testCases {
dir, err := ioutil.TempDir(".", "localWriterTest")
dir, err := os.MkdirTemp(".", "localWriterTest")
s.Assert().NoError(err, "Error making tmp dir", name)

tc.setup(dir, tc.testPath)
Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/build_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package skaffold
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
)

Expand Down Expand Up @@ -44,12 +44,12 @@ func (t *BuildOutputFileFlag) Set(value string) error {
)

if value == "-" {
buf, err = ioutil.ReadAll(os.Stdin)
buf, err = io.ReadAll(os.Stdin)
} else {
if _, err := os.Stat(value); os.IsNotExist(err) {
return err
}
buf, err = ioutil.ReadFile(value)
buf, err = os.ReadFile(value)
}
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions pkg/skaffold/skaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package skaffold

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -151,7 +150,7 @@ func RunBuild(skaffoldFile string, buildDir string, tags []string, sess *session
Log: log,
}

dir, err := ioutil.TempDir("", "hydrosSkaffoldBuild")
dir, err := os.MkdirTemp("", "hydrosSkaffoldBuild")
if err != nil {
return errors.Wrapf(err, "Failed to create temporary directory for skaffold")
}
Expand Down Expand Up @@ -182,7 +181,7 @@ func RunBuild(skaffoldFile string, buildDir string, tags []string, sess *session
}

// TODO(jeremy): Really need to accumulate errors and check no errors occurred.
data, err := ioutil.ReadFile(outFile)
data, err := os.ReadFile(outFile)
if err != nil {
return errors.Wrapf(err, "Could not open skaffold output file; %v", outFile)
}
Expand Down
5 changes: 2 additions & 3 deletions tests/configs_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tests

import (
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -51,7 +50,7 @@ func Test_kustomizations(t *testing.T) {
t.Errorf("Files should be listed in sorted order in the configMapGenerator in %v;\nGot: %v,\nWant: %v\nDiff: %v", kustomizeFile, actual, want, d)
}

files, err := ioutil.ReadDir(d)
files, err := os.ReadDir(d)
if err != nil {
t.Errorf("Failed to readDir: %v", d)
continue
Expand Down Expand Up @@ -116,7 +115,7 @@ func Test_build(t *testing.T) {
// Test_ValidManifestSync validates the manifestsyncs
func Test_ValidManifestSync(t *testing.T) {
for _, d := range testDirs {
files, err := ioutil.ReadDir(d)
files, err := os.ReadDir(d)
if err != nil {
if os.IsNotExist(err) {
t.Logf("Directory %v doesn't exist; test skipped", d)
Expand Down

0 comments on commit 1e90dca

Please sign in to comment.