Support reusing workflows with absolute URLs (#104)
Resolve https://gitea.com/gitea/act_runner/issues/507 Reviewed-on: https://gitea.com/gitea/act/pulls/104 Reviewed-by: Jason Song <i@wolfogre.com> Co-authored-by: Zettat123 <zettat123@gmail.com> Co-committed-by: Zettat123 <zettat123@gmail.com>
This commit is contained in:
@@ -54,10 +54,18 @@ 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)
|
var remoteReusableWorkflow *remoteReusableWorkflow
|
||||||
|
if strings.HasPrefix(uses, "http://") || strings.HasPrefix(uses, "https://") {
|
||||||
|
remoteReusableWorkflow = newRemoteReusableWorkflowFromAbsoluteURL(uses)
|
||||||
|
if remoteReusableWorkflow == nil {
|
||||||
|
return common.NewErrorExecutor(fmt.Errorf("expected format http(s)://{domain}/{owner}/{repo}/.{git_platform}/workflows/{filename}@{ref}. Actual '%s' Input string was not in a correct format", uses))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
remoteReusableWorkflow = newRemoteReusableWorkflowWithPlat(rc.Config.GitHubInstance, 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))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// uses with safe filename makes the target directory look something like this {owner}-{repo}-.github-workflows-{filename}@{ref}
|
// uses with safe filename makes the target directory look something like this {owner}-{repo}-.github-workflows-{filename}@{ref}
|
||||||
// instead we will just use {owner}-{repo}@{ref} as our target directory. This should also improve performance when we are using
|
// instead we will just use {owner}-{repo}@{ref} as our target directory. This should also improve performance when we are using
|
||||||
@@ -226,6 +234,24 @@ func newRemoteReusableWorkflowWithPlat(url, uses string) *remoteReusableWorkflow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For Gitea
|
||||||
|
// newRemoteReusableWorkflowWithPlat create a `remoteReusableWorkflow` from an absolute url
|
||||||
|
func newRemoteReusableWorkflowFromAbsoluteURL(uses string) *remoteReusableWorkflow {
|
||||||
|
r := regexp.MustCompile(`^(https?://.*)/([^/]+)/([^/]+)/\.([^/]+)/workflows/([^@]+)@(.*)$`)
|
||||||
|
matches := r.FindStringSubmatch(uses)
|
||||||
|
if len(matches) != 7 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &remoteReusableWorkflow{
|
||||||
|
URL: matches[1],
|
||||||
|
Org: matches[2],
|
||||||
|
Repo: matches[3],
|
||||||
|
GitPlatform: matches[4],
|
||||||
|
Filename: matches[5],
|
||||||
|
Ref: matches[6],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// deprecated: use newRemoteReusableWorkflowWithPlat
|
// deprecated: use newRemoteReusableWorkflowWithPlat
|
||||||
func newRemoteReusableWorkflow(uses string) *remoteReusableWorkflow {
|
func newRemoteReusableWorkflow(uses string) *remoteReusableWorkflow {
|
||||||
// GitHub docs:
|
// GitHub docs:
|
||||||
|
|||||||
Reference in New Issue
Block a user