1

I am trying to set sqlfluff linting for dbt files by following the example on this example with some slight changes. My github actions yml file looks like:

name: Run sqlfluff linter

on:
  push:
      branches:
        - main
        - sqlfluff_ga2
  
jobs:
  sql-lint:
    name: runner / sqlfluff (github-check)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: yu-iskw/action-sqlfluff@v3
        id: lint-sql
        with:
          github_token: ${{ secrets.github_token }}
          reporter: github-pr-review
          sqlfluff_version: "1.2.0"
          sqlfluff_command: "lint" # Or "fix"
          config: "${{ github.workspace }}/.sqlfluff"
          paths: '${{ github.workspace }}/models'
          github_base_ref: "main"
      - name: 'Show outputs (Optional)'
        shell: bash
        run: |
          echo '${{ steps.lint-sql.outputs.sqlfluff-results }}' | jq -r '.'
          echo '${{ steps.lint-sql.outputs.sqlfluff-results-rdjson }}' | jq -r '.'

and here is my .sqlfluff rules:

[sqlfluff]
dialect = bigquery

# L031 - Exclude rule requiring fully-qualified table names in joins
# should have been disabled for BigQuery already
# L036 - multiple SELECT columns can appear on the SELECT line
# L051 - Exclude rule requiring INNER JOIN rather than just JOIN
# L003 - Ignore whitespace problems for now
# L034 - Don't move around columns
# L016 - Long lines are fine
# L009 - No need for a single newline at end of file
# L008 - No need for spaces around commas
exclude_rules = L051,L031,L036,L003,L034,L016,L009,L008

[sqlfluff:rules:L010]
# Keywords
capitalisation_policy = upper

and finally here is a test sql file content which resides in models folder of the dbt file structure:

select
  t.table_catalog t_catalog,
  t.table_schema t_schema,
  t.table_name t_name,
  t.table_type t_type,
  c.column_name c_name,
  c.data_type d_type
FROM "{{ database }}".information_schema.tables t
inner JOIN "{{ database }}".information_schema.columns c
  on c.table_schema = t.table_schema
  and c.table_name = t.table_name
where t.table_catalog =  '{{ database.upper() }}' 
  and t.table_type in ('BASE TABLE', 'VIEW') and t.table_schema = '{{ schema.upper() }}' and t.table_name = '{{ alias.upper() }}' 
ORDER BY t.table_schema,
 t.table_name;

The github action run is successful, however, the sql file linting is not fixed. No capitalization or addition of ASalias took place. Here is the output I am seeing: outputfile

I was wondering if someone can help me understand what is going on.

G1124E
  • 407
  • 1
  • 10
  • 20

1 Answers1

0

I'm guessing you didn't push any changes in the test sql file together. yu-iskw/action-sqlfluff does test changed/added files only as https://github.com/yu-iskw/action-sqlfluff/blob/main/entrypoint.sh#L16

Yoichi Nakayama
  • 704
  • 6
  • 9