mirror of
https://gitea.com/gitea/act
synced 2026-05-06 01:37:48 +02:00
Merge branch 'main' into fix-yaml-with-prefixed-newline
This commit is contained in:
@@ -39,6 +39,9 @@ type GithubContext struct {
|
|||||||
ServerURL string `json:"server_url"`
|
ServerURL string `json:"server_url"`
|
||||||
APIURL string `json:"api_url"`
|
APIURL string `json:"api_url"`
|
||||||
GraphQLURL string `json:"graphql_url"`
|
GraphQLURL string `json:"graphql_url"`
|
||||||
|
|
||||||
|
// For Gitea
|
||||||
|
RunAttempt string `json:"run_attempt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func asString(v interface{}) string {
|
func asString(v interface{}) string {
|
||||||
|
|||||||
@@ -142,12 +142,14 @@ func cloneIfRequired(rc *RunContext, remoteReusableWorkflow remoteReusableWorkfl
|
|||||||
return notExists
|
return notExists
|
||||||
},
|
},
|
||||||
func(ctx context.Context) error {
|
func(ctx context.Context) error {
|
||||||
|
// interpolate the cloneURL
|
||||||
|
cloneURL := rc.NewExpressionEvaluator(ctx).Interpolate(ctx, remoteReusableWorkflow.CloneURL())
|
||||||
// Do not change the remoteReusableWorkflow.URL, because:
|
// Do not change the remoteReusableWorkflow.URL, because:
|
||||||
// 1. Gitea doesn't support specifying GithubContext.ServerURL by the GITHUB_SERVER_URL env
|
// 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
|
// 2. Gitea has already full URL with rc.Config.GitHubInstance when calling newRemoteReusableWorkflowWithPlat
|
||||||
// remoteReusableWorkflow.URL = rc.getGithubContext(ctx).ServerURL
|
// remoteReusableWorkflow.URL = rc.getGithubContext(ctx).ServerURL
|
||||||
return git.NewGitCloneExecutor(git.NewGitCloneExecutorInput{
|
return git.NewGitCloneExecutor(git.NewGitCloneExecutorInput{
|
||||||
URL: remoteReusableWorkflow.CloneURL(),
|
URL: cloneURL,
|
||||||
Ref: remoteReusableWorkflow.Ref,
|
Ref: remoteReusableWorkflow.Ref,
|
||||||
Dir: targetDirectory,
|
Dir: targetDirectory,
|
||||||
Token: token,
|
Token: token,
|
||||||
@@ -321,23 +323,28 @@ func setReusedWorkflowCallerResult(rc *RunContext, runner Runner) common.Executo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For Gitea
|
// For Gitea
|
||||||
// getGitCloneToken returns GITEA_TOKEN when checkCloneURL returns true,
|
// getGitCloneToken returns GITEA_TOKEN when shouldCloneURLUseToken returns true,
|
||||||
// otherwise returns an empty string
|
// otherwise returns an empty string
|
||||||
func getGitCloneToken(conf *Config, cloneURL string) string {
|
func getGitCloneToken(conf *Config, cloneURL string) string {
|
||||||
if !checkCloneURL(conf.GitHubInstance, cloneURL) {
|
if !shouldCloneURLUseToken(conf.GitHubInstance, cloneURL) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return conf.GetToken()
|
return conf.GetToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Gitea
|
// For Gitea
|
||||||
// checkCloneURL returns true when the cloneURL is from the same Gitea instance that the runner is registered to
|
// shouldCloneURLUseToken returns true when the following conditions are met:
|
||||||
func checkCloneURL(instanceURL, cloneURL string) bool {
|
// 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)
|
u1, err1 := url.Parse(instanceURL)
|
||||||
u2, err2 := url.Parse(cloneURL)
|
u2, err2 := url.Parse(cloneURL)
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if u2.User != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return u1.Host == u2.Host
|
return u1.Host == u2.Host
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -903,6 +903,7 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext
|
|||||||
ghc.Event = preset.Event
|
ghc.Event = preset.Event
|
||||||
ghc.RunID = preset.RunID
|
ghc.RunID = preset.RunID
|
||||||
ghc.RunNumber = preset.RunNumber
|
ghc.RunNumber = preset.RunNumber
|
||||||
|
ghc.RunAttempt = preset.RunAttempt
|
||||||
ghc.Actor = preset.Actor
|
ghc.Actor = preset.Actor
|
||||||
ghc.Repository = preset.Repository
|
ghc.Repository = preset.Repository
|
||||||
ghc.EventName = preset.EventName
|
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_SERVER_URL"] = instance
|
||||||
env["GITHUB_API_URL"] = instance + "/api/v1" // the version of Gitea is v1
|
env["GITHUB_API_URL"] = instance + "/api/v1" // the version of Gitea is v1
|
||||||
env["GITHUB_GRAPHQL_URL"] = "" // Gitea doesn't support graphql
|
env["GITHUB_GRAPHQL_URL"] = "" // Gitea doesn't support graphql
|
||||||
|
env["GITHUB_RUN_ATTEMPT"] = github.RunAttempt
|
||||||
}
|
}
|
||||||
|
|
||||||
if rc.Config.ArtifactServerPath != "" {
|
if rc.Config.ArtifactServerPath != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user