diff --git a/cmd/input.go b/cmd/input.go index ed6e36b..cd3397b 100644 --- a/cmd/input.go +++ b/cmd/input.go @@ -40,6 +40,7 @@ type Input struct { artifactServerPort string jsonLogger bool noSkipCheckout bool + remoteName string } func (i *Input) resolve(path string) string { diff --git a/cmd/root.go b/cmd/root.go index 9567a42..a94f692 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -43,6 +43,7 @@ func Execute(ctx context.Context, version string) { rootCmd.Flags().StringP("job", "j", "", "run job") rootCmd.Flags().BoolP("bug-report", "", false, "Display system information for bug report") + rootCmd.Flags().StringVar(&input.remoteName, "remote-name", "origin", "git remote name that will be used to retrieve url of git repo") rootCmd.Flags().StringArrayVarP(&input.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)") rootCmd.Flags().StringArrayVarP(&input.envs, "env", "", []string{}, "env to make available to actions with optional value (e.g. --env myenv=foo or --env myenv)") rootCmd.Flags().StringArrayVarP(&input.platforms, "platform", "P", []string{}, "custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)") @@ -379,6 +380,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str ArtifactServerPath: input.artifactServerPath, ArtifactServerPort: input.artifactServerPort, NoSkipCheckout: input.noSkipCheckout, + RemoteName: input.remoteName, } r, err := runner.New(config) if err != nil { diff --git a/pkg/common/git.go b/pkg/common/git.go index b5e288f..6c1f501 100644 --- a/pkg/common/git.go +++ b/pkg/common/git.go @@ -142,8 +142,12 @@ func findGitPrettyRef(head, root, sub string) (string, error) { } // FindGithubRepo get the repo -func FindGithubRepo(file string, githubInstance string) (string, error) { - url, err := findGitRemoteURL(file) +func FindGithubRepo(file, githubInstance, remoteName string) (string, error) { + if remoteName == "" { + remoteName = "origin" + } + + url, err := findGitRemoteURL(file, remoteName) if err != nil { return "", err } @@ -151,7 +155,7 @@ func FindGithubRepo(file string, githubInstance string) (string, error) { return slug, err } -func findGitRemoteURL(file string) (string, error) { +func findGitRemoteURL(file, remoteName string) (string, error) { gitDir, err := findGitDirectory(file) if err != nil { return "", err @@ -162,7 +166,7 @@ func findGitRemoteURL(file string) (string, error) { if err != nil { return "", err } - remote, err := gitconfig.GetSection("remote \"origin\"") + remote, err := gitconfig.GetSection(fmt.Sprintf(`remote "%s"`, remoteName)) if err != nil { return "", err } diff --git a/pkg/common/git_test.go b/pkg/common/git_test.go index 97829db..48c6455 100644 --- a/pkg/common/git_test.go +++ b/pkg/common/git_test.go @@ -47,7 +47,7 @@ func TestFindGitSlug(t *testing.T) { func testDir(t *testing.T) string { basedir, err := ioutil.TempDir("", "act-test") require.NoError(t, err) - t.Cleanup(func() { os.RemoveAll(basedir) }) + t.Cleanup(func() { _ = os.RemoveAll(basedir) }) return basedir } @@ -86,7 +86,7 @@ func TestFindGitRemoteURL(t *testing.T) { err = gitCmd("config", "-f", fmt.Sprintf("%s/.git/config", basedir), "--add", "remote.origin.url", remoteURL) assert.NoError(err) - u, err := findGitRemoteURL(basedir) + u, err := findGitRemoteURL(basedir, "origin") assert.NoError(err) assert.Equal(remoteURL, u) } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index e5caaf5..bbc2d14 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -510,7 +510,7 @@ func (rc *RunContext) getGithubContext() *model.GithubContext { } repoPath := rc.Config.Workdir - repo, err := common.FindGithubRepo(repoPath, rc.Config.GitHubInstance) + repo, err := common.FindGithubRepo(repoPath, rc.Config.GitHubInstance, rc.Config.RemoteName) if err != nil { log.Warningf("unable to get git repo: %v", err) } else { diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index f846d96..751ee8a 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -51,6 +51,7 @@ type Config struct { ArtifactServerPort string // the port the artifact server binds to CompositeRestrictions *model.CompositeRestrictions // describes which features are available in composite actions NoSkipCheckout bool // do not skip actions/checkout + RemoteName string // remote name in local git repo config } // Resolves the equivalent host path inside the container