From fa3a0df5eda7baef8e668774259cd7ee6ca0dbaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garrido=20S=C3=A1nchez?= Date: Sun, 21 Jan 2024 18:36:05 +0100 Subject: [PATCH] pre-commit (#3) --- .github/workflows/pre-commit.yml | 36 ++++++++++++++++++++++++++++ .pre-commit-config.yaml | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..7a3e132 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,36 @@ +name: "pre-commit" + +on: + pull_request: + branches: + - main + +permissions: + id-token: write + contents: read + +jobs: + main: + runs-on: ubuntu-latest + + steps: + - name: Download repository + uses: actions/checkout@v4 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: "1.3.0" + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + + - name: Setup Homebrew + uses: Homebrew/actions/setup-homebrew@master + + - name: Install dependencies + run: brew install tflint terraform-docs + + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4ff97ed --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,40 @@ +repos: + - repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.86.0 + hooks: + - id: terraform_fmt + name: Format Terraform code + + - id: terraform_validate + name: Validate Terraform code + exclude: ^(examples|tests) + args: + - --tf-init-args=-upgrade + - --tf-init-args=-backend=false + - --hook-config=--retry-once-with-cleanup=true + + - id: terraform_tflint + name: Validate Terraform tests + exclude: ^(examples|tests) + args: + - --args=--enable-rule=terraform_naming_convention + - --args=--enable-rule=terraform_unused_required_providers + - --args=--module + + - id: terraform_docs + name: Generate Terraform documentation + + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.38.0 + hooks: + - id: markdownlint + name: Validate Markdown text + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-merge-conflict + name: Check for files that contain merge conflict strings + + - id: end-of-file-fixer + name: Makes sure files end in a newline and only a newline