Skip to content

Commit

Permalink
chore: Remove obsolete Container.UpdateFromPath (#1631)
Browse files Browse the repository at this point in the history
* chore: Remove obsolete Container.UpdateFromPath

* remove unused import
  • Loading branch information
ChristopherHX authored Feb 16, 2023
1 parent 1316307 commit 21ea3d0
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 63 deletions.
1 change: 0 additions & 1 deletion pkg/container/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type Container interface {
Exec(command []string, env map[string]string, user, workdir string) common.Executor
UpdateFromEnv(srcPath string, env *map[string]string) common.Executor
UpdateFromImageEnv(env *map[string]string) common.Executor
UpdateFromPath(env *map[string]string) common.Executor
Remove() common.Executor
Close() common.Executor
ReplaceLogWriter(io.Writer, io.Writer) (io.Writer, io.Writer)
Expand Down
30 changes: 0 additions & 30 deletions pkg/container/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package container

import (
"archive/tar"
"bufio"
"bytes"
"context"
"errors"
Expand Down Expand Up @@ -152,10 +151,6 @@ func (cr *containerReference) UpdateFromImageEnv(env *map[string]string) common.
return cr.extractFromImageEnv(env).IfNot(common.Dryrun)
}

func (cr *containerReference) UpdateFromPath(env *map[string]string) common.Executor {
return cr.extractPath(env).IfNot(common.Dryrun)
}

func (cr *containerReference) Exec(command []string, env map[string]string, user, workdir string) common.Executor {
return common.NewPipelineExecutor(
common.NewInfoExecutor("%sdocker exec cmd=[%s] user=%s workdir=%s", logPrefix, strings.Join(command, " "), user, workdir),
Expand Down Expand Up @@ -492,31 +487,6 @@ func (cr *containerReference) extractFromImageEnv(env *map[string]string) common
}
}

func (cr *containerReference) extractPath(env *map[string]string) common.Executor {
localEnv := *env
return func(ctx context.Context) error {
pathTar, _, err := cr.cli.CopyFromContainer(ctx, cr.id, localEnv["GITHUB_PATH"])
if err != nil {
return fmt.Errorf("failed to copy from container: %w", err)
}
defer pathTar.Close()

reader := tar.NewReader(pathTar)
_, err = reader.Next()
if err != nil && err != io.EOF {
return fmt.Errorf("failed to read tar archive: %w", err)
}
s := bufio.NewScanner(reader)
for s.Scan() {
line := s.Text()
localEnv["PATH"] = fmt.Sprintf("%s:%s", line, localEnv["PATH"])
}

env = &localEnv
return nil
}
}

func (cr *containerReference) exec(cmd []string, env map[string]string, user, workdir string) common.Executor {
return func(ctx context.Context) error {
logger := common.Logger(ctx)
Expand Down
27 changes: 0 additions & 27 deletions pkg/container/host_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package container

import (
"archive/tar"
"bufio"
"bytes"
"context"
"errors"
Expand Down Expand Up @@ -344,32 +343,6 @@ func (e *HostEnvironment) UpdateFromEnv(srcPath string, env *map[string]string)
return parseEnvFile(e, srcPath, env)
}

func (e *HostEnvironment) UpdateFromPath(env *map[string]string) common.Executor {
localEnv := *env
return func(ctx context.Context) error {
pathTar, err := e.GetContainerArchive(ctx, localEnv["GITHUB_PATH"])
if err != nil {
return err
}
defer pathTar.Close()

reader := tar.NewReader(pathTar)
_, err = reader.Next()
if err != nil && err != io.EOF {
return err
}
s := bufio.NewScanner(reader)
for s.Scan() {
line := s.Text()
pathSep := string(filepath.ListSeparator)
localEnv[e.GetPathVariableName()] = fmt.Sprintf("%s%s%s", line, pathSep, localEnv[e.GetPathVariableName()])
}

env = &localEnv
return nil
}
}

func (e *HostEnvironment) Remove() common.Executor {
return func(ctx context.Context) error {
if e.CleanUp != nil {
Expand Down
5 changes: 0 additions & 5 deletions pkg/runner/container_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ func (cm *containerMock) UpdateFromImageEnv(env *map[string]string) common.Execu
return args.Get(0).(func(context.Context) error)
}

func (cm *containerMock) UpdateFromPath(env *map[string]string) common.Executor {
args := cm.Called(env)
return args.Get(0).(func(context.Context) error)
}

func (cm *containerMock) Copy(destPath string, files ...*container.FileEntry) common.Executor {
args := cm.Called(destPath, files)
return args.Get(0).(func(context.Context) error)
Expand Down

0 comments on commit 21ea3d0

Please sign in to comment.