mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-26 16:09:45 -05:00
c1f9d86cd3
* explicitly ignore pkgs for cleaner output * do not ignore but redirect stderr * silent env var to silent stderr * add silent env var to vuln,lint,tf * fix golangci silent * Update bazel/ci/terraform.sh.in Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com> * Update bazel/ci/golicenses.sh.in Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com> * Update bazel/ci/govulncheck.sh.in Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com> * Update bazel/ci/golangci_lint.sh.in Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com> --------- Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com>
105 lines
2.8 KiB
Bash
105 lines
2.8 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
###### script header ######
|
|
|
|
lib=$(realpath @@BASE_LIB@@) || exit 1
|
|
stat "${lib}" >> /dev/null || exit 1
|
|
|
|
# shellcheck source=../sh/lib.bash
|
|
if ! source "${lib}"; then
|
|
echo "Error: could not find import"
|
|
exit 1
|
|
fi
|
|
|
|
terraform=$(realpath @@TERRAFORM@@)
|
|
stat "${terraform}" >> /dev/null
|
|
mode="@@MODE@@"
|
|
|
|
cd "${BUILD_WORKSPACE_DIRECTORY}"
|
|
|
|
###### script body ######
|
|
|
|
readarray -t <<< "$(
|
|
find "$(pwd)" -type f -name "*.tf" -exec dirname "{}" \; |
|
|
sort -ud
|
|
)"
|
|
terraformPaths=("${MAPFILE[@]}")
|
|
terraformModules=()
|
|
pathPrefix="${terraformPaths[0]}"
|
|
for ((i = 1; i < ${#terraformPaths[@]}; i++)); do
|
|
path="${terraformPaths[i]}"
|
|
if [[ ${path} == "${pathPrefix}"* ]]; then
|
|
continue
|
|
fi
|
|
terraformModules+=("${pathPrefix}")
|
|
pathPrefix="${path}"
|
|
done
|
|
|
|
excludeDirs=(
|
|
"build"
|
|
)
|
|
|
|
check() {
|
|
echo "The following Terraform modules are excluded and won't be tidied:"
|
|
for exclude in "${excludeDirs[@]}"; do
|
|
for i in "${!terraformModules[@]}"; do
|
|
if [[ ${terraformModules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}"* ]]; then
|
|
echo " ${terraformModules[i]}"
|
|
unset 'terraformModules[i]'
|
|
fi
|
|
done
|
|
done
|
|
|
|
case ${mode} in
|
|
"check")
|
|
echo "Checking validity and format of the following Terraform modules:"
|
|
for script in "${terraformModules[@]}"; do
|
|
echo " ${script}"
|
|
done
|
|
echo "This may take a minute..."
|
|
for module in "${terraformModules[@]}"; do
|
|
${terraform} -chdir="${module}" init > /dev/null
|
|
${terraform} -chdir="${module}" fmt -check -recursive > /dev/null
|
|
${terraform} -chdir="${module}" validate > /dev/null
|
|
rm -rf "${module}/.terraform"
|
|
done
|
|
;;
|
|
|
|
"format")
|
|
echo "Formatting the following Terraform modules:"
|
|
for module in "${terraformModules[@]}"; do
|
|
echo " ${module}"
|
|
${terraform} -chdir="${module}" fmt -recursive > /dev/null
|
|
done
|
|
;;
|
|
|
|
"generate")
|
|
echo "Formatting and generating lock files for the following Terraform modules:"
|
|
for script in "${terraformModules[@]}"; do
|
|
echo " ${script}"
|
|
done
|
|
echo "This may take 5-10 min..."
|
|
for module in "${terraformModules[@]}"; do
|
|
${terraform} -chdir="${module}" init > /dev/null
|
|
${terraform} -chdir="${module}" providers lock -platform=linux_arm64 > /dev/null
|
|
${terraform} -chdir="${module}" providers lock -platform=linux_amd64 > /dev/null
|
|
${terraform} -chdir="${module}" providers lock -platform=darwin_arm64 > /dev/null
|
|
${terraform} -chdir="${module}" providers lock -platform=darwin_amd64 > /dev/null
|
|
${terraform} -chdir="${module}" providers lock -platform=windows_amd64 > /dev/null
|
|
rm -rf "${module}/.terraform"
|
|
done
|
|
;;
|
|
|
|
*)
|
|
echo "Error: unknown mode \"${mode}\""
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
if test -v SILENT; then
|
|
check > /dev/null
|
|
else
|
|
check
|
|
fi
|