Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Wrong exit code for pre-commit hooks #795

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

Open
LukaK opened this issue Aug 21, 2024 · 0 comments
Open

Wrong exit code for pre-commit hooks #795

LukaK opened this issue Aug 21, 2024 · 0 comments
Labels

Comments

@LukaK
Copy link

LukaK commented Aug 21, 2024

Describe the bug

Hi this issue is related to already reported issue link but I would suggest failing the hook instead of auto adding the changes similar to tools like black.

When you run pre-commit run --all-files or change moduel files, hook passes even if it updates the documentation leading to incomplete commits and hacks like the one below. Disabling fail_fast and adding additional step to check the documentation before updating it.

default_stages:
  - pre-commit
  - pre-push

fail_fast: false

repos:

  - repo: https://github.com/terraform-docs/terraform-docs
    rev: "v0.18.0"
    hooks:

      - id: terraform-docs-go
        name: terraform-docs-check
        args: ["--recursive", "--recursive-path", "modules", "--recursive-include-main=false", "--output-file", "README.md", "markdown", "--output-check",  "./infrastructure"]

      - id: terraform-docs-go
        name: terraform-docs-generate
        args: ["--recursive", "--recursive-path", "modules", "--recursive-include-main=false", "--output-file", "README.md", "markdown",  "./infrastructure"]

How can we reproduce it?

Create directory structure.

infrastructure/modules/test-module/main.tf

main.tf

terraform {
  required_version = ">= 1.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.62.0"
    }
  }
}

variable "env" {
  type        = string
  description = "Environment values"
}

resource "aws_s3_bucket" "this" {
  tags = {
    Name        = "${var.env}-mybucket"
    Environment = var.env
  }
}

resource "aws_s3_bucket_public_access_block" "this" {
  bucket = aws_s3_bucket.this.id

  block_public_acls       = true
  ignore_public_acls      = true
  restrict_public_buckets = true
  block_public_policy     = true

}

resource "aws_s3_bucket_server_side_encryption_configuration" "this2" {
  bucket = aws_s3_bucket.this.id

  rule {
    apply_server_side_encryption_by_default {
      sse_algorithm = "AES256"
    }
  }
}


output "bucket_name2" {
  value       = aws_s3_bucket.this.id
  description = "Bucket name"
}

.pre-commit-config.yaml

default_stages:
  - pre-commit
  - pre-push

fail_fast: false

repos:

  - repo: https://github.com/terraform-docs/terraform-docs
    rev: "v0.18.0"
    hooks:

      # - id: terraform-docs-go
      #   name: terraform-docs-check
      #   args: ["--recursive", "--recursive-path", "modules", "--recursive-include-main=false", "--output-file", "README.md", "markdown", "--output-check",  "./infrastructure"]

      - id: terraform-docs-go
        name: terraform-docs-generate
        args: ["--recursive", "--recursive-path", "modules", "--recursive-include-main=false", "--output-file", "README.md", "markdown",  "./infrastructure"]

Environment information

@LukaK LukaK added the bug label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant