Skip to content

Commit 5e3e79c

Browse files
authored
feat: add sg_flags option to pass additional ast-grep flags (#5)
* feat: add `sg_flags` option to pass additional ast-grep flags Signed-off-by: Rintaro Okamura <[email protected]> * docs: update readme - update inputs - add usage example about custom parser Signed-off-by: Rintaro Okamura <[email protected]> * docs: fix typo Signed-off-by: Rintaro Okamura <[email protected]> --------- Signed-off-by: Rintaro Okamura <[email protected]>
1 parent 9948874 commit 5e3e79c

File tree

3 files changed

+108
-47
lines changed

3 files changed

+108
-47
lines changed

README.md

+100-45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# action-ast-grep
1+
# GitHub Action: Run ast-grep with reviewdog
22

33
[![Test](https://github.com/reviewdog/action-ast-grep/workflows/Test/badge.svg)](https://github.com/reviewdog/action-ast-grep/actions?query=workflow%3ATest)
44
[![reviewdog](https://github.com/reviewdog/action-ast-grep/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-ast-grep/actions?query=workflow%3Areviewdog)
@@ -7,58 +7,79 @@
77
[![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)
88
[![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)
99

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-
1310
This is an action to run [ast-grep(sg)][ast-grep] with [reviewdog][reviewdog].
1411

1512
[ast-grep]: https://github.com/ast-grep/ast-grep
1613
[reviewdog]: https://github.com/reviewdog/reviewdog
1714

18-
## Input
15+
## Examples
1916

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.
5978

6079
## Usage
6180

81+
### Basic
82+
6283
Create `sgconfig.yml` and some rules in your repository by following the [project setup guide][sg-scan-guide].
6384

6485
Add a workflow to run action-ast-grep that triggered by pull request event.
@@ -74,7 +95,7 @@ jobs:
7495
- uses: actions/checkout@v4
7596
- uses: reviewdog/action-ast-grep@v1
7697
with:
77-
github_token: ${{ secrets.github_token }}
98+
github_token: ${{ secrets.GITHUB_TOKEN }}
7899
# Change reviewdog reporter if you need [github-check,github-pr-review,github-pr-check].
79100
reporter: github-pr-review
80101
# Change reporter level if you need.
@@ -88,6 +109,40 @@ Reviewdog will report `ast-grep scan` result.
88109

89110
[sg-scan-guide]: https://ast-grep.github.io/guide/scan-project.html
90111

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+
91146
## Development
92147

93148
### Release

action.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ inputs:
2626
fail_on_error:
2727
description: |
2828
Exit code for reviewdog when errors are found [true,false].
29-
Default is `false`.
3029
default: 'false'
3130
reviewdog_flags:
3231
description: 'Additional reviewdog flags.'
@@ -41,6 +40,9 @@ inputs:
4140
sg_config:
4241
description: 'path to the ast-grep config file'
4342
default: 'sgconfig.yml'
43+
sg_flags:
44+
description: 'Additional ast-grep flags.'
45+
default: ''
4446

4547
runs:
4648
using: 'composite'
@@ -64,6 +66,7 @@ runs:
6466
INPUT_OUTPUT_DIR: ${{ inputs.output_dir }}
6567
INPUT_SG_VERSION: ${{ inputs.sg_version }}
6668
INPUT_SG_CONFIG: ${{ inputs.sg_config }}
69+
INPUT_SG_FLAGS: ${{ inputs.sg_flags }}
6770
DEFAULT_SG_VERSION: 0.26.2
6871
- if: inputs.reporter == 'sarif'
6972
uses: github/codeql-action/upload-sarif@v3

script.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ echo '::endgroup::'
3434
echo '::group:: Running ast-grep with reviewdog 🐶 ...'
3535

3636
# shellcheck disable=SC2086
37-
ast-grep scan --config="${INPUT_SG_CONFIG}" --json=compact |
37+
ast-grep scan \
38+
--config="${INPUT_SG_CONFIG}" \
39+
--json=compact \
40+
${INPUT_SG_FLAGS} |
3841
jq -f "${GITHUB_ACTION_PATH}/to-rdjsonl.jq" -c |
3942
reviewdog \
4043
-f=rdjsonl \

0 commit comments

Comments
 (0)