1
- # action- ast-grep
1
+ # GitHub Action: Run ast-grep with reviewdog
2
2
3
3
[ ![ Test] ( https://github.com/reviewdog/action-ast-grep/workflows/Test/badge.svg )] ( https://github.com/reviewdog/action-ast-grep/actions?query=workflow%3ATest )
4
4
[ ![ reviewdog] ( https://github.com/reviewdog/action-ast-grep/workflows/reviewdog/badge.svg )] ( https://github.com/reviewdog/action-ast-grep/actions?query=workflow%3Areviewdog )
7
7
[ ![ GitHub release (latest SemVer)] ( https://img.shields.io/github/v/release/reviewdog/action-ast-grep?logo=github&sort=semver )] ( https://github.com/reviewdog/action-ast-grep/releases )
8
8
[ ![ action-bumpr supported] ( https://img.shields.io/badge/bumpr-supported-ff69b4?logo=github&link=https://github.com/haya14busa/action-bumpr )] ( https://github.com/haya14busa/action-bumpr )
9
9
10
- ![ demo1] ( https://github.com/user-attachments/assets/1c767bc0-43c4-4a60-ab97-b8b8e916ddc8 )
11
- ![ demo2] ( https://github.com/user-attachments/assets/3c341c29-536c-4032-b5f4-f9ec06731dfe )
12
-
13
10
This is an action to run [ ast-grep(sg)] [ ast-grep ] with [ reviewdog] [ reviewdog ] .
14
11
15
12
[ ast-grep ] : https://github.com/ast-grep/ast-grep
16
13
[ reviewdog ] : https://github.com/reviewdog/reviewdog
17
14
18
- ## Input
15
+ ## Examples
19
16
20
- ``` yaml
21
- inputs :
22
- github_token :
23
- description : ' GITHUB_TOKEN'
24
- default : ' ${{ github.token }}'
25
- workdir :
26
- description : ' Working directory relative to the root directory.'
27
- default : ' .'
28
- # ## Flags for reviewdog ###
29
- tool_name :
30
- description : ' Tool name to use for reviewdog reporter.'
31
- default : ' ast-grep'
32
- level :
33
- description : ' Report level for reviewdog [info,warning,error].'
34
- default : ' error'
35
- reporter :
36
- description : ' Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].'
37
- default : ' github-check'
38
- filter_mode :
39
- description : |
40
- Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
41
- Default is added.
42
- default : ' added'
43
- fail_on_error :
44
- description : |
45
- Exit code for reviewdog when errors are found [true,false].
46
- Default is `false`.
47
- default : ' false'
48
- reviewdog_flags :
49
- description : ' Additional reviewdog flags.'
50
- default : ' '
51
- # ## Flags for ast-grep ###
52
- sg_version :
53
- description : ' ast-grep version.'
54
- default : ' '
55
- sg_config :
56
- description : ' path to the ast-grep config file'
57
- default : ' sgconfig.yml'
58
- ` ` `
17
+ ![ demo1] ( https://github.com/user-attachments/assets/1c767bc0-43c4-4a60-ab97-b8b8e916ddc8 )
18
+ ![ demo2] ( https://github.com/user-attachments/assets/3c341c29-536c-4032-b5f4-f9ec06731dfe )
19
+
20
+ ## Inputs
21
+
22
+ ### ` github_token `
23
+
24
+ GITHUB_TOKEN
25
+ The default is ` ${{ github.token }} ` .
26
+
27
+ ### ` workdir `
28
+
29
+ Working directory relative to the root directory.
30
+ The default is ` . ` .
31
+
32
+ ### ` tool_name `
33
+
34
+ Tool name to use for reviewdog reporter.
35
+ The default is ` ast-grep ` .
36
+
37
+ ### ` level `
38
+
39
+ Report level for reviewdog [ info,warning,error] .
40
+ The default is ` error ` .
41
+
42
+ ### ` reporter `
43
+
44
+ Reporter of reviewdog command [ github-check,github-pr-review,github-pr-check] .
45
+ The default is ` github-check ` .
46
+
47
+ ### ` filter_mode `
48
+
49
+ Filtering mode for the reviewdog command [ added,diff_context,file,nofilter] .
50
+ Default is ` added ` except that sarif reporter uses ` nofilter ` .
51
+
52
+ ### ` fail_on_error `
53
+
54
+ Exit code for reviewdog when errors are found [ true,false] .
55
+ The default is ` false ` .
56
+
57
+ ### ` reviewdog_flags `
58
+
59
+ Additional reviewdog flags.
60
+
61
+ ### ` output_dir `
62
+
63
+ Output directory of reviewdog result. Useful for -reporter=sarif
64
+ The default is ` ../reviewdog-results ` .
65
+
66
+ ### ` sg_version `
67
+
68
+ ast-grep version.
69
+
70
+ ### ` sg_config `
71
+
72
+ The path to the ast-grep config file.
73
+ The default is ` sgconfig.yml ` .
74
+
75
+ ### ` sg_flags `
76
+
77
+ Additional ast-grep flags.
59
78
60
79
## Usage
61
80
81
+ ### Basic
82
+
62
83
Create ` sgconfig.yml ` and some rules in your repository by following the [ project setup guide] [ sg-scan-guide ] .
63
84
64
85
Add a workflow to run action-ast-grep that triggered by pull request event.
74
95
- uses : actions/checkout@v4
75
96
- uses : reviewdog/action-ast-grep@v1
76
97
with :
77
- github_token: ${{ secrets.github_token }}
98
+ github_token : ${{ secrets.GITHUB_TOKEN }}
78
99
# Change reviewdog reporter if you need [github-check,github-pr-review,github-pr-check].
79
100
reporter : github-pr-review
80
101
# Change reporter level if you need.
@@ -88,6 +109,40 @@ Reviewdog will report `ast-grep scan` result.
88
109
89
110
[sg-scan-guide] : https://ast-grep.github.io/guide/scan-project.html
90
111
112
+ # ## Advanced: Use Custom Language Parser
113
+
114
+ ast-grep experimentally supports custom languages. ([ref][sg-custom-lang])
115
+
116
+ To use this feature with this action, build tree-sitter parsers before calling this action on your workflow.
117
+
118
+ For building tree-sitter parsers, [rinx/setup-tree-sitter-parser][rinx/setup-tree-sitter-parser] is useful.
119
+
120
+ ` ` ` yaml
121
+ name: reviewdog
122
+ on: [pull_request]
123
+ jobs:
124
+ ast-grep:
125
+ name: runner / ast-grep / fennel
126
+ runs-on: ubuntu-latest
127
+ steps:
128
+ - uses: actions/checkout@v4
129
+ - name: Build tree-sitter grammar for fennel
130
+ uses: rinx/setup-tree-sitter-parser@v1
131
+ with:
132
+ # this action will place the build artifact here.
133
+ parser_dir: ./
134
+ parser_repository: alexmozaidze/tree-sitter-fennel
135
+ - name: Run ast-grep with reviewdog
136
+ uses: reviewdog/action-ast-grep@v1
137
+ with:
138
+ github_token: ${{ secrets.GITHUB_TOKEN }}
139
+ level: info
140
+ reporter: github-pr-review
141
+ ` ` `
142
+
143
+ [sg-custom-lang] : https://ast-grep.github.io/advanced/custom-language.html
144
+ [rinx/setup-tree-sitter-parser] : https://github.com/rinx/setup-tree-sitter-parser
145
+
91
146
# # Development
92
147
93
148
# ## Release
0 commit comments