Repository: nektos/act (language: go)

Issue:
Allow to change location of workspaces when using -self-hosted
### Act version

nektos/v0.2.45

### Feature description

When running `act` manually or as runner invoked through [Gitea actions](https://gitea.com/gitea/act_runner) the workspace will end up at `~/.cache/act` with no way to change this.

It would provide additional flexibility if there was a cli flag to move this directory though, e.g. to use a ram disk or some other custom location. This would be similar to how the location of the cache server can also be specified via `--cache-server-path`.


Discussion / hints:

Fix patch:
diff --git a/cmd/input.go b/cmd/input.go
index 954018f69ec..64556e1d3f6 100644
--- a/cmd/input.go
+++ b/cmd/input.go
@@ -54,6 +54,7 @@ type Input struct {
 	replaceGheActionWithGithubCom      []string
 	replaceGheActionTokenWithGithubCom string
 	matrix                             []string
+	actionCachePath                    string
 }
 
 func (i *Input) resolve(path string) string {
diff --git a/cmd/root.go b/cmd/root.go
index ba1f31d5278..59a571e2b23 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -94,6 +94,7 @@ func Execute(ctx context.Context, version string) {
 	rootCmd.PersistentFlags().StringVarP(&input.cacheServerPath, "cache-server-path", "", filepath.Join(CacheHomeDir, "actcache"), "Defines the path where the cache server stores caches.")
 	rootCmd.PersistentFlags().StringVarP(&input.cacheServerAddr, "cache-server-addr", "", common.GetOutboundIP().String(), "Defines the address to which the cache server binds.")
 	rootCmd.PersistentFlags().Uint16VarP(&input.cacheServerPort, "cache-server-port", "", 0, "Defines the port where the artifact server listens. 0 means a randomly available port.")
+	rootCmd.PersistentFlags().StringVarP(&input.actionCachePath, "action-cache-path", "", filepath.Join(CacheHomeDir, "act"), "Defines the path where the actions get cached and host workspaces created.")
 	rootCmd.SetArgs(args())
 
 	if err := rootCmd.Execute(); err != nil {
@@ -580,6 +581,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
 			ForceRebuild:                       input.forceRebuild,
 			ReuseContainers:                    input.reuseContainers,
 			Workdir:                            input.Workdir(),
+			ActionCacheDir:                     input.actionCachePath,
 			BindWorkdir:                        input.bindWorkdir,
 			LogOutput:                          !input.noOutput,
 			JSONLogger:                         input.jsonLogger,
diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go
index acffb76dc95..6dd52b06183 100644
--- a/pkg/runner/run_context.go
+++ b/pkg/runner/run_context.go
@@ -383,6 +383,9 @@ func (rc *RunContext) stopJobContainer() common.Executor {
 
 // ActionCacheDir is for rc
 func (rc *RunContext) ActionCacheDir() string {
+	if rc.Config.ActionCacheDir != "" {
+		return rc.Config.ActionCacheDir
+	}
 	var xdgCache string
 	var ok bool
 	if xdgCache, ok = os.LookupEnv("XDG_CACHE_HOME"); !ok || xdgCache == "" {
diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go
index 01fd06cae7a..aad2541a6dd 100644
--- a/pkg/runner/runner.go
+++ b/pkg/runner/runner.go
@@ -22,6 +22,7 @@ type Runner interface {
 type Config struct {
 	Actor                              string                     // the user that triggered the event
 	Workdir                            string                     // path to working directory
+	ActionCacheDir                     string                     // path used for caching action contents
 	BindWorkdir                        bool                       // bind the workdir to the job container
 	EventName                          string                     // name of event to run
 	EventPath                          string                     // path to JSON file to use for event.json in containers


Test patch: