From 00100050d5cc6f2c62c7b526f10ad7bb3bbd1330 Mon Sep 17 00:00:00 2001 From: userhas404d <29389186+userhas404d@users.noreply.github.com> Date: Wed, 22 Jan 2020 20:14:43 -0500 Subject: [PATCH 1/7] Adds unified lint target --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index db90e055..d698a14e 100644 --- a/Makefile +++ b/Makefile @@ -191,3 +191,5 @@ bats/test: | guard/program/bats @ echo "[$@]: Completed successfully!" install: terraform/install shellcheck/install tfdocs-awk/install bats/install + +lint: terraform/lint sh/lint json/lint docs/lint From 8b0ab8f70ff28ba9ae88495d949ea31d1938668c Mon Sep 17 00:00:00 2001 From: userhas404d <29389186+userhas404d@users.noreply.github.com> Date: Thu, 23 Jan 2020 20:33:12 -0500 Subject: [PATCH 2/7] Updates terraform-docs make targets and associated tests --- Makefile | 44 +++++++++++++++------- tests/make/docs_generate_failure.bats | 18 +++++++-- tests/make/docs_generate_success.bats | 15 ++++++-- tests/make/docs_lint_failure.bats | 44 ++++++++++++++++++++++ tests/make/docs_lint_success.bats | 54 +++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 21 deletions(-) create mode 100644 tests/make/docs_lint_failure.bats create mode 100644 tests/make/docs_lint_success.bats diff --git a/Makefile b/Makefile index d698a14e..1554ed74 100644 --- a/Makefile +++ b/Makefile @@ -144,22 +144,40 @@ json/format: | guard/program/jq json/validate $(FIND_JSON) | $(XARGS) bash -c 'echo "$$(jq --indent 4 -S . "{}")" > "{}"' @ echo "[$@]: Successfully formatted JSON files!" -tfdocs-awk/install: $(BIN_DIR) -tfdocs-awk/install: ARCHIVE := https://github.com/plus3it/tfdocs-awk/archive/0.0.2.tar.gz -tfdocs-awk/install: - $(CURL) $(ARCHIVE) | tar -C $(BIN_DIR) --strip-components=1 --wildcards '*.sh' --wildcards '*.awk' -xzvf - +docs/%: TFDOCS ?= terraform-docs --sort-by-required markdown table +docs/%: README_FILES ?= find . -type f -name README.md +docs/%: README_TMP ?= $(TMP)/README.tmp +docs/%: TFDOCS_START_MARKER ?= +docs/%: TFDOCS_END_MARKER ?= + +docs/tmp/%: | guard/program/terraform-docs +docs/tmp/%: + [[ $$(grep '' $*) && $$(grep '' $*) ]] && \ + sed '/$(TFDOCS_START_MARKER)/,/$(TFDOCS_END_MARKER)/{//!d}' $* | awk '{print $$0} /$(TFDOCS_START_MARKER)/ {system("$(TFDOCS) $$(dirname $*)")} /$(TFDOCS_END_MARKER)/ {f=1}' > $(README_TMP) || \ + exit 0 + +docs/generate/%: + @ echo "[$@]: Creating documentation files.." + @ $(MAKE) docs/tmp/$* + [[ $$(grep '' $*) && $$(grep '' $*) ]] && \ + mv -f $(README_TMP) $* || \ + echo "$* doesn't contain tf docs markers, skipping.." + @ echo "[$@]: Documentation files creation complete!" + +docs/lint/%: + @ echo "[$@]: Linting documentation files.." + @ $(MAKE) docs/tmp/$* + [[ $$(grep '' $*) && $$(grep '' $*) ]] && diff $* $(README_TMP); \ + [ -s $(README_TMP) ] && rm -f $(README_TMP) + @ echo "[$@]: Documentation files PASSED lint test!" ## Generates terraform documentation -docs/generate: | tfdocs-awk/install guard/program/terraform-docs - @ echo "[$@]: Creating documentation files.." - @ bash -eu -o pipefail autodocs.sh -g - @ echo "[$@]: Documentation generated!" +docs/generate: + @ $(README_FILES) | $(XARGS) $(MAKE) docs/generate/{} ## Lints terraform documentation -docs/lint: | tfdocs-awk/install guard/program/terraform-docs - @ echo "[$@] Linting documentation files.." - @ bash -eu -o pipefail autodocs.sh -l - @ echo "[$@] documentation linting complete!" +docs/lint: + @ $(README_FILES) | $(XARGS) $(MAKE) docs/lint/{} TERRAFORM_TEST_DIR ?= tests terratest/install: | guard/program/go @@ -190,6 +208,6 @@ bats/test: | guard/program/bats cd tests/make && bats -r *.bats @ echo "[$@]: Completed successfully!" -install: terraform/install shellcheck/install tfdocs-awk/install bats/install +install: terraform/install shellcheck/install terraform-docs/install bats/install lint: terraform/lint sh/lint json/lint docs/lint diff --git a/tests/make/docs_generate_failure.bats b/tests/make/docs_generate_failure.bats index d96272af..d9ae1efd 100644 --- a/tests/make/docs_generate_failure.bats +++ b/tests/make/docs_generate_failure.bats @@ -8,22 +8,32 @@ rm -rf "$TEST_DIR" working_dirs=("$TEST_DIR" "$TEST_DIR/nested") for working_dir in "${working_dirs[@]}" do - mkdir -p "$working_dir/_docs" - cat > "$working_dir/main.tf" < "$working_dir/main.tf" <<"EOF" variable "foo" { default = "bar" type = string description = "test var +EOF +# intentionally malform the readmes + cat > "$working_dir/README.md" <<"EOF" +# Foo + EOF -# intentially exclude the _docs/MAIN.md done } +# due to a workaround to handle non-tf readmes this check will exit 0 @test "docs/generate: nested file failure" { run make docs/generate - [ "$status" -eq 2 ] + [ "$status" -eq 0 ] } function teardown() { diff --git a/tests/make/docs_generate_success.bats b/tests/make/docs_generate_success.bats index aeb42fee..d6804f10 100644 --- a/tests/make/docs_generate_success.bats +++ b/tests/make/docs_generate_success.bats @@ -4,20 +4,27 @@ TEST_DIR="$(pwd)/docs_generate_success" # generate a test terraform project with a nested "module" function setup() { +rm -rf "$TEST_DIR" working_dirs=("$TEST_DIR" "$TEST_DIR/nested") for working_dir in "${working_dirs[@]}" do - mkdir -p "$working_dir/_docs" - cat > "$working_dir/main.tf" < "$working_dir/main.tf" <<"EOF" variable "foo" { default = "bar" type = string description = "test var" } EOF + cat > "$working_dir/README.md" <<"EOF" +# Foo - cat > "$working_dir/_docs/MAIN.md" < + EOF done diff --git a/tests/make/docs_lint_failure.bats b/tests/make/docs_lint_failure.bats new file mode 100644 index 00000000..3a68ff1b --- /dev/null +++ b/tests/make/docs_lint_failure.bats @@ -0,0 +1,44 @@ +#!/usr/bin/env bats + +TEST_DIR="$(pwd)/docs_lint_failure" + +# generate a test terraform project with a nested "module" +function setup() { +rm -rf "$TEST_DIR" +working_dirs=("$TEST_DIR" "$TEST_DIR/nested") +for working_dir in "${working_dirs[@]}" +do + + mkdir -p "$working_dir" + touch "$working_dir/main.tf" + touch "$working_dir/README.md" + + cat > "$working_dir/main.tf" <<"EOF" + variable "foo" { + default = "bar" + type = string + description = "test var" + } +EOF + # intentionally generate incomplete READMEs + cat > "$working_dir/README.md" < + +bar + + +EOF +done + +} + +@test "docs/lint: nested file failure" { + run make docs/lint + [ "$status" -eq 2 ] +} + +function teardown() { + rm -rf "$TEST_DIR" +} diff --git a/tests/make/docs_lint_success.bats b/tests/make/docs_lint_success.bats new file mode 100644 index 00000000..30b33c09 --- /dev/null +++ b/tests/make/docs_lint_success.bats @@ -0,0 +1,54 @@ +#!/usr/bin/env bats + +TEST_DIR="$(pwd)/docs_lint_success" + +# generate a test terraform project with a nested "module" +function setup() { +rm -rf "$TEST_DIR" +working_dirs=("$TEST_DIR" "$TEST_DIR/nested") +for working_dir in "${working_dirs[@]}" +do + + mkdir -p "$working_dir" + touch "$working_dir/main.tf" + touch "$working_dir/README.md" + + cat > "$working_dir/main.tf" < "$working_dir/README.md" <<"EOF" +# Foo + + +## Providers + +No provider. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:-----:| +| foo | test var | `string` | `"bar"` | no | + +## Outputs + +No output. + + +EOF +done + +} + +@test "docs/lint: nested file success" { + run make docs/lint + [ "$status" -eq 0 ] +} + +function teardown() { + rm -rf "$TEST_DIR" +} From 64e6d9ebf57228fd01e57598ef67934b742fea9c Mon Sep 17 00:00:00 2001 From: userhas404d <29389186+userhas404d@users.noreply.github.com> Date: Thu, 23 Jan 2020 20:36:31 -0500 Subject: [PATCH 3/7] Updates changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2979c93d..c2934b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +### 0.0.1 + +**Released**: 2020.1.23 + +**Commit Delta**: [Change from 0.0.0 release](https://github.com/plus3it/tardigrade-ci/compare/0.0.0...0.0.1) + +**Summary**: + +* Updates terraform-docs make targets and associated tests + ### 0.0.0 **Commit Delta**: N/A From c69c6a194d4d21b32f09161a632142462bb6e5f3 Mon Sep 17 00:00:00 2001 From: userhas404d <29389186+userhas404d@users.noreply.github.com> Date: Thu, 23 Jan 2020 20:36:49 -0500 Subject: [PATCH 4/7] Bumps version to 0.0.1 --- .bumpversion.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index ee11dd65..50dd797d 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,6 +1,7 @@ [bumpversion] -current_version = 0.0.0 +current_version = 0.0.1 commit = True message = Bumps version to {new_version} tag = False tag_name = {new_version} + From 04359323b0eabf50e1566d4a7e56de94c424d2fd Mon Sep 17 00:00:00 2001 From: userhas404d <29389186+userhas404d@users.noreply.github.com> Date: Thu, 23 Jan 2020 21:18:21 -0500 Subject: [PATCH 5/7] Removes unnecessary logic from terraform docs make targets --- Makefile | 17 ++++++----------- tests/make/docs_generate_failure.bats | 1 - 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 1554ed74..116bfcb5 100644 --- a/Makefile +++ b/Makefile @@ -151,31 +151,26 @@ docs/%: TFDOCS_START_MARKER ?= docs/%: TFDOCS_END_MARKER ?= docs/tmp/%: | guard/program/terraform-docs -docs/tmp/%: - [[ $$(grep '' $*) && $$(grep '' $*) ]] && \ - sed '/$(TFDOCS_START_MARKER)/,/$(TFDOCS_END_MARKER)/{//!d}' $* | awk '{print $$0} /$(TFDOCS_START_MARKER)/ {system("$(TFDOCS) $$(dirname $*)")} /$(TFDOCS_END_MARKER)/ {f=1}' > $(README_TMP) || \ - exit 0 + sed '/$(TFDOCS_START_MARKER)/,/$(TFDOCS_END_MARKER)/{//!d}' $* | awk '{print $$0} /$(TFDOCS_START_MARKER)/ {system("$(TFDOCS) $$(dirname $*)")} /$(TFDOCS_END_MARKER)/ {f=1}' > $(README_TMP) docs/generate/%: @ echo "[$@]: Creating documentation files.." @ $(MAKE) docs/tmp/$* - [[ $$(grep '' $*) && $$(grep '' $*) ]] && \ - mv -f $(README_TMP) $* || \ - echo "$* doesn't contain tf docs markers, skipping.." + mv -f $(README_TMP) $* @ echo "[$@]: Documentation files creation complete!" docs/lint/%: @ echo "[$@]: Linting documentation files.." @ $(MAKE) docs/tmp/$* - [[ $$(grep '' $*) && $$(grep '' $*) ]] && diff $* $(README_TMP); \ - [ -s $(README_TMP) ] && rm -f $(README_TMP) + diff $* $(README_TMP) + rm -f $(README_TMP) @ echo "[$@]: Documentation files PASSED lint test!" -## Generates terraform documentation +## Generates Terraform documentation docs/generate: @ $(README_FILES) | $(XARGS) $(MAKE) docs/generate/{} -## Lints terraform documentation +## Lints Terraform documentation docs/lint: @ $(README_FILES) | $(XARGS) $(MAKE) docs/lint/{} diff --git a/tests/make/docs_generate_failure.bats b/tests/make/docs_generate_failure.bats index d9ae1efd..f4e20f52 100644 --- a/tests/make/docs_generate_failure.bats +++ b/tests/make/docs_generate_failure.bats @@ -30,7 +30,6 @@ done } -# due to a workaround to handle non-tf readmes this check will exit 0 @test "docs/generate: nested file failure" { run make docs/generate [ "$status" -eq 0 ] From aa5d0042c24e7abb865b4519696bb5eab3a86938 Mon Sep 17 00:00:00 2001 From: userhas404d <29389186+userhas404d@users.noreply.github.com> Date: Fri, 24 Jan 2020 11:06:03 -0500 Subject: [PATCH 6/7] Adds terraform/format as prereq to docs/% targets --- Makefile | 4 ++-- tests/make/docs_generate_failure.bats | 2 +- tests/make/docs_lint_success.bats | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 116bfcb5..97e4a480 100644 --- a/Makefile +++ b/Makefile @@ -167,11 +167,11 @@ docs/lint/%: @ echo "[$@]: Documentation files PASSED lint test!" ## Generates Terraform documentation -docs/generate: +docs/generate: | terraform/format @ $(README_FILES) | $(XARGS) $(MAKE) docs/generate/{} ## Lints Terraform documentation -docs/lint: +docs/lint: | terraform/lint @ $(README_FILES) | $(XARGS) $(MAKE) docs/lint/{} TERRAFORM_TEST_DIR ?= tests diff --git a/tests/make/docs_generate_failure.bats b/tests/make/docs_generate_failure.bats index f4e20f52..20894926 100644 --- a/tests/make/docs_generate_failure.bats +++ b/tests/make/docs_generate_failure.bats @@ -32,7 +32,7 @@ done @test "docs/generate: nested file failure" { run make docs/generate - [ "$status" -eq 0 ] + [ "$status" -eq 2 ] } function teardown() { diff --git a/tests/make/docs_lint_success.bats b/tests/make/docs_lint_success.bats index 30b33c09..e366c7ce 100644 --- a/tests/make/docs_lint_success.bats +++ b/tests/make/docs_lint_success.bats @@ -14,11 +14,11 @@ do touch "$working_dir/README.md" cat > "$working_dir/main.tf" < "$working_dir/README.md" <<"EOF" # Foo From a58118e72845cc7c95361517e0d61c083bc4f9ba Mon Sep 17 00:00:00 2001 From: userhas404d <29389186+userhas404d@users.noreply.github.com> Date: Fri, 24 Jan 2020 12:57:44 -0500 Subject: [PATCH 7/7] Removes touch lines from bats tests --- tests/make/docs_generate_failure.bats | 3 --- tests/make/docs_generate_success.bats | 3 --- tests/make/docs_lint_failure.bats | 2 -- tests/make/docs_lint_success.bats | 2 -- 4 files changed, 10 deletions(-) diff --git a/tests/make/docs_generate_failure.bats b/tests/make/docs_generate_failure.bats index 20894926..f22cf459 100644 --- a/tests/make/docs_generate_failure.bats +++ b/tests/make/docs_generate_failure.bats @@ -10,9 +10,6 @@ for working_dir in "${working_dirs[@]}" do mkdir -p "$working_dir" - touch "$working_dir/main.tf" - touch "$working_dir/README.md" - cat > "$working_dir/main.tf" <<"EOF" variable "foo" { default = "bar" diff --git a/tests/make/docs_generate_success.bats b/tests/make/docs_generate_success.bats index d6804f10..bfb05723 100644 --- a/tests/make/docs_generate_success.bats +++ b/tests/make/docs_generate_success.bats @@ -10,9 +10,6 @@ for working_dir in "${working_dirs[@]}" do mkdir -p "$working_dir" - touch "$working_dir/main.tf" - touch "$working_dir/README.md" - cat > "$working_dir/main.tf" <<"EOF" variable "foo" { default = "bar" diff --git a/tests/make/docs_lint_failure.bats b/tests/make/docs_lint_failure.bats index 3a68ff1b..0cdc265d 100644 --- a/tests/make/docs_lint_failure.bats +++ b/tests/make/docs_lint_failure.bats @@ -10,8 +10,6 @@ for working_dir in "${working_dirs[@]}" do mkdir -p "$working_dir" - touch "$working_dir/main.tf" - touch "$working_dir/README.md" cat > "$working_dir/main.tf" <<"EOF" variable "foo" { diff --git a/tests/make/docs_lint_success.bats b/tests/make/docs_lint_success.bats index e366c7ce..8eaab1fa 100644 --- a/tests/make/docs_lint_success.bats +++ b/tests/make/docs_lint_success.bats @@ -10,8 +10,6 @@ for working_dir in "${working_dirs[@]}" do mkdir -p "$working_dir" - touch "$working_dir/main.tf" - touch "$working_dir/README.md" cat > "$working_dir/main.tf" <