fix action cloning, set correct server_url for act_runner exec (#68)

1. Newest act is not able to clone action based on --default-actions-url
It might be side effect of https://gitea.com/gitea/act/pulls/67.
2. Set correct server_url, api_url, graphql_url for act_runner exec

Reviewed-on: https://gitea.com/gitea/act/pulls/68
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: Tomasz Duda <tomaszduda23@gmail.com>
Co-committed-by: Tomasz Duda <tomaszduda23@gmail.com>
This commit is contained in:
Tomasz Duda 2023-06-20 07:36:10 +00:00 committed by Jason Song
parent a165e17878
commit 515c2c429d
2 changed files with 16 additions and 7 deletions

View file

@ -874,6 +874,18 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext
ghc.APIURL = fmt.Sprintf("https://%s/api/v3", rc.Config.GitHubInstance)
ghc.GraphQLURL = fmt.Sprintf("https://%s/api/graphql", rc.Config.GitHubInstance)
}
{ // Adapt to Gitea
instance := rc.Config.GitHubInstance
if !strings.HasPrefix(instance, "http://") &&
!strings.HasPrefix(instance, "https://") {
instance = "https://" + instance
}
ghc.ServerURL = instance
ghc.APIURL = instance + "/api/v1" // the version of Gitea is v1
ghc.GraphQLURL = "" // Gitea doesn't support graphql
}
// allow to be overridden by user
if rc.Config.Env["GITHUB_SERVER_URL"] != "" {
ghc.ServerURL = rc.Config.Env["GITHUB_SERVER_URL"]

View file

@ -49,8 +49,6 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
}
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
@ -225,11 +223,7 @@ type remoteAction struct {
Ref string
}
func (ra *remoteAction) CloneURL(defaultURL string) string {
u := ra.URL
if u == "" {
u = defaultURL
}
func (ra *remoteAction) CloneURL(u string) string {
if !strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "https://") {
u = "https://" + u
}
@ -244,6 +238,9 @@ func (ra *remoteAction) IsCheckout() bool {
}
func (ra *remoteAction) GetAvailableCloneURL(actionURLs []string) (string, error) {
if ra.URL != "" {
return ra.CloneURL(ra.URL), nil
}
for _, u := range actionURLs {
cloneURL := ra.CloneURL(u)
resp, err := detectActionClient.Get(cloneURL)