Skip to content

Commit

Permalink
fix: avoid setting DELETE_AT_EXIT twice and set parallel --will-cite
Browse files Browse the repository at this point in the history
Fixes #2618

- Check if `DELETE_AT_EXIT` is set in `setup_trap_handler()` before
  trying to set it, to avoid `DELETE_AT_EXIT: readonly variable` error
- Set the `--will-cite` flag for parallel - in some cases, I've seen the
  citation warning
- Add swp to list of file extensions to ignore (for vim)
- Small shellcheck fixes (not exhaustive)
  • Loading branch information
wyardley committed Sep 25, 2024
1 parent a9c4772 commit 16ff54f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions infra/build/developer-tools/build/scripts/task_helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# setup_trap_handler() and used by maketemp()
finish() {
if [[ -n "${DELETE_AT_EXIT:-}" ]]; then
rm -rf "${DELETE_AT_EXIT}"
rm -rf "$DELETE_AT_EXIT"
fi
}

Expand All @@ -27,7 +27,9 @@ finish() {
# for use with maketemp() to automatically clean up temporary files, especially
# those used to store credentials.
setup_trap_handler() {
readonly DELETE_AT_EXIT="$(mktemp -d)"
if [[ -z "${DELETE_AT_EXIT+x}" ]]; then
readonly DELETE_AT_EXIT="$(mktemp -d)"
fi
trap finish EXIT
}

Expand Down Expand Up @@ -152,8 +154,8 @@ function lint_docker() {

# This function creates TF_PLUGIN_CACHE_DIR if TF_PLUGIN_CACHE_DIR envvar is set
function init_tf_plugin_cache() {
if [[ ! -z "${TF_PLUGIN_CACHE_DIR}" ]]; then
mkdir -p ${TF_PLUGIN_CACHE_DIR}
if [[ -n "$TF_PLUGIN_CACHE_DIR" ]]; then
mkdir -p "$TF_PLUGIN_CACHE_DIR"
fi
}

Expand Down Expand Up @@ -191,7 +193,7 @@ function check_terraform() {
| grep -v 'test/fixtures/shared' \
| compat_xargs -n1 dirname \
| sort -u \
| parallel --keep-order --retries 3 --joblog /tmp/lint_log terraform_validate
| parallel --will-cite --keep-order --retries 3 --joblog /tmp/lint_log terraform_validate
cat /tmp/lint_log
else
find_files . -name "*.tf" -print \
Expand Down Expand Up @@ -237,7 +239,7 @@ check_whitespace() {
local rc
echo "Checking for trailing whitespace"
find_files . -print \
| grep -v -E '\.(pyc|png|gz|tfvars|mp4|zip|ico|jar|parquet|pb|index)$' \
| grep -v -E '\.(pyc|png|gz|swp|tfvars|mp4|zip|ico|jar|parquet|pb|index)$' \
| compat_xargs grep -H -n '[[:blank:]]$'
rc=$?
if [[ ${rc} -eq 0 ]]; then
Expand Down Expand Up @@ -519,9 +521,9 @@ function fix_headers() {
YEAR=$(date +'%Y')
if [ $# -eq 0 ]
then
find_files . for_header_check -type f -print0 | compat_xargs -0 addlicense -y $YEAR
find_files . for_header_check -type f -print0 | compat_xargs -0 addlicense -y "$YEAR"
else
addlicense -y $YEAR "$@"
addlicense -y "$YEAR" "$@"
fi
}

Expand Down

0 comments on commit 16ff54f

Please sign in to comment.