Skip to content

Commit

Permalink
feat: Host environment (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX authored Nov 16, 2022
1 parent 64e68bd commit f2b98ed
Show file tree
Hide file tree
Showing 39 changed files with 1,394 additions and 185 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ jobs:
files: coverage.txt
fail_ci_if_error: true # optional (default = false)

test-host:
strategy:
matrix:
os:
- windows-latest
- macos-latest
name: test-${{matrix.os}}
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- run: go test -v -run ^TestRunEventHostEnvironment$ ./...
# TODO merge coverage with test-linux

snapshot:
name: snapshot
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/Masterminds/semver v1.5.0
github.com/andreaskoch/go-fswatch v1.0.0
github.com/creack/pty v1.1.17
github.com/docker/cli v20.10.21+incompatible
github.com/docker/distribution v2.8.1+incompatible
github.com/docker/docker v20.10.21+incompatible
Expand Down
3 changes: 2 additions & 1 deletion pkg/container/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type Container interface {
}

// NewContainer creates a reference to a container
func NewContainer(input *NewContainerInput) Container {
func NewContainer(input *NewContainerInput) ExecutionsEnvironment {
cr := new(containerReference)
cr.input = input
return cr
Expand Down Expand Up @@ -233,6 +233,7 @@ type containerReference struct {
input *NewContainerInput
UID int
GID int
LinuxContainerEnvironmentExtensions
}

func GetDockerClient(ctx context.Context) (cli client.APIClient, err error) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/container/docker_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,6 @@ func TestDockerExecFailure(t *testing.T) {
conn.AssertExpectations(t)
client.AssertExpectations(t)
}

// Type assert containerReference implements ExecutionsEnvironment
var _ ExecutionsEnvironment = &containerReference{}
13 changes: 13 additions & 0 deletions pkg/container/executions_environment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package container

import "context"

type ExecutionsEnvironment interface {
Container
ToContainerPath(string) string
GetActPath() string
GetPathVariableName() string
DefaultPathVariable() string
JoinPathVariable(...string) string
GetRunnerContext(ctx context.Context) map[string]interface{}
}
23 changes: 23 additions & 0 deletions pkg/container/file_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ func (tc tarCollector) WriteFile(fpath string, fi fs.FileInfo, linkName string,
return nil
}

type copyCollector struct {
DstDir string
}

func (cc *copyCollector) WriteFile(fpath string, fi fs.FileInfo, linkName string, f io.Reader) error {
fdestpath := filepath.Join(cc.DstDir, fpath)
if err := os.MkdirAll(filepath.Dir(fdestpath), 0777); err != nil {
return err
}
if f == nil {
return os.Symlink(linkName, fdestpath)
}
df, err := os.OpenFile(fdestpath, os.O_CREATE|os.O_WRONLY, fi.Mode())
if err != nil {
return err
}
defer df.Close()
if _, err := io.Copy(df, f); err != nil {
return err
}
return nil
}

type fileCollector struct {
Ignorer gitignore.Matcher
SrcPath string
Expand Down
Loading

0 comments on commit f2b98ed

Please sign in to comment.