Skip to content

Commit f2b98ed

Browse files
feat: Host environment (#1293)
1 parent 64e68bd commit f2b98ed

39 files changed

+1394
-185
lines changed

.github/workflows/checks.yml

+19
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ jobs:
5757
files: coverage.txt
5858
fail_ci_if_error: true # optional (default = false)
5959

60+
test-host:
61+
strategy:
62+
matrix:
63+
os:
64+
- windows-latest
65+
- macos-latest
66+
name: test-${{matrix.os}}
67+
runs-on: ${{matrix.os}}
68+
steps:
69+
- uses: actions/checkout@v3
70+
with:
71+
fetch-depth: 2
72+
- uses: actions/setup-go@v3
73+
with:
74+
go-version: ${{ env.GO_VERSION }}
75+
check-latest: true
76+
- run: go test -v -run ^TestRunEventHostEnvironment$ ./...
77+
# TODO merge coverage with test-linux
78+
6079
snapshot:
6180
name: snapshot
6281
runs-on: ubuntu-latest

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/AlecAivazis/survey/v2 v2.3.6
77
github.com/Masterminds/semver v1.5.0
88
github.com/andreaskoch/go-fswatch v1.0.0
9+
github.com/creack/pty v1.1.17
910
github.com/docker/cli v20.10.21+incompatible
1011
github.com/docker/distribution v2.8.1+incompatible
1112
github.com/docker/docker v20.10.21+incompatible

pkg/container/docker_run.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type Container interface {
8484
}
8585

8686
// NewContainer creates a reference to a container
87-
func NewContainer(input *NewContainerInput) Container {
87+
func NewContainer(input *NewContainerInput) ExecutionsEnvironment {
8888
cr := new(containerReference)
8989
cr.input = input
9090
return cr
@@ -233,6 +233,7 @@ type containerReference struct {
233233
input *NewContainerInput
234234
UID int
235235
GID int
236+
LinuxContainerEnvironmentExtensions
236237
}
237238

238239
func GetDockerClient(ctx context.Context) (cli client.APIClient, err error) {

pkg/container/docker_run_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,6 @@ func TestDockerExecFailure(t *testing.T) {
163163
conn.AssertExpectations(t)
164164
client.AssertExpectations(t)
165165
}
166+
167+
// Type assert containerReference implements ExecutionsEnvironment
168+
var _ ExecutionsEnvironment = &containerReference{}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package container
2+
3+
import "context"
4+
5+
type ExecutionsEnvironment interface {
6+
Container
7+
ToContainerPath(string) string
8+
GetActPath() string
9+
GetPathVariableName() string
10+
DefaultPathVariable() string
11+
JoinPathVariable(...string) string
12+
GetRunnerContext(ctx context.Context) map[string]interface{}
13+
}

pkg/container/file_collector.go

+23
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ func (tc tarCollector) WriteFile(fpath string, fi fs.FileInfo, linkName string,
5959
return nil
6060
}
6161

62+
type copyCollector struct {
63+
DstDir string
64+
}
65+
66+
func (cc *copyCollector) WriteFile(fpath string, fi fs.FileInfo, linkName string, f io.Reader) error {
67+
fdestpath := filepath.Join(cc.DstDir, fpath)
68+
if err := os.MkdirAll(filepath.Dir(fdestpath), 0777); err != nil {
69+
return err
70+
}
71+
if f == nil {
72+
return os.Symlink(linkName, fdestpath)
73+
}
74+
df, err := os.OpenFile(fdestpath, os.O_CREATE|os.O_WRONLY, fi.Mode())
75+
if err != nil {
76+
return err
77+
}
78+
defer df.Close()
79+
if _, err := io.Copy(df, f); err != nil {
80+
return err
81+
}
82+
return nil
83+
}
84+
6285
type fileCollector struct {
6386
Ignorer gitignore.Matcher
6487
SrcPath string

0 commit comments

Comments
 (0)