From 969cf3d0f03a1acfac959bb16b837a6938cb28ab Mon Sep 17 00:00:00 2001 From: Nathan Parraga Thiesen Date: Mon, 28 Mar 2022 16:39:49 +0200 Subject: [PATCH 1/3] feat: add terradoc --- .pre-commit-hooks.yaml | 21 +++++++++++++++++++++ pre_commit_hooks/terradoc/fmt.sh | 5 +++++ pre_commit_hooks/terradoc/generate.sh | 5 +++++ 3 files changed, 31 insertions(+) create mode 100755 pre_commit_hooks/terradoc/fmt.sh create mode 100755 pre_commit_hooks/terradoc/generate.sh diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index f7206fe..b330a29 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -115,3 +115,24 @@ .+\.vendor\/.*$| .+\.terraform\/.*$| )$ + +# --------------------------------------------------------------------------------------------------------------------- +# Terradoc specific hooks +# --------------------------------------------------------------------------------------------------------------------- + +- id: terradoc-fmt + name: Terradoc fmt + description: The terradoc fmt command is used to rewrite Terradoc input files to a canonical format and style. This command applies a subset of the Terraform language style conventions, along with other minor adjustments for readability similarly to the corresponding terraform hook. + entry: pre_commit_hooks/terradoc/fmt.sh + language: script + args: + - README.tfdoc.hcl + +- id: terradoc-generate + name: Terradoc generate + description: The terradoc generate command is used to generate documentation files from a Terradoc input file. + entry: pre_commit_hooks/terradoc/generate.sh + language: script + args: + - README.tfdoc.hcl + - README.md diff --git a/pre_commit_hooks/terradoc/fmt.sh b/pre_commit_hooks/terradoc/fmt.sh new file mode 100755 index 0000000..b47e5ad --- /dev/null +++ b/pre_commit_hooks/terradoc/fmt.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +terradoc fmt $1 -w diff --git a/pre_commit_hooks/terradoc/generate.sh b/pre_commit_hooks/terradoc/generate.sh new file mode 100755 index 0000000..5d35a13 --- /dev/null +++ b/pre_commit_hooks/terradoc/generate.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +terradoc generate $1 -o $2 From 4c921a5dfa06136e80640aeaac1eb666324d2b81 Mon Sep 17 00:00:00 2001 From: Nathan Parraga Thiesen Date: Wed, 30 Mar 2022 08:34:11 +0200 Subject: [PATCH 2/3] doc: update readme --- README.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7149914..37080e4 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,9 @@ Currently, the following hooks are supported: It's fast: on average 5 times faster than gometalinter. It's easy to integrate and use, has nice output and has a minimum number of false positives. An example configuration can be found in [.golangci.example.yml](https://github.com/mineiros-io/pre-commit-hooks/blob/master/.golangci.example.yml). - + #### The following hooks can be configured through golangci-lint and are therefore redundant when golangci-lint is being used - + - [gofmt](https://golang.org/cmd/gofmt/): Go fmt is a tool that automatically formats Go `*.go` files to canonical format and style. - [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports): The goimports command updates import lines in Go @@ -74,6 +74,13 @@ Currently, the following hooks are supported: - [shellcheck](https://github.com/koalaman/shellcheck): ShellCheck is a GPLv3 tool that gives warnings and suggestions for bash/sh shell scripts. +### Terradoc + +- terradoc-fmt: The terradoc fmt command is used to rewrite + Terradoc configuration `*tfdoc.hcl` files to a canonical format and style. +- terradoc-generate: The terradoc generates a documentation file from + Terradoc configuration `*tfdoc.hcl` files + ## Installation & Dependencies 1. Install [pre-commit](https://pre-commit.com/). E.g. `brew install pre-commit` @@ -87,7 +94,8 @@ Currently, the following hooks are supported: go \ golangci/tap/golangci-lint \ shellcheck && \ - npm install -g markdown-link-check + npm install -g markdown-link-check && \ + go install github.com/mineiros-io/terradoc/cmd/terradoc@latest ``` ## Usage @@ -108,6 +116,8 @@ repos: - id: markdown-link-check args: [-p] # When adding the -p flag, markdown-link-check will always with an exit code 0, even if dead links are found - id: shellcheck + - id: terradoc-fmt + - id: terradoc-generate # The following hooks are redundant when golangci-lint is being. Our recommendation is to use golangci-lint # as the main linter for go since it enables you to run all available linters in parallel. From 03b12e8213ed2d5455f2d606426d59f9bc67331a Mon Sep 17 00:00:00 2001 From: Nathan Parraga Thiesen Date: Thu, 31 Mar 2022 15:56:05 +0200 Subject: [PATCH 3/3] feat: ensure `terradoc` is installed before running cmds --- pre_commit_hooks/terradoc/fmt.sh | 6 ++++++ pre_commit_hooks/terradoc/generate.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/pre_commit_hooks/terradoc/fmt.sh b/pre_commit_hooks/terradoc/fmt.sh index b47e5ad..1a3d152 100755 --- a/pre_commit_hooks/terradoc/fmt.sh +++ b/pre_commit_hooks/terradoc/fmt.sh @@ -2,4 +2,10 @@ set -e +if ! command -v terradoc >/dev/null 2>&1; then + echo >&2 "terradoc is not available on this system." + echo >&2 "Please install it by running 'go install github.com/mineiros-io/terradoc/cmd/terradoc@latest'" + exit 1 +fi + terradoc fmt $1 -w diff --git a/pre_commit_hooks/terradoc/generate.sh b/pre_commit_hooks/terradoc/generate.sh index 5d35a13..bc036dd 100755 --- a/pre_commit_hooks/terradoc/generate.sh +++ b/pre_commit_hooks/terradoc/generate.sh @@ -2,4 +2,10 @@ set -e +if ! command -v terradoc >/dev/null 2>&1; then + echo >&2 "terradoc is not available on this system." + echo >&2 "Please install it by running 'go install github.com/mineiros-io/terradoc/cmd/terradoc@latest'" + exit 1 +fi + terradoc generate $1 -o $2