action-sqlfluff icon indicating copy to clipboard operation
action-sqlfluff copied to clipboard

Alternate working directory configuration not respected (dbt_project.yml)

Open matt-winkler opened this issue 2 years ago • 4 comments

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.

matt-winkler avatar Apr 25 '23 16:04 matt-winkler

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

yu-iskw avatar May 02 '23 13:05 yu-iskw

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?

matt-winkler avatar May 02 '23 20:05 matt-winkler

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

yu-iskw avatar May 04 '23 01:05 yu-iskw

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?🤔

ktopcuoglu avatar May 10 '23 22:05 ktopcuoglu