mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
chore: Add shellcheck and make checks passing (#315)
Co-authored-by: Anton Babenko <anton@antonbabenko.com>
This commit is contained in:
parent
645f3fd126
commit
3045dd55a3
5 changed files with 34 additions and 24 deletions
4
.github/workflows/pre-commit.yaml
vendored
4
.github/workflows/pre-commit.yaml
vendored
|
|
@ -21,6 +21,10 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
curl -L "$(curl -s https://api.github.com/repos/mvdan/sh/releases/latest | grep -o -E -m 1 "https://.+?linux_amd64")" > shfmt \
|
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/
|
&& 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
|
# Need to success pre-commit fix push
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,4 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: shfmt
|
- id: shfmt
|
||||||
args: ['-l', '-i', '2', '-ci', '-sr', '-w']
|
args: ['-l', '-i', '2', '-ci', '-sr', '-w']
|
||||||
|
- id: shellcheck
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ function common::parse_cmdline {
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
|
# shellcheck disable=SC2034 # Common function
|
||||||
FILES=("$@")
|
FILES=("$@")
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
|
|
@ -101,6 +102,7 @@ function infracost_breakdown_ {
|
||||||
# $hook_config receives string like '1 > 2; 3 == 4;' etc.
|
# $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')
|
# 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.
|
# Next line removes leading spaces, just for fancy output reason.
|
||||||
|
# shellcheck disable=SC2001 # Rule exception
|
||||||
check=$(echo "$check" | sed 's/^[[:space:]]*//')
|
check=$(echo "$check" | sed 's/^[[:space:]]*//')
|
||||||
|
|
||||||
# Drop quotes in hook args section. From:
|
# Drop quotes in hook args section. From:
|
||||||
|
|
@ -116,7 +118,7 @@ function infracost_breakdown_ {
|
||||||
}; then
|
}; then
|
||||||
check="${check:1:-1}"
|
check="${check:1:-1}"
|
||||||
fi
|
fi
|
||||||
|
# shellcheck disable=SC2207 # Can't find working `read` command
|
||||||
operations=($(echo "$check" | grep -oE '[!<>=]{1,2}'))
|
operations=($(echo "$check" | grep -oE '[!<>=]{1,2}'))
|
||||||
# Get the very last operator, that is used in comparison inside `jq` query.
|
# 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`,
|
# From the example below we need to pick the `>` which is in between `add` and `1000`,
|
||||||
|
|
|
||||||
|
|
@ -121,9 +121,11 @@ function terraform_docs {
|
||||||
local add_to_existing=false
|
local add_to_existing=false
|
||||||
local create_if_not_exist=false
|
local create_if_not_exist=false
|
||||||
|
|
||||||
configs=($hook_config)
|
read -r -a configs <<< "$hook_config"
|
||||||
|
|
||||||
for c in "${configs[@]}"; do
|
for c in "${configs[@]}"; do
|
||||||
config=(${c//=/ })
|
|
||||||
|
IFS="=" read -r -a config <<< "$c"
|
||||||
key=${config[0]}
|
key=${config[0]}
|
||||||
value=${config[1]}
|
value=${config[1]}
|
||||||
|
|
||||||
|
|
@ -161,9 +163,11 @@ function terraform_docs {
|
||||||
dir="$(dirname "$text_file")"
|
dir="$(dirname "$text_file")"
|
||||||
|
|
||||||
mkdir -p "$dir"
|
mkdir -p "$dir"
|
||||||
echo -e "# ${PWD##*/}\n" >> "$text_file"
|
{
|
||||||
echo "<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" >> "$text_file"
|
echo -e "# ${PWD##*/}\n"
|
||||||
echo "<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" >> "$text_file"
|
echo "<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->"
|
||||||
|
echo "<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->"
|
||||||
|
} >> "$text_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If file still not exist - skip dir
|
# If file still not exist - skip dir
|
||||||
|
|
|
||||||
|
|
@ -44,33 +44,33 @@ function generate_table {
|
||||||
| time command | max | min | mean | median |
|
| time command | max | min | mean | median |
|
||||||
| -------------- | ------ | ------ | -------- | ------ |
|
| -------------- | ------ | ------ | -------- | ------ |
|
||||||
| users seconds | $(
|
| 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 mean 1
|
||||||
) | $(printf %"s\n" $users_seconds | datamash median 1) |
|
) | $(printf %"s\n" "$users_seconds" | datamash median 1) |
|
||||||
| system seconds | $(
|
| 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 mean 1
|
||||||
) | $(printf %"s\n" $system_seconds | datamash median 1) |
|
) | $(printf %"s\n" "$system_seconds" | datamash median 1) |
|
||||||
| CPU % | $(
|
| 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 mean 1
|
||||||
) | $(printf %"s\n" $cpu | datamash median 1) |
|
) | $(printf %"s\n" "$cpu" | datamash median 1) |
|
||||||
| Total time | $(
|
| 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 mean 1
|
||||||
) | $(printf %"s\n" $total_time | datamash median 1) |
|
) | $(printf %"s\n" "$total_time" | datamash median 1) |
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,8 +82,7 @@ function save_result {
|
||||||
|
|
||||||
local FILE_NAME=${5:-"tests_result.md"}
|
local FILE_NAME=${5:-"tests_result.md"}
|
||||||
|
|
||||||
echo -e "\n$DESCRIPTION" >> "tests/results/$FILE_NAME"
|
echo -e "\n$DESCRIPTION\n$TABLE" >> "tests/results/$FILE_NAME"
|
||||||
echo -e "$TABLE" >> "tests/results/$FILE_NAME"
|
|
||||||
# shellcheck disable=SC2016,SC2128 # Irrelevant
|
# shellcheck disable=SC2016,SC2128 # Irrelevant
|
||||||
echo -e '
|
echo -e '
|
||||||
<details><summary>Run details</summary>
|
<details><summary>Run details</summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue