Repository: nektos/act (language: go)

Issue:
Support for ssh remote workflows (and actions) or using git config
### Act version

act version 0.2.40-14-g932863b

### Feature description

I'm using a build from `master` that contains the [new feature for remote workflows](https://github.com/nektos/act/pull/1525). The remote workflows are hard coded to use HTTPS, and I need SSH support.

https://github.com/nektos/act/blob/82a8c1e80dfcd73842bc0359ca8447303b6fcc08/pkg/runner/reusable_workflow.go#L109

Normally I would use the `insteadOf` config to fix this but it didn't seem to work.

```shell
git config --global url."ssh://git@github.com/".insteadOf "https://github.com/"
```

```shell
% act pull_request
[build-test-release.yaml/MyWorkflow]   ☁  git clone 'https://github.com/myorg/reusable-workflows' # ref=my_branch
[build-test-release.yaml/MyWorkflow] Unable to clone https://github.com/myorg/reusable-workflows refs/heads/my_branch: authentication required
Error: authentication required
```

However, if I manually clone it, the `insteadOf` config works fine. I noticed the clone is not run in a container, so I'm not sure if it is otherwise ignoring the global git config.

```shell
% git clone 'https://github.com/myorg/reusable-workflows'
Cloning into 'reusable-workflows'...
remote: Enumerating objects: 1183, done.
remote: Counting objects: 100% (360/360), done.
...
```



Discussion / hints:
a workaround for this is to manually checkout the repo, then checkout the ref. 

```shell
git clone https://github.com/{{org}}/{{repo}} ~/.cache/act/{{org}-{{repo}}-.github-workflows-{{workflow_filename}}@{{ ref | replace("/", "-")}}/
cd ~/.cache/act/{{org}-{{repo}}-.github-workflows-{{workflow_filename}}.yaml@{{ ref | replace("/", "-")}}/
git checkout {{ref}}
```


I noticed this is lacking for remote actions as well that require SSH. The workaround does not work for the remote actions.
By the way, why does not `act` clone using `GITHUB_TOKEN` ? `gh-cli` already supports to clone using `GITHUB_TOKEN`. https://cli.github.com/manual/gh_repo_clone

EDIT: My bad, I just had to do `act -s GITHUB_TOKEN=$GITHUB_TOKEN`

Fix patch:
diff --git a/pkg/runner/reusable_workflow.go b/pkg/runner/reusable_workflow.go
index 1ffa22b7bff..67e04037701 100644
--- a/pkg/runner/reusable_workflow.go
+++ b/pkg/runner/reusable_workflow.go
@@ -26,9 +26,12 @@ func newRemoteReusableWorkflowExecutor(rc *RunContext) common.Executor {
 	if remoteReusableWorkflow == nil {
 		return common.NewErrorExecutor(fmt.Errorf("expected format {owner}/{repo}/.github/workflows/{filename}@{ref}. Actual '%s' Input string was not in a correct format", uses))
 	}
-	remoteReusableWorkflow.URL = rc.Config.GitHubInstance
 
-	workflowDir := fmt.Sprintf("%s/%s", rc.ActionCacheDir(), safeFilename(uses))
+	// uses with safe filename makes the target directory look something like this {owner}-{repo}-.github-workflows-{filename}@{ref}
+	// instead we will just use {owner}-{repo}@{ref} as our target directory. This should also improve performance when we are using
+	// multiple reusable workflows from the same repository and ref since for each workflow we won't have to clone it again
+	filename := fmt.Sprintf("%s/%s@%s", remoteReusableWorkflow.Org, remoteReusableWorkflow.Repo, remoteReusableWorkflow.Ref)
+	workflowDir := fmt.Sprintf("%s/%s", rc.ActionCacheDir(), safeFilename(filename))
 
 	return common.NewPipelineExecutor(
 		newMutexExecutor(cloneIfRequired(rc, *remoteReusableWorkflow, workflowDir)),
@@ -56,12 +59,15 @@ func cloneIfRequired(rc *RunContext, remoteReusableWorkflow remoteReusableWorkfl
 			notExists := errors.Is(err, fs.ErrNotExist)
 			return notExists
 		},
-		git.NewGitCloneExecutor(git.NewGitCloneExecutorInput{
-			URL:   remoteReusableWorkflow.CloneURL(),
-			Ref:   remoteReusableWorkflow.Ref,
-			Dir:   targetDirectory,
-			Token: rc.Config.Token,
-		}),
+		func(ctx context.Context) error {
+			remoteReusableWorkflow.URL = rc.getGithubContext(ctx).ServerURL
+			return git.NewGitCloneExecutor(git.NewGitCloneExecutorInput{
+				URL:   remoteReusableWorkflow.CloneURL(),
+				Ref:   remoteReusableWorkflow.Ref,
+				Dir:   targetDirectory,
+				Token: rc.Config.Token,
+			})(ctx)
+		},
 		nil,
 	)
 }
