Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add shellcheck and make checks passing #315

Merged
merged 3 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
run: |
curl -L "$(curl -s https://api.github.com/repos/mvdan/sh/releases/latest | grep -o -E -m 1 "https://.+?linux_amd64")" > shfmt \
&& chmod +x shfmt && sudo mv shfmt /usr/bin/

- name: Install shellcheck
run: |
sudo apt update && sudo apt install shellcheck
# Need to success pre-commit fix push
- uses: actions/checkout@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ repos:
hooks:
- id: shfmt
args: ['-l', '-i', '2', '-ci', '-sr', '-w']
- id: shellcheck
4 changes: 3 additions & 1 deletion infracost_breakdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function common::parse_cmdline {
;;
--)
shift
# shellcheck disable=SC2034 # Common function
FILES=("$@")
break
;;
Expand Down Expand Up @@ -101,6 +102,7 @@ function infracost_breakdown_ {
# $hook_config receives string like '1 > 2; 3 == 4;' etc.
# It gets split by `;` into array, which we're parsing here ('1 > 2' ' 3 == 4')
# Next line removes leading spaces, just for fancy output reason.
# shellcheck disable=SC2001 # Rule exception
check=$(echo "$check" | sed 's/^[[:space:]]*//')

# Drop quotes in hook args section. From:
Expand All @@ -116,7 +118,7 @@ function infracost_breakdown_ {
}; then
check="${check:1:-1}"
fi

# shellcheck disable=SC2207 # Can't find working `read` command
operations=($(echo "$check" | grep -oE '[!<>=]{1,2}'))
# Get the very last operator, that is used in comparison inside `jq` query.
# From the example below we need to pick the `>` which is in between `add` and `1000`,
Expand Down
14 changes: 9 additions & 5 deletions terraform_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ function terraform_docs {
local add_to_existing=false
local create_if_not_exist=false

configs=($hook_config)
read -r -a configs <<< "$hook_config"

for c in "${configs[@]}"; do
config=(${c//=/ })

IFS="=" read -r -a config <<< "$c"
key=${config[0]}
value=${config[1]}

Expand Down Expand Up @@ -161,9 +163,11 @@ function terraform_docs {
dir="$(dirname "$text_file")"

mkdir -p "$dir"
echo -e "# ${PWD##*/}\n" >> "$text_file"
echo "<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" >> "$text_file"
echo "<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" >> "$text_file"
{
echo -e "# ${PWD##*/}\n"
echo "<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->"
echo "<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->"
} >> "$text_file"
fi

# If file still not exist - skip dir
Expand Down
35 changes: 17 additions & 18 deletions tests/hooks_performance_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,33 @@ function generate_table {
| time command | max | min | mean | median |
| -------------- | ------ | ------ | -------- | ------ |
| users seconds | $(
printf %"s\n" $users_seconds | datamash max 1
printf %"s\n" "$users_seconds" | datamash max 1
) | $(
printf %"s\n" $users_seconds | datamash min 1
printf %"s\n" "$users_seconds" | datamash min 1
) | $(
printf %"s\n" $users_seconds | datamash mean 1
) | $(printf %"s\n" $users_seconds | datamash median 1) |
printf %"s\n" "$users_seconds" | datamash mean 1
) | $(printf %"s\n" "$users_seconds" | datamash median 1) |
| system seconds | $(
printf %"s\n" $system_seconds | datamash max 1
printf %"s\n" "$system_seconds" | datamash max 1
) | $(
printf %"s\n" $system_seconds | datamash min 1
printf %"s\n" "$system_seconds" | datamash min 1
) | $(
printf %"s\n" $system_seconds | datamash mean 1
) | $(printf %"s\n" $system_seconds | datamash median 1) |
printf %"s\n" "$system_seconds" | datamash mean 1
) | $(printf %"s\n" "$system_seconds" | datamash median 1) |
| CPU % | $(
printf %"s\n" $cpu | datamash max 1
printf %"s\n" "$cpu" | datamash max 1
) | $(
printf %"s\n" $cpu | datamash min 1
printf %"s\n" "$cpu" | datamash min 1
) | $(
printf %"s\n" $cpu | datamash mean 1
) | $(printf %"s\n" $cpu | datamash median 1) |
printf %"s\n" "$cpu" | datamash mean 1
) | $(printf %"s\n" "$cpu" | datamash median 1) |
| Total time | $(
printf %"s\n" $total_time | datamash max 1
printf %"s\n" "$total_time" | datamash max 1
) | $(
printf %"s\n" $total_time | datamash min 1
printf %"s\n" "$total_time" | datamash min 1
) | $(
printf %"s\n" $total_time | datamash mean 1
) | $(printf %"s\n" $total_time | datamash median 1) |
printf %"s\n" "$total_time" | datamash mean 1
) | $(printf %"s\n" "$total_time" | datamash median 1) |
"
}

Expand All @@ -82,8 +82,7 @@ function save_result {

local FILE_NAME=${5:-"tests_result.md"}

echo -e "\n$DESCRIPTION" >> "tests/results/$FILE_NAME"
echo -e "$TABLE" >> "tests/results/$FILE_NAME"
echo -e "\n$DESCRIPTION\n$TABLE" >> "tests/results/$FILE_NAME"
# shellcheck disable=SC2016,SC2128 # Irrelevant
echo -e '
<details><summary>Run details</summary>
Expand Down