Skip to content

Commit

Permalink
Refactor: replace mapfile with while loop for file list population in…
Browse files Browse the repository at this point in the history
… validation scripts (#5)

* patch: update pre-commit hook stages for flux validation script

* refactor: replace mapfile with while loop for file list population in validation scripts

* fix: update pre-commit hook stages for eslint and sample file generation scripts
  • Loading branch information
thamudi authored Jan 7, 2025
1 parent 4ab2077 commit dd78ea8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
description: "A script to validate eslint rules on Javascript and Typescript files."
entry: ./scripts/validate-eslint.sh
language: script
stages: [commit]
stages: ["pre-commit"]
- id: run-samplr
name: generate sample .env files
description: "A script to generate sample files."
entry: ./scripts/samplr/run-samplr.sh
language: script
stages: [commit]
stages: ["pre-commit"]
20 changes: 17 additions & 3 deletions scripts/validate-flux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ print_summary() {
# validate_files

validate_files() {
mapfile -t fileList < <(get_git_diff_files "./" ".*\.ya\?ml$")
fileList=()
while IFS= read -r file; do
fileList+=("$file")
done < <(get_git_diff_files "./" ".*\.ya\?ml$")

if [ ${#fileList[@]} -eq 0 ]; then
echo "No files to validate"
exit 0
Expand Down Expand Up @@ -257,7 +261,12 @@ validate_clusters() {

echo -n "VALIDATING CLUSTERS ..."
[[ $DEBUG -eq 1 ]] && echo -e "\n${CYAN}INFO${NC} - Validating clusters"
mapfile -t clusterList < <(get_git_diff_files "./clusters" ".*\.ya\?ml$")

clusterList=()
while IFS= read -r file; do
clusterList+=("$file")
done < <(get_git_diff_files "./clusters" ".*\.ya\?ml$")

for file in "${clusterList[@]}"; do
local failed_checks
[[ $DEBUG -eq 1 ]] && echo -e "${CYAN}INFO${NC} - Validating ${file}"
Expand Down Expand Up @@ -290,7 +299,12 @@ validate_clusters() {
validate_kustomize() {
echo -n "VALIDATING KUSTOMIZE ..."
[[ $DEBUG -eq 1 ]] && echo -e "\n${CYAN}INFO${NC} - Validating kustomize overlays"
mapfile -t kustomizeList < <(get_git_diff_files "./" "$kustomize_config")

kustomizeList=()
while IFS= read -r file; do
kustomizeList+=("$file")
done < <(get_git_diff_files "./" "$kustomize_config")

for file in "${kustomizeList[@]}"; do
local failed_checks=0
if [[ "$file" == *"$kustomize_config" ]]; then
Expand Down

0 comments on commit dd78ea8

Please sign in to comment.