yu-iskw / action-sqlfluff

Run sqlfluff with reviewdog to check or format styles
https://github.com/marketplace/actions/run-sqlfluff-with-reviewdog
MIT License
68 stars 27 forks source link

Alternate working directory configuration not respected (dbt_project.yml) #82

Open matt-winkler opened 1 year ago

matt-winkler commented 1 year ago

Is it possible to use this action template on dbt when the dbt_project.yml file lives somewhere other than the root of the repository? If so, how to configure it? The below describes what I have attempted.

In a git action template, I am setting the working-directory for yu-iskw/action-sqlfluff@v3 as follows:

working-directory: ${{ github.workspace }}/dbt_transform_code

In the SQL Fluff configuration file, I've also experimented with setting the project_dir to '/home/runner/work/<repo-name>/<repo-name>/dbt_transform_code'

In either case, I see the following error from the git action run:

    File "/usr/local/bin/sqlfluff", line 8, in <module>
      sys.exit(cli())
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
      return self.main(*args, **kwargs)
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
      rv = self.invoke(ctx)
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
      return __callback(*args, **kwargs)
    File "/usr/local/lib/python3.9/site-packages/sqlfluff/cli/commands.py", line 830, in fix
      result = lnt.lint_paths(
    File "/usr/local/lib/python3.9/site-packages/sqlfluff/core/linter/linter.py", line 1164, in lint_paths
      for i, linted_file in enumerate(runner.run(expanded_paths, fix), start=1):
    File "/usr/local/lib/python3.9/site-packages/sqlfluff/core/linter/runner.py", line 142, in run
      for lint_result in self._map(
    File "/usr/local/lib/python3.9/multiprocessing/pool.py", line 870, in next
      raise value
  dbt.exceptions.DbtProjectError: Runtime Error
    no dbt_project.yml found at expected path /github/workspace/dbt_project.yml

Which appears to be telling me the process is looking for the dbt_project.yml file to exist at the root of the repository.

yu-iskw commented 1 year ago

Is your dbt_project.yml located in somewhere other than the dbt project directory?

I test the actions with the workflow below. The working-directory input definitely works in my case. https://github.com/yu-iskw/action-sqlfluff/blob/main/.github/workflows/test.yml#L36

matt-winkler commented 1 year ago

Thanks for the response @yu-iskw . Yes, the dbt_project.yml is located in a directory called dbt_transform within the repo rather than at the root. Are you saying that the action template linked above works in this case, and can you please provide the name of the directory where the dbt_project.yml file lives?

yu-iskw commented 1 year ago

https://github.com/yu-iskw/action-sqlfluff/blob/main/testdata/test_failed_dbt/dbt_project.yml

ktopcuoglu commented 1 year ago

hey @yu-iskw , do you have a chance to test the same scenario with the dbt templater, instead of jinja?

INPUT_WORKING_DIRECTORY: https://github.com/yu-iskw/action-sqlfluff/blob/2b313f10cc5db392bed833c57b7bac89775b2597/action.yml#L155

my hypothesis is, as we're CWD to INPUT_WORKING_DIRECTORY below, to install dbt deps; https://github.com/yu-iskw/action-sqlfluff/blob/2b313f10cc5db392bed833c57b7bac89775b2597/entrypoint.sh#L55-L57

For the same reason, we may need to CWD to INPUT_WORKING_DIRECTORY before calling sqlfluff as well.

https://github.com/yu-iskw/action-sqlfluff/blob/2b313f10cc5db392bed833c57b7bac89775b2597/entrypoint.sh#L62-L80

could it be the reason?🤔