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} + 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 diff --git a/Makefile b/Makefile index db90e055..97e4a480 100644 --- a/Makefile +++ b/Makefile @@ -144,22 +144,35 @@ 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 ?= -## Generates terraform documentation -docs/generate: | tfdocs-awk/install guard/program/terraform-docs +docs/tmp/%: | guard/program/terraform-docs + 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.." - @ bash -eu -o pipefail autodocs.sh -g - @ echo "[$@]: Documentation generated!" + @ $(MAKE) docs/tmp/$* + mv -f $(README_TMP) $* + @ echo "[$@]: Documentation files creation complete!" + +docs/lint/%: + @ echo "[$@]: Linting documentation files.." + @ $(MAKE) docs/tmp/$* + diff $* $(README_TMP) + rm -f $(README_TMP) + @ echo "[$@]: Documentation files PASSED lint test!" -## 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!" +## Generates Terraform documentation +docs/generate: | terraform/format + @ $(README_FILES) | $(XARGS) $(MAKE) docs/generate/{} + +## Lints Terraform documentation +docs/lint: | terraform/lint + @ $(README_FILES) | $(XARGS) $(MAKE) docs/lint/{} TERRAFORM_TEST_DIR ?= tests terratest/install: | guard/program/go @@ -190,4 +203,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..f22cf459 100644 --- a/tests/make/docs_generate_failure.bats +++ b/tests/make/docs_generate_failure.bats @@ -8,15 +8,21 @@ 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 } diff --git a/tests/make/docs_generate_success.bats b/tests/make/docs_generate_success.bats index aeb42fee..bfb05723 100644 --- a/tests/make/docs_generate_success.bats +++ b/tests/make/docs_generate_success.bats @@ -4,20 +4,24 @@ 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..0cdc265d --- /dev/null +++ b/tests/make/docs_lint_failure.bats @@ -0,0 +1,42 @@ +#!/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" + + 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..8eaab1fa --- /dev/null +++ b/tests/make/docs_lint_success.bats @@ -0,0 +1,52 @@ +#!/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" + + 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" +}