Skip to content
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
14 changes: 14 additions & 0 deletions cmd/src/actions_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type actionExecutionCacheKey struct {
type actionExecutionCache interface {
get(ctx context.Context, key actionExecutionCacheKey) (result PatchInput, ok bool, err error)
set(ctx context.Context, key actionExecutionCacheKey, result PatchInput) error
clear(ctx context.Context, key actionExecutionCacheKey) error
}

type actionExecutionDiskCache struct {
Expand Down Expand Up @@ -82,6 +83,15 @@ func (c actionExecutionDiskCache) set(ctx context.Context, key actionExecutionCa
return ioutil.WriteFile(path, data, 0600)
}

func (c actionExecutionDiskCache) clear(ctx context.Context, key actionExecutionCacheKey) error {
path, err := c.cacheFilePath(key)
if err != nil {
return err
}

return os.Remove(path)
}

// actionExecutionNoOpCache is an implementation of actionExecutionCache that does not store or
// retrieve cache entries.
type actionExecutionNoOpCache struct{}
Expand All @@ -93,3 +103,7 @@ func (actionExecutionNoOpCache) get(ctx context.Context, key actionExecutionCach
func (actionExecutionNoOpCache) set(ctx context.Context, key actionExecutionCacheKey, result PatchInput) error {
return nil
}

func (actionExecutionNoOpCache) clear(ctx context.Context, key actionExecutionCacheKey) error {
return nil
}
16 changes: 10 additions & 6 deletions cmd/src/actions_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ Format of the action JSON files:
var (
fileFlag = flagSet.String("f", "-", "The action file. If not given or '-' standard input is used. (Required)")
parallelismFlag = flagSet.Int("j", runtime.GOMAXPROCS(0), "The number of parallel jobs.")
cacheDirFlag = flagSet.String("cache", displayUserCacheDir, "Directory for caching results.")
keepLogsFlag = flagSet.Bool("keep-logs", false, "Do not remove execution log files when done.")
timeoutFlag = flagSet.Duration("timeout", defaultTimeout, "The maximum duration a single action run can take (excluding the building of Docker images).")

cacheDirFlag = flagSet.String("cache", displayUserCacheDir, "Directory for caching results.")
clearCacheFlag = flagSet.Bool("clear-cache", false, "Remove possibly cached results for an action before executing it.")

keepLogsFlag = flagSet.Bool("keep-logs", false, "Do not remove execution log files when done.")
timeoutFlag = flagSet.Duration("timeout", defaultTimeout, "The maximum duration a single action run can take (excluding the building of Docker images).")

createPatchSetFlag = flagSet.Bool("create-patchset", false, "Create a patch set from the produced set of patches. When the execution of the action fails in a single repository a prompt will ask to confirm or reject the patch set creation.")
forceCreatePatchSetFlag = flagSet.Bool("force-create-patchset", false, "Force creation of patch set from the produced set of patches, without asking for confirmation even when the execution of the action failed for a subset of repositories.")
Expand Down Expand Up @@ -196,9 +199,10 @@ Format of the action JSON files:
}

opts := actionExecutorOptions{
timeout: *timeoutFlag,
keepLogs: *keepLogsFlag,
cache: actionExecutionDiskCache{dir: *cacheDirFlag},
timeout: *timeoutFlag,
keepLogs: *keepLogsFlag,
clearCache: *clearCacheFlag,
cache: actionExecutionDiskCache{dir: *cacheDirFlag},
}
if !*verbose {
opts.onUpdate = newTerminalUI(*keepLogsFlag)
Expand Down
4 changes: 3 additions & 1 deletion cmd/src/actions_exec_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ type actionExecutorOptions struct {
keepLogs bool
timeout time.Duration

cache actionExecutionCache
clearCache bool
cache actionExecutionCache

onUpdate func(map[ActionRepo]ActionRepoStatus)
}

Expand Down
20 changes: 13 additions & 7 deletions cmd/src/actions_exec_backend_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ type ActionRepoStatus struct {
func (x *actionExecutor) do(ctx context.Context, repo ActionRepo) (err error) {
// Check if cached.
cacheKey := actionExecutionCacheKey{Repo: repo, Runs: x.action.Steps}
if result, ok, err := x.opt.cache.get(ctx, cacheKey); err != nil {
return errors.Wrapf(err, "checking cache for %s", repo.Name)
} else if ok {
status := ActionRepoStatus{Cached: true, Patch: result}
x.updateRepoStatus(repo, status)
x.logger.RepoCacheHit(repo, status.Patch != PatchInput{})
return nil
if x.opt.clearCache {
if err := x.opt.cache.clear(ctx, cacheKey); err != nil {
return errors.Wrapf(err, "clearing cache for %s", repo.Name)
}
} else {
if result, ok, err := x.opt.cache.get(ctx, cacheKey); err != nil {
return errors.Wrapf(err, "checking cache for %s", repo.Name)
} else if ok {
status := ActionRepoStatus{Cached: true, Patch: result}
x.updateRepoStatus(repo, status)
x.logger.RepoCacheHit(repo, status.Patch != PatchInput{})
return nil
}
}

prefix := "action-" + strings.Replace(strings.Replace(repo.Name, "/", "-", -1), "github.com-", "", -1)
Expand Down