Skip to content

Commit

Permalink
Merge pull request #15 from userhas404d/target-update
Browse files Browse the repository at this point in the history
Target update
  • Loading branch information
userhas404d authored Jan 24, 2020
2 parents 3adf2e2 + a58118e commit ed41f4a
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -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}

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 29 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?= <!-- BEGIN TFDOCS -->
docs/%: TFDOCS_END_MARKER ?= <!-- END TFDOCS -->

## 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
Expand Down Expand Up @@ -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
12 changes: 9 additions & 3 deletions tests/make/docs_generate_failure.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" <<EOF

mkdir -p "$working_dir"
cat > "$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
<!-- BEGIN TFDOCS
END TFDOCS -->
EOF
# intentially exclude the _docs/MAIN.md
done

}
Expand Down
12 changes: 8 additions & 4 deletions tests/make/docs_generate_success.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" <<EOF

mkdir -p "$working_dir"
cat > "$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
# Test
<!-- BEGIN TFDOCS -->
<!-- END TFDOCS -->
EOF
done

Expand Down
42 changes: 42 additions & 0 deletions tests/make/docs_lint_failure.bats
Original file line number Diff line number Diff line change
@@ -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" <<EOF
# Foo
<!-- BEGIN TFDOCS -->
bar
<!-- END TFDOCS -->
EOF
done

}

@test "docs/lint: nested file failure" {
run make docs/lint
[ "$status" -eq 2 ]
}

function teardown() {
rm -rf "$TEST_DIR"
}
52 changes: 52 additions & 0 deletions tests/make/docs_lint_success.bats
Original file line number Diff line number Diff line change
@@ -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" <<EOF
variable "foo" {
default = "bar"
type = string
description = "test var"
}
EOF
cat > "$working_dir/README.md" <<"EOF"
# Foo
<!-- BEGIN TFDOCS -->
## Providers
No provider.
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| foo | test var | `string` | `"bar"` | no |
## Outputs
No output.
<!-- END TFDOCS -->
EOF
done

}

@test "docs/lint: nested file success" {
run make docs/lint
[ "$status" -eq 0 ]
}

function teardown() {
rm -rf "$TEST_DIR"
}

0 comments on commit ed41f4a

Please sign in to comment.