diff --git a/pkg/common/file.go b/pkg/common/file.go index 0894f0c..09c2102 100644 --- a/pkg/common/file.go +++ b/pkg/common/file.go @@ -48,9 +48,7 @@ func CopyDir(source string, dest string) (err error) { return err } - directory, _ := os.Open(source) - - objects, err := directory.Readdir(-1) + objects, err := os.ReadDir(source) for _, obj := range objects { sourcefilepointer := source + "/" + obj.Name() diff --git a/pkg/common/git/git.go b/pkg/common/git/git.go index 01c4b74..d03dada 100644 --- a/pkg/common/git/git.go +++ b/pkg/common/git/git.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -61,7 +60,7 @@ func FindGitRevision(ctx context.Context, file string) (shortSha string, sha str return "", "", err } - bts, err := ioutil.ReadFile(filepath.Join(gitDir, "HEAD")) + bts, err := os.ReadFile(filepath.Join(gitDir, "HEAD")) if err != nil { return "", "", err } @@ -70,7 +69,7 @@ func FindGitRevision(ctx context.Context, file string) (shortSha string, sha str var refBuf []byte if strings.HasPrefix(ref, "refs/") { // load commitid ref - refBuf, err = ioutil.ReadFile(filepath.Join(gitDir, ref)) + refBuf, err = os.ReadFile(filepath.Join(gitDir, ref)) if err != nil { return "", "", err } @@ -151,7 +150,7 @@ func findGitPrettyRef(ctx context.Context, head, root, sub string) (string, erro return nil } var bts []byte - if bts, err = ioutil.ReadFile(path); err != nil { + if bts, err = os.ReadFile(path); err != nil { return err } var pointsTo = strings.TrimSpace(string(bts)) diff --git a/pkg/common/git/git_test.go b/pkg/common/git/git_test.go index 067744d..9798193 100644 --- a/pkg/common/git/git_test.go +++ b/pkg/common/git/git_test.go @@ -3,7 +3,6 @@ package git import ( "context" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -45,7 +44,7 @@ func TestFindGitSlug(t *testing.T) { } func testDir(t *testing.T) string { - basedir, err := ioutil.TempDir("", "act-test") + basedir, err := os.MkdirTemp("", "act-test") require.NoError(t, err) t.Cleanup(func() { _ = os.RemoveAll(basedir) }) return basedir @@ -53,7 +52,7 @@ func testDir(t *testing.T) string { func cleanGitHooks(dir string) error { hooksDir := filepath.Join(dir, ".git", "hooks") - files, err := ioutil.ReadDir(hooksDir) + files, err := os.ReadDir(hooksDir) if err != nil { if os.IsNotExist(err) { return nil diff --git a/pkg/container/docker_images_test.go b/pkg/container/docker_images_test.go index a4670b6..cf13f43 100644 --- a/pkg/container/docker_images_test.go +++ b/pkg/container/docker_images_test.go @@ -2,7 +2,7 @@ package container import ( "context" - "io/ioutil" + "io" "testing" "github.com/docker/docker/api/types" @@ -45,7 +45,7 @@ func TestImageExistsLocally(t *testing.T) { }) assert.Nil(t, err) defer readerDefault.Close() - _, err = ioutil.ReadAll(readerDefault) + _, err = io.ReadAll(readerDefault) assert.Nil(t, err) imageDefaultArchExists, err := ImageExistsLocally(ctx, "node:16-buster-slim", "linux/amd64") @@ -58,7 +58,7 @@ func TestImageExistsLocally(t *testing.T) { }) assert.Nil(t, err) defer readerArm64.Close() - _, err = ioutil.ReadAll(readerArm64) + _, err = io.ReadAll(readerArm64) assert.Nil(t, err) imageArm64Exists, err := ImageExistsLocally(ctx, "node:16-buster-slim", "linux/arm64") diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index f58287e..896a269 100644 --- a/pkg/container/docker_run.go +++ b/pkg/container/docker_run.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -769,7 +768,7 @@ func (cr *containerReference) waitForCommand(ctx context.Context, isTerminal boo func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgnore bool) common.Executor { return func(ctx context.Context) error { logger := common.Logger(ctx) - tarFile, err := ioutil.TempFile("", "act") + tarFile, err := os.CreateTemp("", "act") if err != nil { return err } diff --git a/pkg/model/planner.go b/pkg/model/planner.go index ef9aaa6..73e3488 100644 --- a/pkg/model/planner.go +++ b/pkg/model/planner.go @@ -3,7 +3,7 @@ package model import ( "fmt" "io" - "io/ioutil" + "io/fs" "math" "os" "path/filepath" @@ -51,7 +51,7 @@ func (r *Run) Job() *Job { } type WorkflowFiles struct { - workflowFileInfo os.FileInfo + workflowDirEntry os.DirEntry dirPath string } @@ -74,7 +74,7 @@ func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, e if fi.IsDir() { log.Debugf("Loading workflows from '%s'", path) if noWorkflowRecurse { - files, err := ioutil.ReadDir(path) + files, err := os.ReadDir(path) if err != nil { return nil, err } @@ -82,7 +82,7 @@ func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, e for _, v := range files { workflows = append(workflows, WorkflowFiles{ dirPath: path, - workflowFileInfo: v, + workflowDirEntry: v, }) } } else { @@ -97,7 +97,7 @@ func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, e log.Debugf("Found workflow '%s' in '%s'", f.Name(), p) workflows = append(workflows, WorkflowFiles{ dirPath: filepath.Dir(p), - workflowFileInfo: f, + workflowDirEntry: fs.FileInfoToDirEntry(f), }) } @@ -112,7 +112,7 @@ func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, e workflows = append(workflows, WorkflowFiles{ dirPath: dirname, - workflowFileInfo: fi, + workflowDirEntry: fs.FileInfoToDirEntry(fi), }) } if err != nil { @@ -121,9 +121,9 @@ func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, e wp := new(workflowPlanner) for _, wf := range workflows { - ext := filepath.Ext(wf.workflowFileInfo.Name()) + ext := filepath.Ext(wf.workflowDirEntry.Name()) if ext == ".yml" || ext == ".yaml" { - f, err := os.Open(filepath.Join(wf.dirPath, wf.workflowFileInfo.Name())) + f, err := os.Open(filepath.Join(wf.dirPath, wf.workflowDirEntry.Name())) if err != nil { return nil, err } @@ -133,19 +133,19 @@ func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, e if err != nil { _ = f.Close() if err == io.EOF { - return nil, fmt.Errorf("unable to read workflow '%s': file is empty: %w", wf.workflowFileInfo.Name(), err) + return nil, fmt.Errorf("unable to read workflow '%s': file is empty: %w", wf.workflowDirEntry.Name(), err) } - return nil, fmt.Errorf("workflow is not valid. '%s': %w", wf.workflowFileInfo.Name(), err) + return nil, fmt.Errorf("workflow is not valid. '%s': %w", wf.workflowDirEntry.Name(), err) } _, err = f.Seek(0, 0) if err != nil { _ = f.Close() - return nil, fmt.Errorf("error occurring when resetting io pointer in '%s': %w", wf.workflowFileInfo.Name(), err) + return nil, fmt.Errorf("error occurring when resetting io pointer in '%s': %w", wf.workflowDirEntry.Name(), err) } - workflow.File = wf.workflowFileInfo.Name() + workflow.File = wf.workflowDirEntry.Name() if workflow.Name == "" { - workflow.Name = wf.workflowFileInfo.Name() + workflow.Name = wf.workflowDirEntry.Name() } jobNameRegex := regexp.MustCompile(`^([[:alpha:]_][[:alnum:]_\-]*)$`) diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index af30305..9c10fbe 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -3,7 +3,7 @@ package runner import ( "context" "fmt" - "io/ioutil" + "os" "path/filepath" "regexp" "runtime" @@ -111,7 +111,7 @@ func New(runnerConfig *Config) (Runner, error) { runner.eventJSON = "{}" if runnerConfig.EventPath != "" { log.Debugf("Reading event.json from %s", runner.config.EventPath) - eventJSONBytes, err := ioutil.ReadFile(runner.config.EventPath) + eventJSONBytes, err := os.ReadFile(runner.config.EventPath) if err != nil { return nil, err }