diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ad9381..e302dbb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,7 @@ jobs: templater: jinja working-directory: "${{ github.workspace }}/testdata/test_failed_dbt" config: "${{ github.workspace }}/testdata/test_failed_dbt/${{ matrix.config }}" - paths: '${{ github.workspace }}/testdata/test_failed_dbt/models' + paths: "${{ github.workspace }}/testdata/test_failed_dbt/models" extra_requirements_txt: "${{ github.workspace }}/${{ matrix.extra_requirements_txt }}" - name: check the exit code if: ${{ !success() }} @@ -58,10 +58,11 @@ jobs: matrix: sqlfluff: - "2.3.0" + - "3.0.7" extra_requirements_txt: - - "testdata/test_failed_dbt/extra_requirements-1.3.txt" - - "testdata/test_failed_dbt/extra_requirements-1.4.txt" - - "testdata/test_failed_dbt/extra_requirements-1.5.txt" + - "testdata/test_failed_dbt/extra_requirements-1.6.txt" + - "testdata/test_failed_dbt/extra_requirements-1.7.txt" + - "testdata/test_failed_dbt/extra_requirements-1.8.txt" config: - ".sqlfluff.bigquery" - ".sqlfluff.postgres" @@ -69,7 +70,7 @@ jobs: - ".sqlfluff.snowflake" - ".sqlfluff.spark" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: ./ id: lint-sql with: @@ -80,5 +81,5 @@ jobs: templater: jinja working-directory: "${{ github.workspace }}/testdata/test_failed_dbt" config: "${{ github.workspace }}/testdata/test_failed_dbt/${{ matrix.config }}" - paths: '${{ github.workspace }}/testdata/test_failed_dbt/models' + paths: "${{ github.workspace }}/testdata/test_failed_dbt/models" extra_requirements_txt: "${{ github.workspace }}/${{ matrix.extra_requirements_txt }}" diff --git a/Dockerfile b/Dockerfile index 990b88e..b977294 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM python:3.10-slim +FROM python:3.12-slim -ENV REVIEWDOG_VERSION="v0.14.1" +ENV REVIEWDOG_VERSION="v0.17.4" ENV WORKING_DIRECTORY="/workdir" WORKDIR "$WORKING_DIRECTORY" diff --git a/README.md b/README.md index 7d27369..2543919 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # action-sqlfluff + [![Test](https://github.com/yu-iskw/action-sqlfluff/workflows/Test/badge.svg)](https://github.com/yu-iskw/action-sqlfluff/actions?query=workflow%3ATest) [![reviewdog](https://github.com/yu-iskw/action-sqlfluff/workflows/reviewdog/badge.svg)](https://github.com/yu-iskw/action-sqlfluff/actions?query=workflow%3Areviewdog) [![depup](https://github.com/yu-iskw/action-sqlfluff/workflows/depup/badge.svg)](https://github.com/yu-iskw/action-sqlfluff/actions?query=workflow%3Adepup) @@ -8,18 +9,19 @@ [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/yu-iskw/action-sqlfluff?logo=github&sort=semver)](https://github.com/yu-iskw/action-sqlfluff/releases) [![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) - This is a github action to lint and fix SQL with [sqlfluff](https://github.com/sqlfluff/sqlfluff). The action has the two modes corresponding to `sqlfluff lint` and `sqlfluff fix`. One is to automatically leaves comments about SQL violation using [reviewdog](https://github.com/reviewdog/reviewdog) The other is to automatically suggests code formatting on github pull request with reviewdog too. ## Lint mode + The lint mode leaves comments on github pull requests. Comments are pointed out by sqlfluff. ![github-pr-review demo (lint)](./docs/images/github-pr-review-demo-lint.png) ## Fix mode + The fix mode suggests code formatting based on `sqlfluff fix`. ![github-pr-review demo (fix)](./docs/images/github-pr-review-demo-fix.png) @@ -40,80 +42,81 @@ jobs: with: github_token: ${{ secrets.github_token }} reporter: github-pr-review - sqlfluff_version: "2.0.7" + sqlfluff_version: "3.0.7" sqlfluff_command: "fix" # Or "lint" config: "${{ github.workspace }}/.sqlfluff" - paths: '${{ github.workspace }}/models' - - name: 'Show outputs (Optional)' + paths: "${{ github.workspace }}/models" + - 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 '.' ``` -## Supported versions of sqlfluff -We tested the action with the following versions of sqlfluff. -We don't recommend to use the sqlfluff version less than 1.4.5, because those don't support dbt-core 1.4 or later. - -- 2.0.7 - - ## Input ```yaml inputs: github_token: - description: 'GITHUB_TOKEN' + description: "GITHUB_TOKEN" required: true - default: '${{ github.token }}' + default: "${{ github.token }}" + github_base_ref: + description: "Pull request target branch name" + required: false + default: "${{ github.base_ref }}" working-directory: - description: 'working directory' + description: "working directory" required: false - default: '${{ github.workspace }}' + default: "${{ github.workspace }}" ### Flags for reviewdog ### level: - description: 'Report level for reviewdog [info,warning,error]' + description: "Report level for reviewdog [info,warning,error]" required: false - default: 'error' + default: "error" reporter: - description: 'Reporter of reviewdog command [github-check,github-pr-review].' + description: "Reporter of reviewdog command [github-check,github-pr-review]." required: false - default: 'github-check' + default: "github-check" filter_mode: description: | Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. Default is file. required: false - default: 'file' + default: "file" fail_on_error: description: | Exit code for reviewdog when errors are found [true,false] Default is `false`. required: false - default: 'false' + default: "false" reviewdog_version: - description: 'reviewdog version' + description: "reviewdog version" required: false - default: '0.14.1' + default: "v0.17.4" ### Flags for sqlfluff ### sqlfluff_version: description: | sqlfluff version. Use the latest version if not set. required: false - default: '2.0.7' + default: "3.0.7" sqlfluff_command: - description: 'The sub command of sqlfluff. One of lint and fix' + description: "The sub command of sqlfluff. One of lint and fix" required: false - default: 'lint' + default: "lint" paths: description: | PATH is the path to a sql file or directory to lint. This can be either a file ('path/to/file.sql'), a path ('directory/of/sql/files'), a single ('-') character to indicate reading from *stdin* or a dot/blank ('.'/' ') which will be interpreted like passing the current working directory as a path argument. required: true + file_pattern: + description: "The regular expression to filter checked files" + required: false + default: '\.sql$' encoding: - description: 'Specifiy encoding to use when reading and writing files. Defaults to autodetect.' + description: "Specifiy encoding to use when reading and writing files. Defaults to autodetect." required: false - default: '' + default: "" config: description: | Include additional config file. @@ -121,7 +124,7 @@ inputs: This argument allows you to specify an additional configuration file that overrides the standard configuration files. N.B. cfg format is required. required: false - default: '' + default: "" exclude-rules: description: | Exclude specific rules. @@ -129,76 +132,55 @@ inputs: This could either be the allowlist, or the general set if there is no specific allowlist. Multiple rules can be specified with commas e.g. –exclude-rules L001,L002 will exclude violations of rule L001 and rule L002. required: false - default: '' + default: "" rules: description: | Narrow the search to only specific rules. For example specifying –rules L001 will only search for rule L001 (Unnecessary trailing whitespace). Multiple rules can be specified with commas e.g. –rules L001,L002 will specify only looking for violations of rule L001 and rule L002. required: false - default: '' + default: "" templater: - description: 'The templater to use' + description: "The templater to use" required: false - default: '' + default: "" disable-noqa: - description: 'Set this flag to ignore inline noqa comments.' + description: "Set this flag to ignore inline noqa comments." required: false - default: '' + default: "" dialect: - description: 'The dialect of SQL to lint' + description: "The dialect of SQL to lint" required: false - default: '' - # annotation-level: - # description: | - # When format is set to github-annotation, default annotation level. - # Options - # notice | warning | failure - # required: false - # default: '' - # nofail: - # description: | - # If set, the exit code will always be zero, regardless of violations found. - # This is potentially useful during rollout. - # required: false - # default: '' - # disregard-sqlfluffignores: - # description: 'Perform the operation regardless of .sqlfluffignore configurations' - # required: false - # default: '' + default: "" processes: - description: 'The number of parallel processes to run.' + description: "The number of parallel processes to run." required: false default: "2" - # Mainly used to install dbt adapters - # NOTE: - # sqlfluff tries to dynamically import a dbt adapter based on a configuration. - # There is no great way to dynamically install required dbt adapters to fit to users of action. - # It might be possible to support only dbt adapters craeted by dbt labo. - # But, as that doesn't support 3rd party dbt adapters, we have no choise but for users to pass their custom extra requirements.txt. extra_requirements_txt: description: | A path to your custom `requirements.txt` to install extra modules for your dbt adapters. Please make sure not to contain `sqlfluff` and its dependent packages, because the action can be broken by the conflicts. required: false - default: '' + default: "" ``` ## Outputs + The outputs are available only when the `sqlfluff_command` input is `lint`. + ```yaml outputs: sqlfluff-results: - description: 'The JSON object string of sqlfluff results' + description: "The JSON object string of sqlfluff results" value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.sqlfluff-results }} sqlfluff-exit-code: - description: 'The exit code of sqlfluff' + description: "The exit code of sqlfluff" value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.sqlfluff-exit-code }} sqlfluff-results-rdjson: - description: 'The JSON object string of sqlfluff results' + description: "The JSON object string of sqlfluff results" value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.sqlfluff-results-rdjson }} reviewdog-return-code: - description: 'The exit code of reviewdog' + description: "The exit code of reviewdog" value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.reviewdog-return-code }} ``` @@ -207,13 +189,14 @@ outputs: ### Release #### [haya14busa/action-bumpr](https://github.com/haya14busa/action-bumpr) + You can bump version on merging Pull Requests with specific labels (bump:major,bump:minor,bump:patch). Pushing tag manually by yourself also work. #### [haya14busa/action-update-semver](https://github.com/haya14busa/action-update-semver) This action updates major/minor release tags on a tag push. e.g. Update v1 and v1.2 tag when released v1.2.3. -ref: https://help.github.com/en/articles/about-actions#versioning-your-action +ref: ### Lint - reviewdog integration @@ -229,12 +212,14 @@ Supported linters: - [reviewdog/action-misspell](https://github.com/reviewdog/action-misspell) ### Dependencies Update Automation + This repository uses [reviewdog/action-depup](https://github.com/reviewdog/action-depup) to update reviewdog version. ![reviewdog depup demo](https://user-images.githubusercontent.com/3797062/73154254-170e7500-411a-11ea-8211-912e9de7c936.png) ## Contributors + diff --git a/action.yml b/action.yml index 6d5a7c1..a8df245 100644 --- a/action.yml +++ b/action.yml @@ -1,54 +1,54 @@ -name: 'Run sqlfluff with reviewdog' -description: '🐶 Run sqlfluff with reviewdog on pull requests to improve code review experience.' -author: 'yu-iskw' +name: "Run sqlfluff with reviewdog" +description: "🐶 Run sqlfluff with reviewdog on pull requests to improve code review experience." +author: "yu-iskw" inputs: github_token: - description: 'GITHUB_TOKEN' + description: "GITHUB_TOKEN" required: true - default: '${{ github.token }}' + default: "${{ github.token }}" github_base_ref: description: "Pull request target branch name" required: false default: "${{ github.base_ref }}" working-directory: - description: 'working directory' + description: "working directory" required: false - default: '${{ github.workspace }}' + default: "${{ github.workspace }}" ### Flags for reviewdog ### level: - description: 'Report level for reviewdog [info,warning,error]' + description: "Report level for reviewdog [info,warning,error]" required: false - default: 'error' + default: "error" reporter: - description: 'Reporter of reviewdog command [github-check,github-pr-review].' + description: "Reporter of reviewdog command [github-check,github-pr-review]." required: false - default: 'github-check' + default: "github-check" filter_mode: description: | Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. Default is file. required: false - default: 'file' + default: "file" fail_on_error: description: | Exit code for reviewdog when errors are found [true,false] Default is `false`. required: false - default: 'false' + default: "false" reviewdog_version: - description: 'reviewdog version' + description: "reviewdog version" required: false - default: 'v0.14.0' + default: "v0.17.4" ### Flags for sqlfluff ### sqlfluff_version: description: | sqlfluff version. Use the latest version if not set. required: false - default: '2.3.0' + default: "3.0.7" sqlfluff_command: - description: 'The sub command of sqlfluff. One of lint and fix' + description: "The sub command of sqlfluff. One of lint and fix" required: false - default: 'lint' + default: "lint" paths: description: | PATH is the path to a sql file or directory to lint. @@ -59,9 +59,9 @@ inputs: required: false default: '\.sql$' encoding: - description: 'Specifiy encoding to use when reading and writing files. Defaults to autodetect.' + description: "Specifiy encoding to use when reading and writing files. Defaults to autodetect." required: false - default: '' + default: "" config: description: | Include additional config file. @@ -69,7 +69,7 @@ inputs: This argument allows you to specify an additional configuration file that overrides the standard configuration files. N.B. cfg format is required. required: false - default: '' + default: "" exclude-rules: description: | Exclude specific rules. @@ -77,45 +77,45 @@ inputs: This could either be the allowlist, or the general set if there is no specific allowlist. Multiple rules can be specified with commas e.g. –exclude-rules L001,L002 will exclude violations of rule L001 and rule L002. required: false - default: '' + default: "" rules: description: | Narrow the search to only specific rules. For example specifying –rules L001 will only search for rule L001 (Unnecessary trailing whitespace). Multiple rules can be specified with commas e.g. –rules L001,L002 will specify only looking for violations of rule L001 and rule L002. required: false - default: '' + default: "" templater: - description: 'The templater to use' + description: "The templater to use" required: false - default: '' + default: "" disable-noqa: - description: 'Set this flag to ignore inline noqa comments.' + description: "Set this flag to ignore inline noqa comments." required: false - default: '' + default: "" dialect: - description: 'The dialect of SQL to lint' - required: false - default: '' -# annotation-level: -# description: | -# When format is set to github-annotation, default annotation level. -# Options -# notice | warning | failure -# required: false -# default: '' -# nofail: -# description: | -# If set, the exit code will always be zero, regardless of violations found. -# This is potentially useful during rollout. -# required: false -# default: '' -# disregard-sqlfluffignores: -# description: 'Perform the operation regardless of .sqlfluffignore configurations' -# required: false -# default: '' + description: "The dialect of SQL to lint" + required: false + default: "" + # annotation-level: + # description: | + # When format is set to github-annotation, default annotation level. + # Options + # notice | warning | failure + # required: false + # default: '' + # nofail: + # description: | + # If set, the exit code will always be zero, regardless of violations found. + # This is potentially useful during rollout. + # required: false + # default: '' + # disregard-sqlfluffignores: + # description: 'Perform the operation regardless of .sqlfluffignore configurations' + # required: false + # default: '' processes: - description: 'The number of parallel processes to run.' + description: "The number of parallel processes to run." required: false default: "2" # Mainly used to install dbt adapters @@ -129,25 +129,25 @@ inputs: A path to your custom `requirements.txt` to install extra modules for your dbt adapters. Please make sure not to contain `sqlfluff` and its dependent packages, because the action can be broken by the conflicts. required: false - default: '' + default: "" outputs: sqlfluff-results: - description: 'The JSON object string of sqlfluff results' + description: "The JSON object string of sqlfluff results" value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.sqlfluff-results }} sqlfluff-exit-code: - description: 'The exit code of sqlfluff' + description: "The exit code of sqlfluff" value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.sqlfluff-exit-code }} sqlfluff-results-rdjson: - description: 'The JSON object string of sqlfluff results' + description: "The JSON object string of sqlfluff results" value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.sqlfluff-results-rdjson }} reviewdog-exit-code: - description: 'The exit code of reviewdog' + description: "The exit code of reviewdog" value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.reviewdog-return-code }} runs: - using: 'docker' - image: 'Dockerfile' + using: "docker" + image: "Dockerfile" env: # INPUT_ is not available in Composite run steps # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 @@ -176,5 +176,5 @@ runs: # Ref: https://haya14busa.github.io/github-action-brandings/ branding: - icon: 'check' - color: 'blue' + icon: "check" + color: "blue" diff --git a/testdata/test_failed_dbt/extra_requirements-1.3.txt b/testdata/test_failed_dbt/extra_requirements-1.3.txt deleted file mode 100644 index 1a07f1f..0000000 --- a/testdata/test_failed_dbt/extra_requirements-1.3.txt +++ /dev/null @@ -1,6 +0,0 @@ -dbt-core>=1.3,<1.4 -dbt-postgres>=1.3,<1.4 -dbt-bigquery>=1.3,<1.4 -dbt-redshift>=1.3,<1.4 -dbt-snowflake>=1.3,<1.4 -dbt-spark[pyHive]>=1.3,<1.4 diff --git a/testdata/test_failed_dbt/extra_requirements-1.4.txt b/testdata/test_failed_dbt/extra_requirements-1.4.txt deleted file mode 100644 index 6d8b296..0000000 --- a/testdata/test_failed_dbt/extra_requirements-1.4.txt +++ /dev/null @@ -1,6 +0,0 @@ -dbt-core>=1.4,<1.5 -dbt-postgres>=1.4,<1.5 -dbt-bigquery>=1.4,<1.5 -dbt-redshift>=1.4,<1.5 -dbt-snowflake>=1.4,<1.5 -dbt-spark[pyHive]>=1.4,<1.5 diff --git a/testdata/test_failed_dbt/extra_requirements-1.5.txt b/testdata/test_failed_dbt/extra_requirements-1.6.txt similarity index 100% rename from testdata/test_failed_dbt/extra_requirements-1.5.txt rename to testdata/test_failed_dbt/extra_requirements-1.6.txt diff --git a/testdata/test_failed_dbt/extra_requirements-1.7.txt b/testdata/test_failed_dbt/extra_requirements-1.7.txt new file mode 100644 index 0000000..0f8d312 --- /dev/null +++ b/testdata/test_failed_dbt/extra_requirements-1.7.txt @@ -0,0 +1,6 @@ +dbt-core>=1.5,<1.6 +dbt-postgres>=1.5,<1.6 +dbt-bigquery>=1.5,<1.6 +dbt-redshift>=1.5,<1.6 +dbt-snowflake>=1.5,<1.6 +dbt-spark[pyHive]>=1.5,<1.6 diff --git a/testdata/test_failed_dbt/extra_requirements-1.8.txt b/testdata/test_failed_dbt/extra_requirements-1.8.txt new file mode 100644 index 0000000..0f8d312 --- /dev/null +++ b/testdata/test_failed_dbt/extra_requirements-1.8.txt @@ -0,0 +1,6 @@ +dbt-core>=1.5,<1.6 +dbt-postgres>=1.5,<1.6 +dbt-bigquery>=1.5,<1.6 +dbt-redshift>=1.5,<1.6 +dbt-snowflake>=1.5,<1.6 +dbt-spark[pyHive]>=1.5,<1.6