feat: add linter action for antlr #4
This file contains hidden or 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
| name: ANTLR Grammar Lint | |
| on: | |
| push: | |
| paths: | |
| - '**/*.g4' | |
| pull_request: | |
| paths: | |
| - '**/*.g4' | |
| workflow_dispatch: | |
| jobs: | |
| lint-grammars: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - dialect: redshift | |
| path: redshift | |
| steps: | |
| - name: Checkout parser repository | |
| uses: actions/checkout@v4 | |
| with: | |
| path: parser | |
| - name: Checkout antlr-v4-linter repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: bytebase/antlr-v4-linter | |
| path: antlr-v4-linter | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install antlr-v4-linter | |
| run: | | |
| cd antlr-v4-linter | |
| pip install -e . | |
| # Verify installation | |
| which antlr-lint | |
| antlr-lint --version || true | |
| - name: Lint ${{ matrix.dialect }} grammar files | |
| working-directory: parser | |
| run: | | |
| echo "Linting ANTLR grammar files for ${{ matrix.dialect }}" | |
| # Track if any errors occurred | |
| has_errors=false | |
| # Find all .g4 files in the dialect directory | |
| for file in $(find ${{ matrix.path }} -name "*.g4" -type f); do | |
| echo "Checking: $file" | |
| # Run antlr-lint on the grammar file | |
| if antlr-lint lint "$file"; then | |
| echo "✅ $file: Passed linting" | |
| else | |
| echo "❌ $file: Failed linting" | |
| echo "::error file=$file::ANTLR grammar linting failed" | |
| has_errors=true | |
| fi | |
| done | |
| if [ "$has_errors" = true ]; then | |
| echo "❌ Grammar linting failed for ${{ matrix.dialect }}" | |
| exit 1 | |
| else | |
| echo "✅ All grammar files for ${{ matrix.dialect }} passed linting" | |
| fi | |
| - name: Summary | |
| if: always() | |
| working-directory: parser | |
| run: | | |
| echo "## ANTLR Grammar Lint Results" >> $GITHUB_STEP_SUMMARY | |
| echo "Dialect: **${{ matrix.dialect }}**" >> $GITHUB_STEP_SUMMARY | |
| echo "Path: \`${{ matrix.path }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Files checked:" >> $GITHUB_STEP_SUMMARY | |
| find ${{ matrix.path }} -name "*.g4" -type f | while read -r file; do | |
| echo "- \`$file\`" >> $GITHUB_STEP_SUMMARY | |
| done |