Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fail to find local subworkflow of remote workflow #1876

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
matrixes := parseMatrix(input.matrix)
log.Debugf("Evaluated matrix inclusions: %v", matrixes)

planner, err := model.NewWorkflowPlanner(input.WorkflowsPath(), input.noWorkflowRecurse)
planner, err := model.NewWorkflowPlanner("", input.WorkflowsPath(), input.noWorkflowRecurse)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/artifacts/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) {
runner, err := runner.New(runnerConfig)
assert.Nil(t, err, tjfi.workflowPath)

planner, err := model.NewWorkflowPlanner(fullWorkflowPath, true)
planner, err := model.NewWorkflowPlanner(workdir, tjfi.workflowPath, true)
assert.Nil(t, err, fullWorkflowPath)

plan, err := planner.PlanEvent(tjfi.eventName)
Expand Down
10 changes: 8 additions & 2 deletions pkg/model/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@
// NewWorkflowPlanner will load a specific workflow, all workflows from a directory or all workflows from a directory and its subdirectories
//
//nolint:gocyclo
func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, error) {
func NewWorkflowPlanner(directory string, workflow string, noWorkflowRecurse bool) (WorkflowPlanner, error) {
path := ""
if directory == "" || workflow == "" {
path = directory + workflow

Check warning on line 64 in pkg/model/planner.go

View check run for this annotation

Codecov / codecov/patch

pkg/model/planner.go#L64

Added line #L64 was not covered by tests
} else {
path = filepath.Join(directory, workflow)
}
path, err := filepath.Abs(path)
if err != nil {
return nil, err
Expand Down Expand Up @@ -142,7 +148,7 @@
_ = f.Close()
return nil, fmt.Errorf("error occurring when resetting io pointer in '%s': %w", wf.workflowDirEntry.Name(), err)
}

workflow.RepoPath = directory
workflow.File = wf.workflowDirEntry.Name()
if workflow.Name == "" {
workflow.Name = wf.workflowDirEntry.Name()
Expand Down
3 changes: 1 addition & 2 deletions pkg/model/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func TestPlanner(t *testing.T) {
workdir, err := filepath.Abs("testdata")
assert.NoError(t, err, workdir)
for _, table := range tables {
fullWorkflowPath := filepath.Join(workdir, table.workflowPath)
_, err = NewWorkflowPlanner(fullWorkflowPath, table.noWorkflowRecurse)
_, err = NewWorkflowPlanner(workdir, table.workflowPath, table.noWorkflowRecurse)
if table.errorMessage == "" {
assert.NoError(t, err, "WorkflowPlanner should exit without any error")
} else {
Expand Down
1 change: 1 addition & 0 deletions pkg/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

// Workflow is the structure of the files in .github/workflows
type Workflow struct {
RepoPath string
File string
Name string `yaml:"name"`
RawOn yaml.Node `yaml:"on"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ jobs:
}

func TestReadWorkflow_Strategy(t *testing.T) {
w, err := NewWorkflowPlanner("testdata/strategy/push.yml", true)
w, err := NewWorkflowPlanner("testdata/strategy", "push.yml", true)
assert.NoError(t, err)

p, err := w.PlanJob("strategy-only-max-parallel")
Expand Down
12 changes: 9 additions & 3 deletions pkg/runner/reusable_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"fmt"
"io/fs"
"os"
"path"
"regexp"
"strings"
"sync"

"github.com/nektos/act/pkg/common"
Expand All @@ -17,7 +17,13 @@
)

func newLocalReusableWorkflowExecutor(rc *RunContext) common.Executor {
return newReusableWorkflowExecutor(rc, rc.Config.Workdir, rc.Run.Job().Uses)
job := rc.Run.Job()
if strings.Index(job.Uses, "./") == 0 {
// relative path
return newReusableWorkflowExecutor(rc, rc.Run.Workflow.RepoPath, job.Uses)
} else {

Check warning on line 24 in pkg/runner/reusable_workflow.go

View workflow job for this annotation

GitHub Actions / lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return newReusableWorkflowExecutor(rc, rc.Config.Workdir, job.Uses)
}

Check warning on line 26 in pkg/runner/reusable_workflow.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/reusable_workflow.go#L25-L26

Added lines #L25 - L26 were not covered by tests
}

func newRemoteReusableWorkflowExecutor(rc *RunContext) common.Executor {
Expand Down Expand Up @@ -114,7 +120,7 @@

func newReusableWorkflowExecutor(rc *RunContext, directory string, workflow string) common.Executor {
return func(ctx context.Context) error {
planner, err := model.NewWorkflowPlanner(path.Join(directory, workflow), true)
planner, err := model.NewWorkflowPlanner(directory, workflow, true)
if err != nil {
return err
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
}

func TestNoWorkflowsFoundByPlanner(t *testing.T) {
planner, err := model.NewWorkflowPlanner("res", true)
planner, err := model.NewWorkflowPlanner("res", "", true)
assert.NoError(t, err)

out := log.StandardLogger().Out
Expand All @@ -70,7 +70,7 @@ func TestNoWorkflowsFoundByPlanner(t *testing.T) {
}

func TestGraphMissingEvent(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/issue-1595/no-event.yml", true)
planner, err := model.NewWorkflowPlanner("testdata/issue-1595", "no-event.yml", true)
assert.NoError(t, err)

out := log.StandardLogger().Out
Expand All @@ -88,7 +88,7 @@ func TestGraphMissingEvent(t *testing.T) {
}

func TestGraphMissingFirst(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/issue-1595/no-first.yml", true)
planner, err := model.NewWorkflowPlanner("testdata/issue-1595", "no-first.yml", true)
assert.NoError(t, err)

plan, err := planner.PlanEvent("push")
Expand All @@ -98,7 +98,7 @@ func TestGraphMissingFirst(t *testing.T) {
}

func TestGraphWithMissing(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/issue-1595/missing.yml", true)
planner, err := model.NewWorkflowPlanner("testdata/issue-1595", "missing.yml", true)
assert.NoError(t, err)

out := log.StandardLogger().Out
Expand All @@ -117,7 +117,7 @@ func TestGraphWithMissing(t *testing.T) {
func TestGraphWithSomeMissing(t *testing.T) {
log.SetLevel(log.DebugLevel)

planner, err := model.NewWorkflowPlanner("testdata/issue-1595/", true)
planner, err := model.NewWorkflowPlanner("testdata/issue-1595", "", true)
assert.NoError(t, err)

out := log.StandardLogger().Out
Expand All @@ -135,7 +135,7 @@ func TestGraphWithSomeMissing(t *testing.T) {
}

func TestGraphEvent(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/basic", true)
planner, err := model.NewWorkflowPlanner("testdata/basic", "", true)
assert.NoError(t, err)

plan, err := planner.PlanEvent("push")
Expand Down Expand Up @@ -192,7 +192,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config
runner, err := New(runnerConfig)
assert.Nil(t, err, j.workflowPath)

planner, err := model.NewWorkflowPlanner(fullWorkflowPath, true)
planner, err := model.NewWorkflowPlanner(workdir, j.workflowPath, true)
assert.Nil(t, err, fullWorkflowPath)

plan, err := planner.PlanEvent(j.eventName)
Expand Down Expand Up @@ -242,6 +242,7 @@ func TestRunEvent(t *testing.T) {
{workdir, "uses-workflow", "pull_request", "", platforms, map[string]string{"secret": "keep_it_private"}},
{workdir, "uses-docker-url", "push", "", platforms, secrets},
{workdir, "act-composite-env-test", "push", "", platforms, secrets},
{workdir, "issue-1875-uses-workflow-with-sub-workflow", "dispatch", "", platforms, secrets},

// Eval
{workdir, "evalmatrix", "push", "", platforms, secrets},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Call Reusable Workflow
on:
push:

jobs:
call-reusable-workflow-with-sub:
uses: wildsheepz/TestReusableWorkflow/.github/workflows/main.yaml@ubuntu_platform
Loading