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

fix(terraform_docs): Fix issue with processing multiply files without terraform-docs markers. Issue introduced in v1.95.0 #720

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

ryan-at-ld
Copy link
Contributor

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.

Description of your changes

A bug in the terraform-docs hook was introduced in #717. In that PR, a continue statement was added that is not preceded by a popd command. The bug is only triggered when the hook is processing multiple files where one (or more) of the files does not contain the terraform-docs marker statements. The hook fails to process the remaining files because the working directory is not reset to the root of the repository. I ran into this bug on version 1.96.0 of the hooks and pre-commit version 3.8.0.

How can we test changes

Here is a script to reproduce the issue. It creates a repository containing multiple modules. The pre-commit run -a command will print an error similar to ~/.cache/pre-commit/reporqzucglw/hooks/terraform_docs.sh: line 178: pushd: modules/c: No such file or directory and module C's README won't be updated by terraform-docs.

cat <<EOF> .pre-commit-config.yaml
---
repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.96.0
    hooks:
      - id: terraform_docs
        files: '.*'
        verbose: true
        types_or:
          - markdown
          - terraform
EOF

git init
pre-commit install --install-hooks
mkdir -p modules/{a,b,c}

cat <<EOF> modules/a/README.md
# I'm module A

<!-- BEGIN_TF_DOCS -->
<!-- END_TF_DOCS -->

EOF

cat <<EOF> modules/b/README.md
# I'm module B

I break things

EOF

cat <<EOF> modules/c/README.md
# I'm module C

<!-- BEGIN_TF_DOCS -->
<!-- END_TF_DOCS -->

EOF

git add .
pre-commit run -a

…1.95.0

A bug in the terraform-docs hook was introduced by the code changes in antonbabenko#717.  [A continue statement was added that is not preceded by a `popd` command](https://github.com/antonbabenko/pre-commit-terraform/blob/869a106a4c8c48f34f58318a830436142e31e10a/hooks/terraform_docs.sh#L216).  The bug is only triggered when the hook is processing multiple files where one (or more) of the files does not contain the terraform-docs marker statements.  The hook fails to process the remaining files because the working directory is not reset to the root of the repository.
@ryan-at-ld ryan-at-ld changed the title fix(terraform_docs) Add missing popd to code that was introduced in v1.95.0 fix (terraform_docs) Add missing popd to code that was introduced in v1.95.0 Sep 16, 2024
@ryan-at-ld ryan-at-ld changed the title fix (terraform_docs) Add missing popd to code that was introduced in v1.95.0 fix: (terraform_docs) Add missing popd to code that was introduced in v1.95.0 Sep 16, 2024
@ryan-at-ld ryan-at-ld changed the title fix: (terraform_docs) Add missing popd to code that was introduced in v1.95.0 fix: Add missing popd to terraform_docs code that was introduced in v1.95.0 Sep 16, 2024
Copy link
Collaborator

@yermulnik yermulnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. Thank you 👍🏻

@yermulnik
Copy link
Collaborator

@MaxymVlasov Would you please add second pair of eyes?

Copy link
Collaborator

@MaxymVlasov MaxymVlasov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@MaxymVlasov MaxymVlasov changed the title fix: Add missing popd to terraform_docs code that was introduced in v1.95.0 fix(terraform_docs): Add missing popd to code that was introduced in v1.95.0 Sep 17, 2024
@MaxymVlasov MaxymVlasov changed the title fix(terraform_docs): Add missing popd to code that was introduced in v1.95.0 fix(terraform_docs): Fix issue with processing multiply files without terraform-docs markers. Issue introduced in v1.95.0 Sep 17, 2024
@MaxymVlasov MaxymVlasov merged commit 2b1aec8 into antonbabenko:master Sep 17, 2024
7 of 10 checks passed
antonbabenko pushed a commit that referenced this pull request Sep 17, 2024
## [1.96.1](v1.96.0...v1.96.1) (2024-09-17)

### Bug Fixes

* **`terraform_docs`:** Fix issue with processing multiply files without `terraform-docs` markers. Issue introduced in v1.95.0 ([#720](#720)) ([2b1aec8](2b1aec8)), closes [#717](#717) [/github.com/antonbabenko/pre-commit-terraform/blob/869a106a4c8c48f34f58318a830436142e31e10a/hooks/terraform_docs.sh#L216](https://github.com//github.com/antonbabenko/pre-commit-terraform/blob/869a106a4c8c48f34f58318a830436142e31e10a/hooks/terraform_docs.sh/issues/L216)
@antonbabenko
Copy link
Owner

This PR is included in version 1.96.1 🎉

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

Successfully merging this pull request may close these issues.

4 participants