1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-26 18:20:59 +00:00

fix: remote reusable workflows require fully qualified URLs

Implicitly prefixing a remote workflow URL with the URL of the
instance from which the workflow runs must not be a requirement.
The URL of the workflow can and must be fully qualified.
This commit is contained in:
Earl Warren 2025-08-03 17:27:17 +02:00
parent 73797fe7cd
commit fcfd4a2952
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -35,7 +35,7 @@ func newLocalReusableWorkflowExecutor(rc *RunContext) common.Executor {
// uses string format is {owner}/{repo}/.{git_platform}/workflows/{filename}@{ref} // uses string format is {owner}/{repo}/.{git_platform}/workflows/{filename}@{ref}
uses := fmt.Sprintf("%s/%s@%s", rc.Config.PresetGitHubContext.Repository, trimmedUses, rc.Config.PresetGitHubContext.Sha) uses := fmt.Sprintf("%s/%s@%s", rc.Config.PresetGitHubContext.Repository, trimmedUses, rc.Config.PresetGitHubContext.Sha)
remoteReusableWorkflow := newRemoteReusableWorkflowWithPlat(rc.Config.GitHubInstance, uses) remoteReusableWorkflow := newRemoteReusableWorkflowWithPlat(uses)
if remoteReusableWorkflow == nil { if remoteReusableWorkflow == nil {
return common.NewErrorExecutor(fmt.Errorf("expected format {owner}/{repo}/.{git_platform}/workflows/{filename}@{ref}. Actual '%s' Input string was not in a correct format", uses)) return common.NewErrorExecutor(fmt.Errorf("expected format {owner}/{repo}/.{git_platform}/workflows/{filename}@{ref}. Actual '%s' Input string was not in a correct format", uses))
} }
@ -54,7 +54,7 @@ func newLocalReusableWorkflowExecutor(rc *RunContext) common.Executor {
func newRemoteReusableWorkflowExecutor(rc *RunContext) common.Executor { func newRemoteReusableWorkflowExecutor(rc *RunContext) common.Executor {
uses := rc.Run.Job().Uses uses := rc.Run.Job().Uses
remoteReusableWorkflow := newRemoteReusableWorkflowWithPlat(rc.Config.GitHubInstance, uses) remoteReusableWorkflow := newRemoteReusableWorkflowWithPlat(uses)
if remoteReusableWorkflow == nil { if remoteReusableWorkflow == nil {
return common.NewErrorExecutor(fmt.Errorf("expected format {owner}/{repo}/.{git_platform}/workflows/{filename}@{ref}. Actual '%s' Input string was not in a correct format", uses)) return common.NewErrorExecutor(fmt.Errorf("expected format {owner}/{repo}/.{git_platform}/workflows/{filename}@{ref}. Actual '%s' Input string was not in a correct format", uses))
} }
@ -203,23 +203,22 @@ func (r *remoteReusableWorkflow) FilePath() string {
return fmt.Sprintf("./.%s/workflows/%s", r.GitPlatform, r.Filename) return fmt.Sprintf("./.%s/workflows/%s", r.GitPlatform, r.Filename)
} }
// For Gitea
// newRemoteReusableWorkflowWithPlat create a `remoteReusableWorkflow` // newRemoteReusableWorkflowWithPlat create a `remoteReusableWorkflow`
// workflows from `.gitea/workflows` and `.github/workflows` are supported // workflows matching `**/workflows/*@*` are supported
func newRemoteReusableWorkflowWithPlat(url, uses string) *remoteReusableWorkflow { func newRemoteReusableWorkflowWithPlat(uses string) *remoteReusableWorkflow {
// GitHub docs: // GitHub docs:
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses // https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses
r := regexp.MustCompile(`^([^/]+)/([^/]+)/\.([^/]+)/workflows/([^@]+)@(.*)$`) r := regexp.MustCompile(`^(.*)/([^/]+)/([^/]+)/\.([^/]+)/workflows/([^@]+)@(.*)$`)
matches := r.FindStringSubmatch(uses) matches := r.FindStringSubmatch(uses)
if len(matches) != 6 { if len(matches) != 7 {
return nil return nil
} }
return &remoteReusableWorkflow{ return &remoteReusableWorkflow{
Org: matches[1], URL: matches[1],
Repo: matches[2], Org: matches[2],
GitPlatform: matches[3], Repo: matches[3],
Filename: matches[4], GitPlatform: matches[4],
Ref: matches[5], Filename: matches[5],
URL: url, Ref: matches[6],
} }
} }