@@ -108,7 +114,7 @@ type remoteReusableWorkflow struct {
 }
 
 func (r *remoteReusableWorkflow) CloneURL() string {
-	return fmt.Sprintf("https://%s/%s/%s", r.URL, r.Org, r.Repo)
+	return fmt.Sprintf("%s/%s/%s", r.URL, r.Org, r.Repo)
 }
 
 func newRemoteReusableWorkflow(uses string) *remoteReusableWorkflow {
@@ -124,6 +130,6 @@ func newRemoteReusableWorkflow(uses string) *remoteReusableWorkflow {
 		Repo:     matches[2],
 		Filename: matches[3],
 		Ref:      matches[4],
-		URL:      "github.com",
+		URL:      "https://github.com",
 	}
 }
diff --git a/pkg/runner/step_action_remote.go b/pkg/runner/step_action_remote.go
index 029ed5c4f83..e23dcf9918b 100644
--- a/pkg/runner/step_action_remote.go
+++ b/pkg/runner/step_action_remote.go
@@ -46,18 +46,17 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
 			return fmt.Errorf("Expected format {org}/{repo}[/path]@ref. Actual '%s' Input string was not in a correct format", sar.Step.Uses)
 		}
 
-		sar.remoteAction.URL = sar.RunContext.Config.GitHubInstance
-
 		github := sar.getGithubContext(ctx)
+		sar.remoteAction.URL = github.ServerURL
+
 		if sar.remoteAction.IsCheckout() && isLocalCheckout(github, sar.Step) && !sar.RunContext.Config.NoSkipCheckout {
 			common.Logger(ctx).Debugf("Skipping local actions/checkout because workdir was already copied")
 			return nil
 		}
 
-		sar.remoteAction.URL = sar.RunContext.Config.GitHubInstance
 		for _, action := range sar.RunContext.Config.ReplaceGheActionWithGithubCom {
 			if strings.EqualFold(fmt.Sprintf("%s/%s", sar.remoteAction.Org, sar.remoteAction.Repo), action) {
-				sar.remoteAction.URL = "github.com"
+				sar.remoteAction.URL = "https://github.com"
 				github.Token = sar.RunContext.Config.ReplaceGheActionTokenWithGithubCom
 			}
 		}
@@ -214,7 +213,7 @@ type remoteAction struct {
 }
 
 func (ra *remoteAction) CloneURL() string {
-	return fmt.Sprintf("https://%s/%s/%s", ra.URL, ra.Org, ra.Repo)
+	return fmt.Sprintf("%s/%s/%s", ra.URL, ra.Org, ra.Repo)
 }
 
 func (ra *remoteAction) IsCheckout() bool {
@@ -240,7 +239,7 @@ func newRemoteAction(action string) *remoteAction {
 		Repo: matches[2],
 		Path: matches[4],
 		Ref:  matches[6],
-		URL:  "github.com",
+		URL:  "https://github.com",
 	}
 }
 


Test patch: