diff --git a/.github/templates/README.tpl b/.github/templates/README.tpl
index 4bc1ffa..f570f84 100644
--- a/.github/templates/README.tpl
+++ b/.github/templates/README.tpl
@@ -1,5 +1,6 @@
{{- define "escape_chars" }}{{ . | strings.ReplaceAll "_" "\\_" | strings.ReplaceAll "|" "\\|" | strings.ReplaceAll "*" "\\*" }}{{- end }}
{{- define "sanatize_string" }}{{ . | strings.ReplaceAll "\n\n" "
" | strings.ReplaceAll " \n" "
" | strings.ReplaceAll "\n" "
" | tmpl.Exec "escape_chars" }}{{- end }}
+{{- define "sanatize_value" }}{{ . | strings.ReplaceAll "\n\n" "\\n\\n" | strings.ReplaceAll " \n" "\\n" | strings.ReplaceAll "\n" "\\n" }}{{- end }}
{{- $action := (datasource "action") -}}
{{- $version := or (getenv "VERSION") "main" -}}
# terraform-docs GitHub Actions
@@ -46,7 +47,7 @@ jobs:
git-push: "true"
```
-| WARNING: If USAGE.md already exists it will need to be updated, with the block delimeters `` and ``, where the generated markdown will be injected. |
+| NOTE: If USAGE.md already exists it will need to be updated, with the block delimeters `` and ``, where the generated markdown will be injected. Otherwise the generated content will be appended at the end of the file. |
| --- |
## Configuration
@@ -56,7 +57,7 @@ jobs:
| Name | Description | Default | Required |
|------|-------------|---------|----------|
{{- range $key, $input := $action.inputs }}
-| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $input "description") }}{{ tmpl.Exec "sanatize_string" $input.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} | {{ if (has $input "default") }}`{{ if $input.default }}{{ tmpl.Exec "sanatize_string" $input.default }}{{ else }}""{{ end }}`{{ else }}N/A{{ end }} | {{ if (has $input "required") }}{{ $input.required }}{{ else }}false{{ end }} |
+| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $input "description") }}{{ tmpl.Exec "sanatize_string" $input.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} | {{ if (has $input "default") }}`{{ if $input.default }}{{ tmpl.Exec "sanatize_value" $input.default }}{{ else }}""{{ end }}`{{ else }}N/A{{ end }} | {{ if (has $input "required") }}{{ $input.required }}{{ else }}false{{ end }} |
{{- end }}
#### Output Method (output-method)
@@ -72,10 +73,10 @@ jobs:
- `inject`
Instead of replacing the `output-file`, this will inject the generated documentation
- into the existing file between the predefined delimeters: ``
- and ``. If the file exists but does not contain the delimeters,
- the action will fail for the given module. If the file doesn't exist, it will create
- it using the value template which MUST have the delimeters.
+ into the existing file between the predefined delimeters: ``
+ and ``. If the file exists but does not contain the delimeters,
+ the action will append the generated content at the end of `output-file`. If the file
+ doesn't exist, it will create it using the value template which MUST have the delimeters.
#### Auto commit changes
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5996eb0..e2ad545 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -12,8 +12,8 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- ref: ${{github.event.pull_request.head.ref}}
- repository: ${{github.event.pull_request.head.repo.full_name}}
+ ref: ${{ github.event.pull_request.head.ref }}
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Build Docker image
run: |
@@ -24,7 +24,8 @@ jobs:
uses: ./
with:
working-dir: examples/tf11_basic
- template: |
+ template: |-
+
# Test tf11 basic
## Verify
@@ -34,8 +35,8 @@ jobs:
# Usage
-
-
+ {{ .Content }}
+
indention: 3
- name: Should generate USAGE.md for tf11_extra_args
@@ -74,13 +75,6 @@ jobs:
output-file: README.md
config-file: .terraform-docs.yml
- - name: Should generate README.md for tf12_fail_diff
- uses: ./
- with:
- working-dir: examples/tf12_fail_diff
- output-file: README.md
- indention: 3
-
- name: Should generate README.md for tf12_inject and push up all changes
uses: ./
with:
diff --git a/README.md b/README.md
index 9e953b6..2016727 100644
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@ jobs:
git-push: "true"
```
-| WARNING: If USAGE.md already exists it will need to be updated, with the block delimeters `` and ``, where the generated markdown will be injected. |
+| NOTE: If USAGE.md already exists it will need to be updated, with the block delimeters `` and ``, where the generated markdown will be injected. Otherwise the generated content will be appended at the end of the file. |
| --- |
## Configuration
@@ -60,7 +60,7 @@ jobs:
| output-file | File in module directory where the docs should be placed | `USAGE.md` | false |
| output-format | terraform-docs format to generate content (see [all formats](https://github.com/terraform-docs/terraform-docs/blob/master/docs/FORMATS\_GUIDE.md)) (ignored if `config-file` is set) | `markdown table` | false |
| output-method | Method should be one of `replace`, `inject`, or `print` | `inject` | false |
-| template | When provided will be used as the template if/when the `output-file` does not exist | `# Usage
` | false |
+| template | When provided will be used as the template if/when the `output-file` does not exist | `\n{{ .Content }}\n` | false |
| working-dir | Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set) | `.` | false |
#### Output Method (output-method)
@@ -76,10 +76,10 @@ jobs:
- `inject`
Instead of replacing the `output-file`, this will inject the generated documentation
- into the existing file between the predefined delimeters: ``
- and ``. If the file exists but does not contain the delimeters,
- the action will fail for the given module. If the file doesn't exist, it will create
- it using the value template which MUST have the delimeters.
+ into the existing file between the predefined delimeters: ``
+ and ``. If the file exists but does not contain the delimeters,
+ the action will append the generated content at the end of `output-file`. If the file
+ doesn't exist, it will create it using the value template which MUST have the delimeters.
#### Auto commit changes
diff --git a/action.yml b/action.yml
index 893422d..c8fb994 100644
--- a/action.yml
+++ b/action.yml
@@ -33,11 +33,10 @@ inputs:
default: "USAGE.md"
template:
description: When provided will be used as the template if/when the `output-file` does not exist
- default: |
- # Usage
-
-
-
+ default: |-
+
+ {{ .Content }}
+
required: false
args:
description: Additional arguments to pass to the command (see [full documentation](https://github.com/terraform-docs/terraform-docs/tree/master/docs))
diff --git a/examples/tf11_basic/README.md b/examples/tf11_basic/README.md
index 119e6c8..9854c1e 100644
--- a/examples/tf11_basic/README.md
+++ b/examples/tf11_basic/README.md
@@ -7,7 +7,8 @@
uses: ./
with:
working-dir: examples/tf11_basic
- template: |
+ template: |-
+
# Test tf11 basic
## Verify
@@ -17,8 +18,8 @@
# Usage
-
-
+ {{ .Content }}
+
indention: 3
```
diff --git a/examples/tf11_basic/USAGE.md b/examples/tf11_basic/USAGE.md
index 092de24..2dd753f 100644
--- a/examples/tf11_basic/USAGE.md
+++ b/examples/tf11_basic/USAGE.md
@@ -1,13 +1,13 @@
-# Test tf11 basic
-
-## Verify
-
-Should use the template defined instead of the default
-Should inject the table under usage
-
-## Usage
-
-
+
+# Test tf11 basic
+
+## Verify
+
+Should use the template defined instead of the default
+Should inject the table under usage
+
+# Usage
+
### Requirements
| Name | Version |
@@ -49,5 +49,4 @@ No modules.
| Name | Description |
|------|-------------|
| [vpc\_id](#output\_vpc\_id) | The Id of the VPC |
-
-
+
diff --git a/examples/tf11_extra_args/README.md b/examples/tf11_extra_args/README.md
deleted file mode 100644
index 4153ffe..0000000
--- a/examples/tf11_extra_args/README.md
+++ /dev/null
@@ -1,41 +0,0 @@
-## Requirements
-
-| Name | Version |
-|------|---------|
-| aws | < 2.2.0 |
-| consul | >= 1.0.0 |
-
-## Providers
-
-| Name | Version |
-|------|---------|
-| aws | < 2.2.0 |
-| consul | >= 1.0.0 |
-
-## Modules
-
-No Modules.
-
-## Resources
-
-| Name |
-|------|
-| [aws_acm_certificate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/acm_certificate) |
-| [consul_key](https://registry.terraform.io/providers/hashicorp/consul/latest/docs/data-sources/key) |
-
-## Inputs
-
-| Name | Description | Type | Default | Required |
-|------|-------------|------|---------|:--------:|
-| extra\_environment | List of additional environment variables | `list` | `[]` | no |
-| extra\_tags | Additional tags | `map` | `{}` | no |
-| instance\_count | Number of instances to create | `string` | `"1"` | no |
-| instance\_name | Instance name prefix | `string` | `"test-"` | no |
-| subnet\_ids | A list of subnet ids to use | `list` | n/a | yes |
-| vpc\_id | The id of the vpc | `string` | n/a | yes |
-
-## Outputs
-
-| Name | Description |
-|------|-------------|
-| vpc\_id | The Id of the VPC |
diff --git a/examples/tf11_extra_args/USAGE.md b/examples/tf11_extra_args/USAGE.md
index 3b1ad15..295dc14 100644
--- a/examples/tf11_extra_args/USAGE.md
+++ b/examples/tf11_extra_args/USAGE.md
@@ -1,6 +1,4 @@
-# Usage
-
-
+
### Providers
The following providers are used by this module:
@@ -79,6 +77,4 @@ The following outputs are exported:
#### [vpc\_id](#output\_vpc\_id)
Description: The Id of the VPC
-
-
-
+
\ No newline at end of file
diff --git a/examples/tf12_atlantis/README.md b/examples/tf12_atlantis/README.md
index efe01cd..992fbf8 100644
--- a/examples/tf12_atlantis/README.md
+++ b/examples/tf12_atlantis/README.md
@@ -1,25 +1,25 @@
-# Test tf12 Atlantis
-
-## Input
-
-```yaml
-- name: Should generate README.md for tf12_atlantis
- uses: ./
- with:
- atlantis-file: atlantis.yaml
- output-file: README.md
- args: --hide providers
- indention: 3
-```
-
-## Verify
-
-- Should inject below Usage in README.md
-- Should not show providers section
-
-## Usage
-
-
+# Test tf12 Atlantis
+
+## Input
+
+```yaml
+- name: Should generate README.md for tf12_atlantis
+ uses: ./
+ with:
+ atlantis-file: atlantis.yaml
+ output-file: README.md
+ args: --hide providers
+ indention: 3
+```
+
+## Verify
+
+- Should inject below Usage in README.md
+- Should not show providers section
+
+## Usage
+
+
### Requirements
| Name | Version |
@@ -54,5 +54,4 @@ No modules.
| Name | Description |
|------|-------------|
| [vpc\_id](#output\_vpc\_id) | The Id of the VPC |
-
-
+
diff --git a/examples/tf12_basic/README.md b/examples/tf12_basic/README.md
index 61341b7..9b19108 100644
--- a/examples/tf12_basic/README.md
+++ b/examples/tf12_basic/README.md
@@ -1,23 +1,23 @@
-# Test tf12 basic
-
-## Input
-
-```yaml
-- name: Should generate README.md for tf12_bsic
- uses: ./
- with:
- working-dir: examples/tf12_basic
- output-file: README.md
- indention: 3
-```
-
-## Verify
-
-- Should inject below Usage in README.md
-
-## Usage
-
-
+# Test tf12 basic
+
+## Input
+
+```yaml
+- name: Should generate README.md for tf12_bsic
+ uses: ./
+ with:
+ working-dir: examples/tf12_basic
+ output-file: README.md
+ indention: 3
+```
+
+## Verify
+
+- Should inject below Usage in README.md
+
+## Usage
+
+
### Requirements
| Name | Version |
@@ -59,5 +59,4 @@ No modules.
| Name | Description |
|------|-------------|
| [vpc\_id](#output\_vpc\_id) | The Id of the VPC |
-
-
+
diff --git a/examples/tf12_config/README.md b/examples/tf12_config/README.md
index fc82c19..b9665ce 100644
--- a/examples/tf12_config/README.md
+++ b/examples/tf12_config/README.md
@@ -1,24 +1,24 @@
-# Test tf12 with config file
-
-## Input
-
-```yaml
-- name: Should generate README.md for tf12_config
- uses: ./
- with:
- working-dir: examples/tf12_config
- output-file: README.md
- config-file: .terraform-docs.yml
-```
-
-## Verify
-
-- Should generate based on `examples/tf12_config/.terraform-docs.yml` spec
-- Should inject below Usage in README.md
-
-## Usage
-
-
+# Test tf12 with config file
+
+## Input
+
+```yaml
+- name: Should generate README.md for tf12_config
+ uses: ./
+ with:
+ working-dir: examples/tf12_config
+ output-file: README.md
+ config-file: .terraform-docs.yml
+```
+
+## Verify
+
+- Should generate based on `examples/tf12_config/.terraform-docs.yml` spec
+- Should inject below Usage in README.md
+
+## Usage
+
+
### Inputs
| Name | Description | Type | Default | Required |
@@ -29,5 +29,4 @@
| [extra\_tags](#input\_extra\_tags) | Additional tags | `map(string)` | `{}` | no |
| [instance\_count](#input\_instance\_count) | Number of instances to create | `number` | `1` | no |
| [instance\_name](#input\_instance\_name) | Instance name prefix | `string` | `"test-"` | no |
-
-
+
diff --git a/examples/tf12_fail_diff/README.md b/examples/tf12_fail_diff/README.md
index 71a9944..7fc5025 100644
--- a/examples/tf12_fail_diff/README.md
+++ b/examples/tf12_fail_diff/README.md
@@ -18,7 +18,7 @@
## Usage
-
+
### Requirements
| Name | Version |
@@ -60,5 +60,4 @@ No modules.
| Name | Description |
|------|-------------|
| [vpc\_id](#output\_vpc\_id) | The Id of the VPC |
-
-
+
diff --git a/examples/tf12_find/USAGE.md b/examples/tf12_find/USAGE.md
index b9c0a5b..44636bf 100644
--- a/examples/tf12_find/USAGE.md
+++ b/examples/tf12_find/USAGE.md
@@ -1,6 +1,4 @@
-# Usage
-
-
+
## Requirements
| Name | Version |
@@ -42,5 +40,4 @@ No modules.
| Name | Description |
|------|-------------|
| [vpc\_id](#output\_vpc\_id) | The Id of the VPC |
-
-
+
diff --git a/examples/tf12_find/modules/tf12_find_submodules/USAGE.md b/examples/tf12_find/modules/tf12_find_submodules/USAGE.md
index c2f46e1..20d1038 100644
--- a/examples/tf12_find/modules/tf12_find_submodules/USAGE.md
+++ b/examples/tf12_find/modules/tf12_find_submodules/USAGE.md
@@ -1,6 +1,4 @@
-# Usage
-
-
+
## Requirements
No requirements.
@@ -33,5 +31,4 @@ No resources.
| Name | Description |
|------|-------------|
| [vpc\_id](#output\_vpc\_id) | The Id of the VPC |
-
-
+
diff --git a/examples/tf12_inject/README.md b/examples/tf12_inject/README.md
index c74c41c..4f83a8e 100644
--- a/examples/tf12_inject/README.md
+++ b/examples/tf12_inject/README.md
@@ -8,7 +8,7 @@
with:
working-dir: examples/tf12_inject
output-file: README.md
- args: --sort-by required
+ args: --sort-by-required
indention: 3
git-push: true
git-commit-message: "terraform-docs: automated action"
@@ -21,7 +21,7 @@
## Usage
-
+
### Requirements
| Name | Version |
@@ -63,5 +63,4 @@ No modules.
| Name | Description |
|------|-------------|
| [vpc\_id](#output\_vpc\_id) | The Id of the VPC |
-
-
+
diff --git a/src/docker-entrypoint.sh b/src/docker-entrypoint.sh
index f431a48..b342963 100755
--- a/src/docker-entrypoint.sh
+++ b/src/docker-entrypoint.sh
@@ -14,37 +14,43 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-set -e
+set -o errexit
+set -o pipefail
+set -o errtrace
+
+# shellcheck disable=SC2206
+cmd_args=(${INPUT_OUTPUT_FORMAT})
+
+# shellcheck disable=SC2206
+cmd_args+=(${INPUT_ARGS})
if [ "${INPUT_CONFIG_FILE}" = "disabled" ]; then
case "$INPUT_OUTPUT_FORMAT" in
"asciidoc" | "asciidoc table" | "asciidoc document")
- INPUT_ARGS="--indent ${INPUT_INDENTION} ${INPUT_ARGS}"
+ cmd_args+=(--indent "${INPUT_INDENTION}")
;;
"markdown" | "markdown table" | "markdown document")
- INPUT_ARGS="--indent ${INPUT_INDENTION} ${INPUT_ARGS}"
+ cmd_args+=(--indent "${INPUT_INDENTION}")
;;
esac
if [ -z "${INPUT_TEMPLATE}" ]; then
- INPUT_TEMPLATE=$(printf '# Usage\n\n\n\n')
+ INPUT_TEMPLATE=$(printf '\n{{ .Content }}\n')
fi
fi
-git_setup() {
- if [ -n "${INPUT_GIT_PUSH_USER_NAME}" ]; then
- git config --global user.name "${INPUT_GIT_PUSH_USER_NAME}"
- else
- git config --global user.name github-actions[bot]
- fi
+if [ -z "${INPUT_GIT_PUSH_USER_NAME}" ]; then
+ INPUT_GIT_PUSH_USER_NAME="github-actions[bot]"
+fi
- if [ -n "${INPUT_GIT_PUSH_USER_EMAIL}" ]; then
- git config --global user.email "${INPUT_GIT_PUSH_USER_EMAIL}"
- else
- git config --global user.email github-actions[bot]@users.noreply.github.com
- fi
+if [ -z "${INPUT_GIT_PUSH_USER_EMAIL}" ]; then
+ INPUT_GIT_PUSH_USER_EMAIL="github-actions[bot]@users.noreply.github.com"
+fi
+git_setup() {
+ git config --global user.name "${INPUT_GIT_PUSH_USER_NAME}"
+ git config --global user.email "${INPUT_GIT_PUSH_USER_EMAIL}"
git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
}
@@ -53,105 +59,84 @@ git_add() {
file="$1"
git add "${file}"
if [ "$(git status --porcelain | grep "$file" | grep -c -E '([MA]\W).+')" -eq 1 ]; then
- echo "::debug file=entrypoint.sh,line=46 Added ${file} to git staging area"
+ echo "::debug Added ${file} to git staging area"
else
- echo "::debug file=entrypoint.sh,line=48 No change in ${file} detected"
+ echo "::debug No change in ${file} detected"
fi
}
git_status() {
- git status --porcelain | grep -c -E '([MA]\W).+'
+ git status --porcelain | grep -c -E '([MA]\W).+' || true
}
git_commit() {
- local is_clean
- set +e
- is_clean=$(git_status)
- set -e
- if [ "${is_clean}" -eq 0 ]; then
- echo "::debug file=entrypoint.sh,line=54 No files changed, skipping commit"
+ if [ "$(git_status)" -eq 0 ]; then
+ echo "::debug No files changed, skipping commit"
exit 0
- else
- local signoff
- signoff=""
- if [ "${INPUT_GIT_PUSH_SIGN_OFF}" = "true" ]; then
- signoff="-s"
- fi
- git commit ${signoff} -m "${INPUT_GIT_COMMIT_MESSAGE}"
fi
+
+ echo "::debug Following files will be committed"
+ git status -s
+
+ local args=(
+ -m "${INPUT_GIT_COMMIT_MESSAGE}"
+ )
+
+ if [ "${INPUT_GIT_PUSH_SIGN_OFF}" = "true" ]; then
+ args+=("-s")
+ fi
+
+ git commit "${args[@]}"
}
update_doc() {
local working_dir
- local generated
- local success
-
working_dir="$1"
- echo "::debug file=entrypoint.sh,line=66 working_dir=${working_dir}"
+ echo "::debug working_dir=${working_dir}"
- set +e
+ local exec_args
+ exec_args=( "${cmd_args[@]}" )
- # shellcheck disable=SC2086
if [ -n "${INPUT_CONFIG_FILE}" ] && [ "${INPUT_CONFIG_FILE}" != "disabled" ]; then
- echo "::debug file=entrypoint.sh,line=80 command=terraform-docs --config ${INPUT_CONFIG_FILE} ${INPUT_ARGS} ${working_dir}"
local config_file
+
if [ -f "${INPUT_CONFIG_FILE}" ]; then
config_file="${INPUT_CONFIG_FILE}"
else
config_file="${working_dir}/${INPUT_CONFIG_FILE}"
fi
- terraform-docs --config ${config_file} ${INPUT_ARGS} ${working_dir} >/tmp/tf_generated
- success=$?
- else
- echo "::debug file=entrypoint.sh,line=84 command=terraform-docs ${INPUT_OUTPUT_FORMAT} ${INPUT_ARGS} ${working_dir}"
- terraform-docs ${INPUT_OUTPUT_FORMAT} ${INPUT_ARGS} ${working_dir} >/tmp/tf_generated
- success=$?
+
+ echo "::debug config_file=${config_file}"
+ exec_args+=(--config "${config_file}")
fi
- set -e
+ if [ "${INPUT_OUTPUT_METHOD}" == "inject" ] || [ "${INPUT_OUTPUT_METHOD}" == "replace" ]; then
+ echo "::debug output_mode=${INPUT_OUTPUT_METHOD}"
+ exec_args+=(--output-mode "${INPUT_OUTPUT_METHOD}")
- if [ $success -ne 0 ]; then
- echo "::error file=entrypoint.sh,line=89::$(cat /tmp/tf_generated)"
- rm -f /tmp/tf_generated
- exit $success
+ echo "::debug output_file=${INPUT_OUTPUT_FILE}"
+ exec_args+=(--output-file "${INPUT_OUTPUT_FILE}")
fi
- generated=$(cat /tmp/tf_generated)
- rm -f /tmp/tf_generated
+ if [ -n "${INPUT_TEMPLATE}" ]; then
+ exec_args+=(--output-template "${INPUT_TEMPLATE}")
+ fi
- case "${INPUT_OUTPUT_METHOD}" in
- print)
- echo "${generated}"
- ;;
+ exec_args+=("${working_dir}")
- replace | inject)
- # Create file if it doesn't exist
- if [ "${INPUT_OUTPUT_METHOD}" = "replace" ]; then
- echo "${INPUT_TEMPLATE}" >"${working_dir}/${INPUT_OUTPUT_FILE}"
- else
- if [ ! -f "${working_dir}/${INPUT_OUTPUT_FILE}" ]; then
- echo "${INPUT_TEMPLATE}" >"${working_dir}/${INPUT_OUTPUT_FILE}"
- fi
- fi
+ local success
- local has_delimiter
- has_delimiter=$(grep -c -E '(BEGIN|END)_TF_DOCS' "${working_dir}/${INPUT_OUTPUT_FILE}")
- echo "::debug file=entrypoint.sh,line=115 has_delimiter=${has_delimiter}"
+ echo "::debug terraform-docs" "${exec_args[@]}"
+ terraform-docs "${exec_args[@]}"
+ success=$?
- # Verify it has BEGIN and END markers
- if [ "${has_delimiter}" -ne 2 ]; then
- echo "::error file=entrypoint.sh,line=119::Output file ${working_dir}/${INPUT_OUTPUT_FILE} does not contain BEGIN_TF_DOCS and END_TF_DOCS"
- exit 1
- fi
+ if [ $success -ne 0 ]; then
+ exit $success
+ fi
- # Output generated markdown to temporary file with a trailing newline and then replace the block
- echo "${generated}" >/tmp/tf_doc.md
- echo "" >>/tmp/tf_doc.md
- sed -i -ne '// {p; r /tmp/tf_doc.md' -e ':a; n; // {p; b}; ba}; p' "${working_dir}/${INPUT_OUTPUT_FILE}"
- git_add "${working_dir}/${INPUT_OUTPUT_FILE}"
- rm -f /tmp/tf_doc.md
- ;;
- esac
+ if [ "${INPUT_OUTPUT_METHOD}" == "inject" ] || [ "${INPUT_OUTPUT_METHOD}" == "replace" ]; then
+ git_add "${working_dir}/${OUTPUT_FILE}"
+ fi
}
# go to github repo
@@ -161,15 +146,14 @@ git_setup
if [ -f "${GITHUB_WORKSPACE}/${INPUT_ATLANTIS_FILE}" ]; then
# Parse an atlantis yaml file
- while read -r line; do
- project_dir=${line//- /}
- update_doc "${project_dir}"
- done < <(yq e '.projects[].dir' "${GITHUB_WORKSPACE}/${INPUT_ATLANTIS_FILE}")
+ for line in $(yq e '.projects[].dir' "${GITHUB_WORKSPACE}/${INPUT_ATLANTIS_FILE}"); do
+ update_doc "${line//- /}"
+ done
elif [ -n "${INPUT_FIND_DIR}" ] && [ "${INPUT_FIND_DIR}" != "disabled" ]; then
# Find all tf
- while read -r project_dir; do
+ for project_dir in $(find "${INPUT_FIND_DIR}" -name '*.tf' -exec dirname {} \; | uniq); do
update_doc "${project_dir}"
- done < <(find "${INPUT_FIND_DIR}" -name '*.tf' -exec dirname {} \; | uniq)
+ done
else
# Split INPUT_WORKING_DIR by commas
for project_dir in ${INPUT_WORKING_DIR//,/ }; do
@@ -188,7 +172,7 @@ if [ "${INPUT_GIT_PUSH}" = "true" ]; then
git push
else
if [ "${INPUT_FAIL_ON_DIFF}" = "true" ] && [ "${num_changed}" -ne 0 ]; then
- echo "::error file=entrypoint.sh,line=169::Uncommitted change(s) has been found!"
+ echo "::error ::Uncommitted change(s) has been found!"
exit 1
fi
fi