Skip to content

Commit

Permalink
now workflow calls can be nested (fix #201)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Aug 25, 2022
1 parent ecd256c commit 8db3e64
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 40 deletions.
13 changes: 1 addition & 12 deletions docs/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1965,9 +1965,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- run: echo "${{ inputs.scheme }}://${{ inputs.host }}:${{ inputs.port }}${{ inputs.path }}"
nested:
# ERROR: Nested workflow call is not allowed
uses: onwer/repo/w.yml@main
```

Output:
Expand All @@ -1989,21 +1986,13 @@ test.yaml:26:18: input "path" of workflow_call event has the default value "", b
|
26 | default: ''
| ^~
test.yaml:35:11: reusable workflow cannot be nested. but this workflow hooks "workflow_call" event at line:2,col:3 [workflow-call]
|
35 | uses: onwer/repo/w.yml@main
| ^~~~~~~~~~~~~~~~~~~~~
```

[Playground](https://rhysd.github.io/actionlint#eJx9kc1ugzAQhO99ilVUKSdA/Tn51AfooT/quTKwFBLjdey1KIp499pAIkRLb/CtPTPeIS1uADqyx0pR91lIpSIAaLTx7KZvAFfU2OLlD6BEV9jGcENawPs4BKrg4+15caSSXrGAmtm4K+beoADHttFfM6zJsfh9D79laxSmBbX/3TZkeSPYSxhtxtqLu/uHx/1KWvs2RzvDk0fbb2i/xtlafNKg/IAFX+JJrrfihdFaweLJNxZLAWw9/pF6HXjexYHysaySJjPrtUuiic+9Zp8oyeimTI7RXItN4smw66Im2N2ez3Pv6VQ4DIPIsgWOVUW4QHH/AS1JfNcw7IKFDqbhMaOZd+jCcnSHNrNoKOvSvlVPrWz0D3BGvIY=)
[Playground]()
[Playground](https://rhysd.github.io/actionlint#eJx9kctuwyAQRff9ilFUKSsn6mPFN3TRh7quMB4XUswQGJRGkf+9JjiR5dbdwZnhzmUuOXEDcKDw1Vo6fChpbQYAxvnEsZwBotLY4eUG0GBUwXg25AS8nYtALby/Pk1aWpksC9DMPl4xHz0KiByM+xyhpsji9zv8lp23uFHU/ffaU+AFY89DadHWWtzdPzyuZ9IudTWGEe4ThuOC9kuuzcWLBtU7VHyxJ1kv2RtKc4WA+2QCNgI4JPzD9dzwuIsd1eewGirDQnKxykNSnRynykrGWDxFRn8Ntsqdw66VJljdnk5j7psSOPS92G4nOEeV4QTl/Q9oSvK/+n71A7U5rsA=)

Unlike inputs of action, inputs of a workflow must specify their types. actionlint validates input types and checks the default
values are correctly typed. For more details, see [the official document][create-reusable-workflow-doc].

In addition, nested workflow call is not allowed. actionlint checks reusable workflow is not called when the workflow hooks
`workflow_call` event.

### Check reusable workflow call syntax

Example input:
Expand Down
2 changes: 0 additions & 2 deletions rule_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,6 @@ func (rule *RuleExpression) checkWorkflowCallOutputs(outputs map[*String]*Workfl
var o *ObjectType
if j.WorkflowCall != nil {
// Outputs are not defined in jobs.<job_id> section when it is reusable workflow call.
// At the point of writing this comment, reusable workflow cannot be nested. So reaching
// here would cause other error in some other checks.
o = NewEmptyObjectType()
} else {
p := make(map[string]ExprType, len(j.Outputs))
Expand Down
4 changes: 0 additions & 4 deletions rule_workflow_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ func (rule *RuleWorkflowCall) VisitJobPre(n *Job) error {
return nil
}

if rule.workflowCallEventPos != nil {
rule.errorf(u.Pos, "reusable workflow cannot be nested. but this workflow hooks \"workflow_call\" event at %s", rule.workflowCallEventPos)
}

if !strings.Contains(u.Value, "${{") && !(checkWorkflowCallUsesLocalFormat(u.Value) || checkWorkflowCallUsesRepoFormat(u.Value)) {
rule.errorf(u.Pos, "reusable workflow call %q at \"uses\" is not following the format \"owner/repo/path/to/workflow.yml@ref\" nor \"./path/to/workflow.yml\". see https://docs.github.com/en/actions/learn-github-actions/reusing-workflows for more details", u.Value)
}
Expand Down
22 changes: 5 additions & 17 deletions rule_workflow_call_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package actionlint

import (
"strings"
"testing"
)

Expand Down Expand Up @@ -56,14 +55,11 @@ func TestRuleWorkflowCallCheckWorkflowCallUsesFormat(t *testing.T) {
}
}

func TestRuleWorkflowCallCheckCannotCallNestedly(t *testing.T) {
func TestRuleWorkflowCallNestedWorkflowCalls(t *testing.T) {
w := &Workflow{
On: []Event{
&WorkflowCallEvent{
Pos: &Pos{
Line: 12,
Col: 34,
},
Pos: &Pos{},
},
},
}
Expand All @@ -86,17 +82,9 @@ func TestRuleWorkflowCallCheckCannotCallNestedly(t *testing.T) {
if err := r.VisitJobPre(j); err != nil {
t.Fatal(err)
}
errs := r.Errs()

err := r.Errs()[0]
msg := err.Error()

want := "reusable workflow cannot be nested"
if !strings.Contains(msg, want) {
t.Errorf("error message %q does not contain expected message %q", msg, want)
}

want = "line:12,col:34"
if !strings.Contains(msg, want) {
t.Errorf("error message %q does not contain proper position %q", msg, want)
if len(errs) > 0 {
t.Fatal("unexpected errors:", errs)
}
}
1 change: 0 additions & 1 deletion testdata/err/nested_workflow_call.out

This file was deleted.

1 change: 0 additions & 1 deletion testdata/examples/workflow_call_definitions.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ test.yaml:9:7: "description" is missing at "host" input of workflow_call event [
test.yaml:16:18: input of workflow_call event "port" is typed as number but its default value ":1234" cannot be parsed as a float number: strconv.ParseFloat: parsing ":1234": invalid syntax [events]
test.yaml:21:15: invalid value "object" for input type of workflow_call event. it must be one of "boolean", "number", or "string" [syntax-check]
test.yaml:26:18: input "path" of workflow_call event has the default value "", but it is also required. if an input is marked as required, its default value will never be used [events]
test.yaml:35:11: reusable workflow cannot be nested. but this workflow hooks "workflow_call" event at line:2,col:3 [workflow-call]
3 changes: 0 additions & 3 deletions testdata/examples/workflow_call_definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,3 @@ jobs:
runs-on: ubuntu-latest
steps:
- run: echo "${{ inputs.scheme }}://${{ inputs.host }}:${{ inputs.port }}${{ inputs.path }}"
nested:
# ERROR: Nested workflow call is not allowed
uses: onwer/repo/w.yml@main
File renamed without changes.

0 comments on commit 8db3e64

Please sign in to comment.