Skip to content

Commit 21cf572

Browse files
authored
[build] Enforce coding standard for grammars. (#3875)
* Update static checking to include coding standard format. * Shunt output to stderr so Github Actions will make a copy of the error messages to a top-level summary. * Test everything if there are no grammars to test. * Parallelize static tests. * Undo install of js. * Remove ".". * Do not do ".". * Fix other block of statements for ".". * Try this first for warning. * Another try, from doc, https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#about-workflow-commands * Try this, directly from the github docs. * Update with annotations. * Add automatic reformat on merge with master. * Add fixes discovered with "test-3875" repo. https://github.com/kaby76/test-3875 * Update main.yml * Add in explicit coding style for grammars. * Add in "naive check" for manual deletions of existing antlr-format changes. People should not change the antlr-format strings. #3875 (comment)
1 parent 412a13e commit 21cf572

File tree

4 files changed

+509
-64
lines changed

4 files changed

+509
-64
lines changed

.github/workflows/main.yml

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8+
89
concurrency:
9-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
1011
cancel-in-progress: true
12+
1113
jobs:
1214
setup:
1315
runs-on: ubuntu-latest
@@ -26,6 +28,39 @@ jobs:
2628
shell: bash
2729
run: |
2830
dotnet tool restore
31+
- name: Check grammar coding standards
32+
continue-on-error: false
33+
run: |
34+
if [ "${{github.event_name}}" == "pull_request" ]; then
35+
Before="${{github.event.pull_request.base.sha}}"
36+
After="${{github.event.pull_request.head.sha}}"
37+
else
38+
Before="${{github.event.before}}"
39+
After="${{github.event.after}}"
40+
fi
41+
# check for bad coding standard in grammar by doing a reformat.
42+
bash _scripts/reformat.sh -f diff $Before $After
43+
- name: Commit changes
44+
# git commit reformatting changes if any, but only if on master branch.
45+
# If there were no changes, this is a no-op.
46+
if: github.ref == 'refs/heads/master'
47+
continue-on-error: false
48+
shell: bash
49+
run: |
50+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
51+
git config --local user.name "github-actions[bot]"
52+
git add --all
53+
git commit -m "Reformat to coding standard."
54+
- name: Push changes
55+
# git push changes to "master" branch.
56+
# make sure to uncheck "Require a pull request before merging" in gh actions, "Branches" section.
57+
uses: ad-m/github-push-action@master
58+
if: github.ref == 'refs/heads/master'
59+
continue-on-error: false
60+
with:
61+
github_token: ${{ secrets.GITHUB_TOKEN }}
62+
branch: ${{ github.ref }}
63+
force_with_lease: true
2964
- name: Gather targets.
3065
id: step1
3166
shell: bash
@@ -157,13 +192,13 @@ jobs:
157192
}
158193
_scripts/test.ps1 -target ${{ matrix.language }} -pc "$Before" -cc "$After"
159194
160-
static-checks:
195+
static-check:
161196
runs-on: ${{ matrix.os }}
162197
strategy:
163198
fail-fast: false
164199
matrix:
165200
os: [ ubuntu-latest]
166-
language: [ CSharp ]
201+
test: [ useless-parens ]
167202
steps:
168203
- name: Info
169204
shell: bash
@@ -195,23 +230,6 @@ jobs:
195230
dotnet --version
196231
java --version
197232
javac --version
198-
- name: Install Dart
199-
if: ${{ matrix.language == 'Dart' }}
200-
uses: dart-lang/setup-dart@v1
201-
- name: Test Dart
202-
if: ${{ matrix.language == 'Dart' }}
203-
run: |
204-
dart --version
205-
- name: Install Go
206-
if: ${{ matrix.language == 'Go' }}
207-
uses: actions/setup-go@v5
208-
with:
209-
go-version: '^1.21.0'
210-
cache: false
211-
- name: Test Go
212-
if: ${{ matrix.language == 'Go' }}
213-
run: |
214-
go version
215233
- name: Install Python
216234
uses: actions/[email protected]
217235
with:
@@ -228,15 +246,6 @@ jobs:
228246
- name: Install Antlr tool
229247
run: |
230248
pip install antlr4-tools
231-
- name: Install JavaScript
232-
if: ${{ matrix.language == 'JavaScript' }}
233-
uses: actions/[email protected]
234-
with:
235-
node-version: '16.13.0'
236-
- name: Test JavaScript
237-
if: ${{ matrix.language == 'JavaScript' }}
238-
run: |
239-
node --version
240249
- name: Install Trash
241250
shell: bash
242251
run: |
@@ -255,6 +264,6 @@ jobs:
255264
Before="${{github.event.before}}"
256265
After="${{github.event.after}}"
257266
fi
258-
bash _scripts/test-static-checks.sh -t ${{matrix.language}} -f diff $Before $After
267+
bash _scripts/test-static-checks.sh -t ${{matrix.test}} -f diff $Before $After
259268
260269

0 commit comments

Comments
 (0)