From f56fd693eeff839287301f22dca030d1696110ac Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 14 Nov 2025 20:14:23 +0000 Subject: [PATCH 1/2] Add `run_attempt` to context (#126) Fix https://github.com/go-gitea/gitea/issues/33135 Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/act/pulls/126 Reviewed-by: Lunny Xiao Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- pkg/model/github_context.go | 3 +++ pkg/runner/run_context.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/pkg/model/github_context.go b/pkg/model/github_context.go index 71221a5..53e2307 100644 --- a/pkg/model/github_context.go +++ b/pkg/model/github_context.go @@ -39,6 +39,9 @@ type GithubContext struct { ServerURL string `json:"server_url"` APIURL string `json:"api_url"` GraphQLURL string `json:"graphql_url"` + + // For Gitea + RunAttempt string `json:"run_attempt"` } func asString(v interface{}) string { diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 9bfb619..ad97ca0 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -903,6 +903,7 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext ghc.Event = preset.Event ghc.RunID = preset.RunID ghc.RunNumber = preset.RunNumber + ghc.RunAttempt = preset.RunAttempt ghc.Actor = preset.Actor ghc.Repository = preset.Repository ghc.EventName = preset.EventName @@ -1065,6 +1066,7 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon env["GITHUB_SERVER_URL"] = instance env["GITHUB_API_URL"] = instance + "/api/v1" // the version of Gitea is v1 env["GITHUB_GRAPHQL_URL"] = "" // Gitea doesn't support graphql + env["GITHUB_RUN_ATTEMPT"] = github.RunAttempt } if rc.Config.ArtifactServerPath != "" { From 5417d3ac6742842fe01f6af00f8ef08e24971d11 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 2 Dec 2025 19:36:38 +0000 Subject: [PATCH 2/2] Interpolate `uses` for remote reusable workflows (#145) Related to #127 Reviewed-on: https://gitea.com/gitea/act/pulls/145 Reviewed-by: Lunny Xiao Reviewed-by: ChristopherHX Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- pkg/runner/reusable_workflow.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/runner/reusable_workflow.go b/pkg/runner/reusable_workflow.go index a738566..c0d079e 100644 --- a/pkg/runner/reusable_workflow.go +++ b/pkg/runner/reusable_workflow.go @@ -142,12 +142,14 @@ func cloneIfRequired(rc *RunContext, remoteReusableWorkflow remoteReusableWorkfl return notExists }, func(ctx context.Context) error { + // interpolate the cloneURL + cloneURL := rc.NewExpressionEvaluator(ctx).Interpolate(ctx, remoteReusableWorkflow.CloneURL()) // Do not change the remoteReusableWorkflow.URL, because: // 1. Gitea doesn't support specifying GithubContext.ServerURL by the GITHUB_SERVER_URL env // 2. Gitea has already full URL with rc.Config.GitHubInstance when calling newRemoteReusableWorkflowWithPlat // remoteReusableWorkflow.URL = rc.getGithubContext(ctx).ServerURL return git.NewGitCloneExecutor(git.NewGitCloneExecutorInput{ - URL: remoteReusableWorkflow.CloneURL(), + URL: cloneURL, Ref: remoteReusableWorkflow.Ref, Dir: targetDirectory, Token: token, @@ -321,23 +323,28 @@ func setReusedWorkflowCallerResult(rc *RunContext, runner Runner) common.Executo } // For Gitea -// getGitCloneToken returns GITEA_TOKEN when checkCloneURL returns true, +// getGitCloneToken returns GITEA_TOKEN when shouldCloneURLUseToken returns true, // otherwise returns an empty string func getGitCloneToken(conf *Config, cloneURL string) string { - if !checkCloneURL(conf.GitHubInstance, cloneURL) { + if !shouldCloneURLUseToken(conf.GitHubInstance, cloneURL) { return "" } return conf.GetToken() } // For Gitea -// checkCloneURL returns true when the cloneURL is from the same Gitea instance that the runner is registered to -func checkCloneURL(instanceURL, cloneURL string) bool { +// shouldCloneURLUseToken returns true when the following conditions are met: +// 1. cloneURL is from the same Gitea instance that the runner is registered to +// 2. the cloneURL does not have basic auth embedded +func shouldCloneURLUseToken(instanceURL, cloneURL string) bool { u1, err1 := url.Parse(instanceURL) u2, err2 := url.Parse(cloneURL) if err1 != nil || err2 != nil { return false } + if u2.User != nil { + return false + } return u1.Host == u2.Host }