From de569e0af3fcacb3fb9edb6f1ccc2aa07cbde1b8 Mon Sep 17 00:00:00 2001 From: Christian Schroer <1319445+cschroer@users.noreply.github.com> Date: Thu, 29 Aug 2024 09:03:05 +0200 Subject: [PATCH 1/2] fix(terraform_docs): Always use GNU sed Ensure sed commands are compatible with MacOS and Linux/GNO version --- README.md | 4 ++-- hooks/terraform_docs.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4c69a1b46..aa77e89b8 100644 --- a/README.md +++ b/README.md @@ -585,8 +585,8 @@ Unlike most other hooks, this hook triggers once if there are any changed files To migrate everything to `terraform-docs` insertion markers, run in repo root: ```bash - grep -rl 'BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs sed -i 's/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/BEGIN_TF_DOCS/g' - grep -rl 'END OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs sed -i 's/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/END_TF_DOCS/g' + grep -rl 'BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs sed -i'' 's/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/BEGIN_TF_DOCS/g' + grep -rl 'END OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs sed -i'' 's/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/END_TF_DOCS/g' ``` ```yaml diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 0a3dbc298..694476eb5 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -40,8 +40,8 @@ function main { function replace_old_markers { local -r file=$1 - sed -i "s/^${old_insertion_marker_begin}$/${insertion_marker_begin}/" "$file" - sed -i "s/^${old_insertion_marker_end}$/${insertion_marker_end}/" "$file" + sed -i'' "s/^${old_insertion_marker_begin}$/${insertion_marker_begin}/" "$file" + sed -i'' "s/^${old_insertion_marker_end}$/${insertion_marker_end}/" "$file" } ####################################################################### From c5c6dcbad81c931b8bd99575778bb33060747d6a Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Thu, 29 Aug 2024 19:55:23 +0300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: George L. Yermulnik --- README.md | 4 ++-- hooks/terraform_docs.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aa77e89b8..0b262520b 100644 --- a/README.md +++ b/README.md @@ -585,8 +585,8 @@ Unlike most other hooks, this hook triggers once if there are any changed files To migrate everything to `terraform-docs` insertion markers, run in repo root: ```bash - grep -rl 'BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs sed -i'' 's/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/BEGIN_TF_DOCS/g' - grep -rl 'END OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs sed -i'' 's/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/END_TF_DOCS/g' + grep -rl --null 'BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs -0 sed -i'' -e 's/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/BEGIN_TF_DOCS/' + grep -rl --null 'END OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs -0 sed -i'' -e 's/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/END_TF_DOCS/' ``` ```yaml diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 694476eb5..0b532ce11 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -40,8 +40,8 @@ function main { function replace_old_markers { local -r file=$1 - sed -i'' "s/^${old_insertion_marker_begin}$/${insertion_marker_begin}/" "$file" - sed -i'' "s/^${old_insertion_marker_end}$/${insertion_marker_end}/" "$file" + sed -i'' -e "s/^${old_insertion_marker_begin}$/${insertion_marker_begin}/" "$file" + sed -i'' -e "s/^${old_insertion_marker_end}$/${insertion_marker_end}/" "$file" } #######################################################################