-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a policy action_shell_is_required (#281)
- Loading branch information
1 parent
d343948
commit d91c201
Showing
7 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# action_shell_is_required | ||
|
||
`shell` is required if `run` is set | ||
|
||
## Examples | ||
|
||
:x: | ||
|
||
```yaml | ||
- run: echo hello | ||
``` | ||
⭕ | ||
```yaml | ||
- run: echo hello | ||
shell: bash | ||
``` | ||
## Why? | ||
> Required if run is set. | ||
https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsstepsshell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package policy | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/suzuki-shunsuke/ghalint/pkg/config" | ||
"github.com/suzuki-shunsuke/ghalint/pkg/workflow" | ||
) | ||
|
||
type ActionShellIsRequiredPolicy struct{} | ||
|
||
func (p *ActionShellIsRequiredPolicy) Name() string { | ||
return "action_shell_is_required" | ||
} | ||
|
||
func (p *ActionShellIsRequiredPolicy) ID() string { | ||
return "011" | ||
} | ||
|
||
func (p *ActionShellIsRequiredPolicy) ApplyStep(_ *logrus.Entry, _ *config.Config, _ *StepContext, step *workflow.Step) error { | ||
if step.Run != "" && step.Shell == "" { | ||
return errors.New("shell is required if run is set") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package policy_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/suzuki-shunsuke/ghalint/pkg/policy" | ||
"github.com/suzuki-shunsuke/ghalint/pkg/workflow" | ||
) | ||
|
||
func TestActionShellIsRequiredPolicy_ApplyStep(t *testing.T) { | ||
t.Parallel() | ||
data := []struct { | ||
name string | ||
step *workflow.Step | ||
isErr bool | ||
}{ | ||
{ | ||
name: "pass", | ||
step: &workflow.Step{ | ||
Run: "echo hello", | ||
Shell: "bash", | ||
}, | ||
}, | ||
{ | ||
name: "step error", | ||
isErr: true, | ||
step: &workflow.Step{ | ||
Run: "echo hello", | ||
}, | ||
}, | ||
} | ||
p := &policy.ActionShellIsRequiredPolicy{} | ||
logE := logrus.NewEntry(logrus.New()) | ||
for _, d := range data { | ||
d := d | ||
t.Run(d.name, func(t *testing.T) { | ||
t.Parallel() | ||
if err := p.ApplyStep(logE, nil, nil, d.step); err != nil { | ||
if d.isErr { | ||
return | ||
} | ||
t.Fatal(err) | ||
} | ||
if d.isErr { | ||
t.Fatal("error must be returned") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters