Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matt-winkler opened this issue Apr 25, 2023 · 4 comments

Comments

@matt-winkler
Copy link

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
Copy link
Owner

yu-iskw commented May 2, 2023

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
Copy link
Author

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?

@ktopcuoglu
Copy link

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

INPUT_WORKING_DIRECTORY:

INPUT_WORKING_DIRECTORY: ${{ inputs.working-directory }}

my hypothesis is, as we're CWD to INPUT_WORKING_DIRECTORY below, to install dbt deps;

cd "$INPUT_WORKING_DIRECTORY"
dbt deps --profiles-dir "${SCRIPT_DIR}/resources/dummy_profiles"
cd "$default_dir"

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

if [[ "${SQLFLUFF_COMMAND:?}" == "lint" ]]; then
echo '::group:: Running sqlfluff 🐶 ...'
# Allow failures now, as reviewdog handles them
set +Eeuo pipefail
lint_results="sqlfluff-lint.json"
# shellcheck disable=SC2086,SC2046
sqlfluff lint \
--format json \
$(if [[ "x${SQLFLUFF_CONFIG}" != "x" ]]; then echo "--config ${SQLFLUFF_CONFIG}"; fi) \
$(if [[ "x${SQLFLUFF_DIALECT}" != "x" ]]; then echo "--dialect ${SQLFLUFF_DIALECT}"; fi) \
$(if [[ "x${SQLFLUFF_PROCESSES}" != "x" ]]; then echo "--processes ${SQLFLUFF_PROCESSES}"; fi) \
$(if [[ "x${SQLFLUFF_RULES}" != "x" ]]; then echo "--rules ${SQLFLUFF_RULES}"; fi) \
$(if [[ "x${SQLFLUFF_EXCLUDE_RULES}" != "x" ]]; then echo "--exclude-rules ${SQLFLUFF_EXCLUDE_RULES}"; fi) \
$(if [[ "x${SQLFLUFF_TEMPLATER}" != "x" ]]; then echo "--templater ${SQLFLUFF_TEMPLATER}"; fi) \
$(if [[ "x${SQLFLUFF_DISABLE_NOQA}" != "x" ]]; then echo "--disable-noqa ${SQLFLUFF_DISABLE_NOQA}"; fi) \
$(if [[ "x${SQLFLUFF_DIALECT}" != "x" ]]; then echo "--dialect ${SQLFLUFF_DIALECT}"; fi) \
$changed_files |
tee "$lint_results"
sqlfluff_exit_code=$?

could it be the reason?🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants