Skip to content

Commit

Permalink
Run dbt deps (#23)
Browse files Browse the repository at this point in the history
* Run `dbt deps`

* Update entrypoint.sh

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update entrypoint.sh

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* test

* Update

* test

* Fix

* Fix

* Update README.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
yu-iskw and github-actions[bot] authored May 9, 2022
1 parent fe3c394 commit af063ab
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 40 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Test
on:
pull_request:
paths-ignore:
- "**/*.md"

jobs:
test-lint:
Expand Down Expand Up @@ -28,6 +30,7 @@ jobs:
sqlfluff_version: ${{ matrix.sqlfluff }}
sqlfluff_command: lint
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'
extra_requirements_txt: "${{ github.workspace }}/testdata/test_failed_dbt/extra_requirements.txt"
Expand All @@ -50,7 +53,15 @@ jobs:
strategy:
fail-fast: false
matrix:
sqlfluff: ["0.9.4", "0.10.1", "0.11.1", "0.13.0"]
sqlfluff:
- "0.12.0"
- "0.13.1"
config:
- ".sqlfluff.bigquery"
- ".sqlfluff.postgres"
- ".sqlfluff.redshift"
- ".sqlfluff.snowflake"
- ".sqlfluff.spark"
steps:
- uses: actions/checkout@v2
- uses: ./
Expand All @@ -61,6 +72,7 @@ jobs:
sqlfluff_version: ${{ matrix.sqlfluff }}
sqlfluff_command: fix
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'
extra_requirements_txt: "${{ github.workspace }}/testdata/test_failed_dbt/extra_requirements.txt"
63 changes: 31 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,39 @@ Comments are pointed out by sqlfluff.
The fix mode suggests code formatting based on `sqlfluff fix`.
![github-pr-review demo (fix)](./docs/images/github-pr-review-demo-fix.png)

## NOTE
The `sqlfluff_version` input must be `0.9.0` or later, because `sqlfluff fix` at `0.8.2` or earlier doesn't support the `--config` option.
## Example

```yaml
name: sqlfluff with reviewdog
on:
pull_request:
jobs:
test-check:
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: "0.13.0"
sqlfluff_command: "fix" # Or "lint"
config: "${{ github.workspace }}/.sqlfluff"
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 '.'
```
## NOTE
The tested sqlfluff versions in the repositories are:
- 0.9.4
- 0.10.1
- 0.12.0
- 0.13.1
## Input
Expand Down Expand Up @@ -175,34 +202,6 @@ outputs:
value: ${{ steps.sqlfluff-with-reviewdog-in-composite.outputs.reviewdog-return-code }}
```

## Usage

```yaml
name: sqlfluff with reviewdog
on:
pull_request:
jobs:
test-check:
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: "0.13.0"
sqlfluff_command: "fix" # Or "lint"
config: "${{ github.workspace }}/.sqlfluff"
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 '.'
```

## Development

### Release
Expand Down
18 changes: 13 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ if [[ "${changed_files}" == "" ]]; then
fi
echo '::endgroup::'

# Change the working directory
if [[ "x${INPUT_WORKING_DIRECTORY}" != "x" ]]; then
cd "$INPUT_WORKING_DIRECTORY"
fi

# Install sqlfluff
echo '::group::🐶 Installing sqlfluff ... https://github.com/sqlfluff/sqlfluff'
if [[ "${SQLFLUFF_VERSION:?}" =~ 0\.8.* ]]; then
pip install --no-cache-dir -r "${SCRIPT_DIR}/requirements/requirements.sqlfluff-0.8.txt"
else
pip install --no-cache-dir -r "${SCRIPT_DIR}/requirements/requirements.txt"
fi
pip install --no-cache-dir -r "${SCRIPT_DIR}/requirements/requirements.txt"
# Make sure the version of sqlfluff
sqlfluff --version
echo '::endgroup::'
Expand All @@ -47,6 +48,13 @@ if [[ "x${EXTRA_REQUIREMENTS_TXT}" != "x" ]]; then
fi
echo '::endgroup::'

# Install dbt packages
echo '::group:: Installing dbt packages'
if [[ -f "${INPUT_WORKING_DIRECTORY}/packages.yml" ]]; then
dbt deps --profiles-dir "${SCRIPT_DIR}/resources/dummy_profiles"
fi
echo '::endgroup::'

# Lint changed files if the mode is lint
if [[ "${SQLFLUFF_COMMAND:?}" == "lint" ]]; then
echo '::group:: Running sqlfluff 🐶 ...'
Expand Down
2 changes: 1 addition & 1 deletion testdata/test_failed_dbt/models/staging/staging_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

SELECT
1 AS x,
2 AS y,
2 AS y,
3 AS z
2 changes: 1 addition & 1 deletion testdata/test_failed_dbt/models/staging/staging_test02.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


SELECT
1 AS x,
1 AS x,
2 AS y,
3 AS z
3 changes: 3 additions & 0 deletions testdata/test_failed_dbt/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- package: dbt-labs/dbt_utils
version: 0.8.0

0 comments on commit af063ab

Please sign in to comment.