Skip to content

Commit

Permalink
fix failing scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
  • Loading branch information
khos2ow committed Dec 31, 2020
1 parent 796d224 commit cf3d4d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
uses: ./
with:
working-dir: examples/tf11_extra_args
content-type: document
indention: 3
args: --no-sensitive --no-requirements --no-required
output-format: markdown document
output-method: replace
indention: 3
args: --sensitive=false --hide requirements --required=false

- name: Should inject into README.md
uses: ./
Expand All @@ -45,9 +45,9 @@ jobs:
- name: Should generate README.md for tf12_atlantis
uses: ./
with:
atlantis_file: atlantis.yaml
atlantis-file: atlantis.yaml
output-file: README.md
args: --no-providers
args: --hide providers

- name: Should generate README.md for tf12_find and its submodules
uses: ./
Expand All @@ -59,13 +59,13 @@ jobs:
with:
find-dir: examples/tf12_inject
output-file: README.md
args: --sort-inputs-by-required
args: --sort-by-required

- name: Push up changes
uses: ./
with:
working-dir: examples/tf12_basic
content-type: json
output-method: print
output-format: markdown table
output-method: replace
git-push: true
git-commit-message: "chore: terraform-docs build"
36 changes: 22 additions & 14 deletions src/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash

set -e
set -o pipefail

# Ensure all variables are present
WORKING_DIR="${1}"
Expand All @@ -16,7 +15,15 @@ INDENTION="${9}"
GIT_PUSH="${10}"
GIT_COMMIT_MESSAGE="${11}"

ARGS="--indent ${INDENTION} ${ARGS}"
case "$OUTPUT_FORMAT" in
"asciidoc" | "asciidoc table" | "asciidoc document")
ARGS="--indent ${INDENTION} ${ARGS}"
;;

"markdown" | "markdown table" | "markdown document")
ARGS="--indent ${INDENTION} ${ARGS}"
;;
esac

if [ -z "${TEMPLATE}" ]; then
TEMPLATE=$(printf '# Usage\n\n<!--- BEGIN_TF_DOCS --->\n<!--- END_TF_DOCS --->\n')
Expand All @@ -25,13 +32,14 @@ fi
git_setup() {
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}"@users.noreply.github.com
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
}

git_add() {
local files
files="${0}"
files="$1"
git add "${files}"
echo "::debug file=entrypoint.sh,line=34,col=1 Added ${files} to git staging area"
}

git_status() {
Expand All @@ -41,8 +49,8 @@ git_status() {
git_commit() {
local is_clean
is_clean=$(git_status)
if [ "${is_clean}" -eq -1 ]; then
echo "::debug file=docker-entrypoint.sh,line=47,col=1 No files changed, skipping commit"
if [ "${is_clean}" -eq 0 ]; then
echo "::debug file=entrypoint.sh,line=45,col=1 No files changed, skipping commit"
else
git commit -m "${GIT_COMMIT_MESSAGE}"
fi
Expand All @@ -52,10 +60,11 @@ update_doc() {
local working_dir
local generated

working_dir="${0}"
echo "::debug file=docker-entrypoint.sh,line=55,col=1 working_dir=${working_dir}"
working_dir="$1"
echo "::debug file=entrypoint.sh,line=56,col=1 working_dir=${working_dir}"

generated=$(terraform-docs "${OUTPUT_FORMAT}" "${ARGS}" "${working_dir}")
# shellcheck disable=SC2086
generated=$(terraform-docs ${OUTPUT_FORMAT} ${ARGS} ${working_dir})

case "${OUTPUT_METHOD}" in
print)
Expand All @@ -75,11 +84,11 @@ update_doc() {

local has_delimiter
has_delimiter=$(grep -c -E '(BEGIN|END)_TF_DOCS' "${working_dir}/${OUTPUT_FILE}")
echo "::debug file=common.sh,line=46,col=1 has_delimiter=${has_delimiter}"
echo "::debug file=entrypoint.sh,line=78,col=1 has_delimiter=${has_delimiter}"

# Verify it has BEGIN and END markers
if [ "${has_delimiter}" -ne 1 ]; then
echo "::error file=common.sh,line=49,col=1::Output file ${working_dir}/${OUTPUT_FILE} does not contain BEGIN_TF_DOCS and END_TF_DOCS"
if [ "${has_delimiter}" -ne 2 ]; then
echo "::error file=entrypoint.sh,line=82,col=1::Output file ${working_dir}/${OUTPUT_FILE} does not contain BEGIN_TF_DOCS and END_TF_DOCS"
exit 1
fi

Expand Down Expand Up @@ -119,8 +128,7 @@ if [ "${GIT_PUSH}" = "true" ]; then
git_commit
git push
else
num_changed=$(git_status)
echo "::set-output name=num-changed::${num_changed}"
echo "::set-output name=num-changed::$(git_status)"
fi

exit 0

0 comments on commit cf3d4d4

Please sign in to comment.