@@ -25,22 +25,22 @@ function compare_cr {
2525 local exclusionfile=$3
2626 local status=0
2727
28- read_dir " $rendered_dir " | grep yaml > rendered_file
29- read_dir " $source_dir " | grep yaml > source_file
28+ read_dir " $rendered_dir " | grep yaml > rendered_file
29+ read_dir " $source_dir " | grep yaml > source_file
3030
3131 local source_cr rendered
3232 while IFS= read -r source_cr; do
3333 while IFS= read -r rendered; do
3434 if [ " ${source_cr##*/ } " = " ${rendered##*/ } " ]; then
35- echo " $source_cr " >> same_file
35+ echo " $source_cr " >> same_file
3636 fi
37- done < rendered_file
38- done < source_file
37+ done < rendered_file
38+ done < source_file
3939
4040 # Filter out files with a source-cr/reference match from the full list of potentiol source-crs/reference files
4141 while IFS= read -r file; do
4242 [[ ${file:: 1} != " #" ]] || continue # Skip any comment lines in the exclusionfile
43- [[ -n ${file} ]] || continue # Skip empty lines
43+ [[ -n ${file} ]] || continue # Skip empty lines
4444 sed -i " /${file##*/ } /d" source_file
4545 sed -i " /${file##*/ } /d" rendered_file
4646 done < <( cat same_file " $exclusionfile " )
@@ -55,103 +55,103 @@ function compare_cr {
5555}
5656
5757sync_cr () {
58- local rendered_dir=$1
59- local source_dir=$2
60- local exclusionfile=$3
61- local status=0
58+ local rendered_dir=$1
59+ local source_dir=$2
60+ local exclusionfile=$3
61+ local status=0
6262
63- local -a renderedFiles
64- readarray -t renderedFiles < <( read_dir " $rendered_dir " | grep yaml)
63+ local -a renderedFiles
64+ readarray -t renderedFiles < <( read_dir " $rendered_dir " | grep yaml)
6565
66- local -a sourceFiles
67- readarray -t sourceFiles < <( read_dir " $source_dir " | grep yaml)
66+ local -a sourceFiles
67+ readarray -t sourceFiles < <( read_dir " $source_dir " | grep yaml)
6868
69- local -a excludedFiles
70- readarray -t excludedFiles < <( grep -v ' ^#' " $exclusionfile " | grep -v ' ^$' )
69+ local -a excludedFiles
70+ readarray -t excludedFiles < <( grep -v ' ^#' " $exclusionfile " | grep -v ' ^$' )
7171
72- local source rendered excluded found
73- for rendered in " ${renderedFiles[@]} " ; do
74- found=0
75- for source in " ${sourceFiles[@]} " ; do
76- if [ " ${source##*/ } " = " ${rendered##*/ } " ]; then
77- # Match found!
78- found=1
79- break
80- fi
81- done
82- if [[ $found == 0 ]]; then
83- source=" $source_dir /${rendered##*/ } "
84- fi
85-
86- # Replace the CR with the rendered copy (minus the helm-rendered heading)
87- tail -n +3 " $rendered " > " $source "
88- git add " $source "
72+ local source rendered excluded found
73+ for rendered in " ${renderedFiles[@]} " ; do
74+ found=0
75+ for source in " ${sourceFiles[@]} " ; do
76+ if [ " ${source##*/ } " = " ${rendered##*/ } " ]; then
77+ # Match found!
78+ found=1
79+ break
80+ fi
8981 done
82+ if [[ $found == 0 ]]; then
83+ source=" $source_dir /${rendered##*/ } "
84+ fi
9085
91- for source in " ${sourceFiles[@]} " ; do
92- found=0
93- for rendered in " ${renderedFiles[@]} " ; do
94- if [ " ${source##*/ } " = " ${rendered##*/ } " ]; then
95- # Match found!
96- found=1
97- break
98- fi
99- done
100- for excluded in " ${excludedFiles[@]} " ; do
101- if [ " ${source##*/ } " = " ${excluded##*/ } " ]; then
102- # Match found!
103- found=1
104- break
105- fi
106- done
107- if [[ $found == 0 ]]; then
108- git rm -f " $source "
109- fi
86+ # Replace the CR with the rendered copy (minus the helm-rendered heading)
87+ tail -n +3 " $rendered " > " $source "
88+ git add " $source "
89+ done
90+
91+ for source in " ${sourceFiles[@]} " ; do
92+ found=0
93+ for rendered in " ${renderedFiles[@]} " ; do
94+ if [ " ${source##*/ } " = " ${rendered##*/ } " ]; then
95+ # Match found!
96+ found=1
97+ break
98+ fi
11099 done
100+ for excluded in " ${excludedFiles[@]} " ; do
101+ if [ " ${source##*/ } " = " ${excluded##*/ } " ]; then
102+ # Match found!
103+ found=1
104+ break
105+ fi
106+ done
107+ if [[ $found == 0 ]]; then
108+ git rm -f " $source "
109+ fi
110+ done
111111
112- git diff --cached --stat --exit-code
112+ git diff --cached --stat --exit-code
113113}
114114
115115usage () {
116- echo " $( basename " $0 " ) [--sync] sourceDir renderDir"
117- echo
118- echo " Compares the rendered reference-based CRs to the CRs in the compare directory"
116+ echo " $( basename " $0 " ) [--sync] sourceDir renderDir"
117+ echo
118+ echo " Compares the rendered reference-based CRs to the CRs in the compare directory"
119119}
120120
121121DOSYNC=0
122122for arg in " $@ " ; do
123- case " $arg " in
124- -h | --help)
125- usage
126- exit 0
127- ;;
128- --sync)
129- DOSYNC=1
130- shift
131- ;;
132- esac
123+ case " $arg " in
124+ -h | --help)
125+ usage
126+ exit 0
127+ ;;
128+ --sync)
129+ DOSYNC=1
130+ shift
131+ ;;
132+ esac
133133done
134134SOURCEDIR=$1
135135if [[ ! -d $SOURCEDIR ]]; then
136- echo " No such source directory $SOURCEDIR "
137- usage
138- exit 1
136+ echo " No such source directory $SOURCEDIR "
137+ usage
138+ exit 1
139139fi
140140RENDERDIR=$2
141141if [[ ! -d $RENDERDIR ]]; then
142- echo " No such source directory $RENDERDIR "
143- usage
144- exit 1
142+ echo " No such source directory $RENDERDIR "
143+ usage
144+ exit 1
145145fi
146146IGNORE=$3
147147if [[ ! -f $IGNORE ]]; then
148- echo " No such ignorefile $IGNORE "
149- usage
150- exit 1
148+ echo " No such ignorefile $IGNORE "
149+ usage
150+ exit 1
151151fi
152152
153153if [[ $DOSYNC == 1 ]]; then
154- sync_cr " $RENDERDIR " " $SOURCEDIR " " $IGNORE "
154+ sync_cr " $RENDERDIR " " $SOURCEDIR " " $IGNORE "
155155else
156- compare_cr " $RENDERDIR " " $SOURCEDIR " " $IGNORE "
156+ compare_cr " $RENDERDIR " " $SOURCEDIR " " $IGNORE "
157157fi
0 commit comments