Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: subpath actions via new artifact cache #2170

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pkg/runner/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,28 @@
return nil
}

var containerActionDirCopy string
containerActionDirCopy = strings.TrimSuffix(containerActionDir, actionPath)
logger.Debug(containerActionDirCopy)

if !strings.HasSuffix(containerActionDirCopy, `/`) {
containerActionDirCopy += `/`
}

if rc.Config != nil && rc.Config.ActionCache != nil {
raction := step.(*stepActionRemote)
ta, err := rc.Config.ActionCache.GetTarArchive(ctx, raction.cacheDir, raction.resolvedSha, "")
if err != nil {
return err
}
defer ta.Close()
return rc.JobContainer.CopyTarStream(ctx, containerActionDir, ta)
return rc.JobContainer.CopyTarStream(ctx, containerActionDirCopy, ta)

Check warning on line 143 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L137-L143

Added lines #L137 - L143 were not covered by tests
}

if err := removeGitIgnore(ctx, actionDir); err != nil {
return err
}

Check warning on line 148 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L147-L148

Added lines #L147 - L148 were not covered by tests

var containerActionDirCopy string
containerActionDirCopy = strings.TrimSuffix(containerActionDir, actionPath)
logger.Debug(containerActionDirCopy)

if !strings.HasSuffix(containerActionDirCopy, `/`) {
containerActionDirCopy += `/`
}
return rc.JobContainer.CopyDir(containerActionDirCopy, actionDir+"/", rc.Config.UseGitIgnore)(ctx)
}

Expand Down Expand Up @@ -201,7 +202,7 @@
model.ActionRunsUsingDocker,
model.ActionRunsUsingNode12,
model.ActionRunsUsingNode16,
model.ActionRunsUsingNode20,

Check warning on line 205 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L205

Added line #L205 was not covered by tests
model.ActionRunsUsingComposite,
}, action.Runs.Using))
}
Expand Down Expand Up @@ -287,16 +288,16 @@
if localAction {
buildContext, err = rc.JobContainer.GetContainerArchive(ctx, contextDir+"/.")
if err != nil {
return err
}

Check warning on line 292 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L291-L292

Added lines #L291 - L292 were not covered by tests
defer buildContext.Close()
} else if rc.Config.ActionCache != nil {
rstep := step.(*stepActionRemote)
buildContext, err = rc.Config.ActionCache.GetTarArchive(ctx, rstep.cacheDir, rstep.resolvedSha, contextDir)
if err != nil {
return err
}
defer buildContext.Close()

Check warning on line 300 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L295-L300

Added lines #L295 - L300 were not covered by tests
}
prepImage = container.NewDockerBuildExecutor(container.NewDockerBuildExecutorInput{
ContextDir: contextDir,
Expand Down Expand Up @@ -395,8 +396,8 @@
binds, mounts := rc.GetBindsAndMounts()
networkMode := fmt.Sprintf("container:%s", rc.jobContainerName())
if rc.IsHostEnv(ctx) {
networkMode = "default"
}

Check warning on line 400 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L399-L400

Added lines #L399 - L400 were not covered by tests
stepContainer := container.NewContainer(&container.NewContainerInput{
Cmd: cmd,
Entrypoint: entrypoint,
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/step_action_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,44 @@
}
}
if sar.RunContext.Config.ActionCache != nil {
cache := sar.RunContext.Config.ActionCache

var err error
sar.cacheDir = fmt.Sprintf("%s/%s", sar.remoteAction.Org, sar.remoteAction.Repo)
sar.resolvedSha, err = cache.Fetch(ctx, sar.cacheDir, sar.remoteAction.URL+"/"+sar.cacheDir, sar.remoteAction.Ref, github.Token)
if err != nil {
return err
}

Check warning on line 74 in pkg/runner/step_action_remote.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/step_action_remote.go#L67-L74

Added lines #L67 - L74 were not covered by tests

remoteReader := func(ctx context.Context) actionYamlReader {
return func(filename string) (io.Reader, io.Closer, error) {
spath := filename
spath := path.Join(sar.remoteAction.Path, filename)
for i := 0; i < maxSymlinkDepth; i++ {
tars, err := cache.GetTarArchive(ctx, sar.cacheDir, sar.resolvedSha, spath)
if err != nil {
return nil, nil, os.ErrNotExist
}
treader := tar.NewReader(tars)
header, err := treader.Next()
if err != nil {
return nil, nil, os.ErrNotExist
}
if header.FileInfo().Mode()&os.ModeSymlink == os.ModeSymlink {
spath, err = symlinkJoin(spath, header.Linkname, ".")
if err != nil {
return nil, nil, err
}
} else {
return treader, tars, nil
}

Check warning on line 96 in pkg/runner/step_action_remote.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/step_action_remote.go#L76-L96

Added lines #L76 - L96 were not covered by tests
}
return nil, nil, fmt.Errorf("max depth %d of symlinks exceeded while reading %s", maxSymlinkDepth, spath)

Check warning on line 98 in pkg/runner/step_action_remote.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/step_action_remote.go#L98

Added line #L98 was not covered by tests
}
}

actionModel, err := sar.readAction(ctx, sar.Step, sar.resolvedSha, sar.remoteAction.Path, remoteReader(ctx), os.WriteFile)
sar.action = actionModel
return err

Check warning on line 104 in pkg/runner/step_action_remote.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/step_action_remote.go#L102-L104

Added lines #L102 - L104 were not covered by tests
}

actionDir := fmt.Sprintf("%s/%s", sar.RunContext.ActionCacheDir(), safeFilename(sar.Step.Uses))
Expand Down
Loading