forked from super-linter/super-linter
/
buildFileList.sh
executable file
·868 lines (778 loc) · 31.6 KB
/
buildFileList.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
#!/usr/bin/env bash
################################################################################
################################################################################
########### Super-Linter Build File List Functions @admiralawkbar ##############
################################################################################
################################################################################
########################## FUNCTION CALLS BELOW ################################
################################################################################
################################################################################
#### Function GenerateFileDiff #################################################
function GenerateFileDiff() {
CMD="${1}"
################
# print header #
################
debug "----------------------------------------------"
debug "Generating Diff with:[$CMD]"
#################################################
# Get the Array of files changed in the commits #
#################################################
CMD_OUTPUT=$(eval "$CMD")
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Error
info "Failed to get Diff with:[$CMD]"
info "Check that you have the full git history, the checkout is not shallow, etc"
info "See https://github.com/github/super-linter#example-connecting-github-action-workflow"
fatal "[${CMD_OUTPUT}]"
fi
###################################################
# Map command output to an array to proper handle #
###################################################
mapfile -t RAW_FILE_ARRAY < <(echo -n "$CMD_OUTPUT")
debug "RAW_FILE_ARRAY contents: ${RAW_FILE_ARRAY[*]}"
}
################################################################################
#### Function BuildFileList ####################################################
function BuildFileList() {
debug "Building file list..."
################
# Pull in vars #
################
VALIDATE_ALL_CODEBASE="${1}"
debug "VALIDATE_ALL_CODEBASE: ${VALIDATE_ALL_CODEBASE}"
TEST_CASE_RUN="${2}"
debug "TEST_CASE_RUN: ${TEST_CASE_RUN}"
ANSIBLE_DIRECTORY="${3}"
debug "ANSIBLE_DIRECTORY: ${ANSIBLE_DIRECTORY}"
debug "IGNORE_GITIGNORED_FILES: ${IGNORE_GITIGNORED_FILES}"
debug "IGNORE_GENERATED_FILES: ${IGNORE_GENERATED_FILES}"
debug "USE_FIND_ALGORITHM: ${USE_FIND_ALGORITHM}"
debug "VALIDATE_JSCPD_ALL_CODEBASE: ${VALIDATE_JSCPD_ALL_CODEBASE}"
# Solve issue with git unsafe dirs
debug "Running git config for safe dirs"
git config --global --add safe.directory "${GITHUB_WORKSPACE}" 2>&1
git config --global --add safe.directory "/tmp/lint" 2>&1
if [ "${VALIDATE_ALL_CODEBASE}" == "false" ] && [ "${TEST_CASE_RUN}" != "true" ]; then
# Need to build a list of all files changed
# This can be pulled from the GITHUB_EVENT_PATH payload
################
# print header #
################
debug "----------------------------------------------"
debug "Pulling in code history and branches..."
#################################################################################
# Switch codebase back to the default branch to get a list of all files changed #
#################################################################################
SWITCH_CMD=$(
git -C "${GITHUB_WORKSPACE}" pull --quiet
git -C "${GITHUB_WORKSPACE}" checkout "${DEFAULT_BRANCH}" 2>&1
)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ] && [ "${LOCAL_UPDATDES}" == "false" ]; then
# Error
info "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!"
fatal "[${SWITCH_CMD}]"
fi
if [ "${GITHUB_EVENT_NAME}" == "push" ]; then
################
# push event #
################
DIFF_TREE_CMD="git -C ${GITHUB_WORKSPACE} diff-tree --no-commit-id --name-only -r ${GITHUB_SHA} | xargs -I % sh -c 'echo \"${GITHUB_WORKSPACE}/%\"' 2>&1"
GenerateFileDiff "$DIFF_TREE_CMD"
###############################################################
# Need to see if the array is empty, if so, try the other way #
###############################################################
if [ ${#RAW_FILE_ARRAY[@]} -eq 0 ]; then
# Empty array, going to try to pull from main branch differences
################
# print header #
################
debug "----------------------------------------------"
debug "WARN: Generation of File array with diff-tree produced [0] items, trying with git diff..."
DIFF_CMD="git -C ${GITHUB_WORKSPACE} diff --name-only ${DEFAULT_BRANCH}...${GITHUB_SHA} --diff-filter=d | xargs -I % sh -c 'echo \"${GITHUB_WORKSPACE}/%\"' 2>&1"
GenerateFileDiff "$DIFF_CMD"
fi
else
################
# PR event #
################
DIFF_CMD="git -C ${GITHUB_WORKSPACE} diff --name-only ${DEFAULT_BRANCH}...${GITHUB_SHA} --diff-filter=d | xargs -I % sh -c 'echo \"${GITHUB_WORKSPACE}/%\"' 2>&1"
GenerateFileDiff "$DIFF_CMD"
fi
else
WORKSPACE_PATH="${GITHUB_WORKSPACE}"
if [ "${TEST_CASE_RUN}" == "true" ]; then
WORKSPACE_PATH="${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}"
fi
#############################
# Use the find on all files #
#############################
if [ "${USE_FIND_ALGORITHM}" == 'true' ]; then
################
# print header #
################
debug "----------------------------------------------"
debug "Populating the file list with all the files in the ${WORKSPACE_PATH} workspace using FIND algorithm"
mapfile -t RAW_FILE_ARRAY < <(find "${WORKSPACE_PATH}" \
-not \( -path '*/\.git' -prune \) \
-not \( -path '*/\.pytest_cache' -prune \) \
-not \( -path '*/\.rbenv' -prune \) \
-not \( -path '*/\.terragrunt-cache' -prune \) \
-not \( -path '*/\.venv' -prune \) \
-not \( -path '*/\__pycache__' -prune \) \
-not \( -path '*/\node_modules' -prune \) \
-not -name ".DS_Store" \
-not -name "*.gif" \
-not -name "*.ico" \
-not -name "*.jpg" \
-not -name "*.jpeg" \
-not -name "*.pdf" \
-not -name "*.png" \
-not -name "*.webp" \
-not -name "*.woff" \
-not -name "*.woff2" \
-not -name "*.zip" \
-type f \
2>&1 | sort)
else
##############################
# use the standard mechinism #
##############################
################
# print header #
################
debug "----------------------------------------------"
debug "Populating the file list with:[git -C \"${WORKSPACE_PATH}\" ls-tree -r --name-only HEAD | xargs -I % sh -c \"echo ${WORKSPACE_PATH}/%\"]"
mapfile -t RAW_FILE_ARRAY < <(git -C "${WORKSPACE_PATH}" ls-tree -r --name-only HEAD | xargs -I % sh -c "echo ${WORKSPACE_PATH}/%" 2>&1)
debug "RAW_FILE_ARRAY contents: ${RAW_FILE_ARRAY[*]}"
fi
fi
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
fatal "Failed to gain a list of all files changed! Error code: ${ERROR_CODE}"
fi
##########################################################################
# Check to make sure the raw file array is not empty or throw a warning! #
##########################################################################
if [ ${#RAW_FILE_ARRAY[@]} -eq 0 ]; then
###############################
# No files were found to lint #
###############################
warn "No files were found in the GITHUB_WORKSPACE:[${GITHUB_WORKSPACE}] to lint!"
fi
if [ "${VALIDATE_ALL_CODEBASE}" == "false" ]; then
#########################################
# Need to switch back to branch of code #
#########################################
SWITCH2_CMD=$(git -C "${GITHUB_WORKSPACE}" checkout --progress --force "${GITHUB_SHA}" 2>&1)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Error
error "Failed to switch back to branch!"
fatal "[${SWITCH2_CMD}]"
fi
fi
###############################
# Load the ignored files list #
###############################
debug "Loading the files list that Git ignores..."
mapfile -t GIT_IGNORED_FILES < <(git -C "${GITHUB_WORKSPACE}" status --ignored --porcelain=v1 --short --untracked-files=normal | grep '!!' | awk -F ' ' '{print $2}' | sed -e 's#^#'"${GITHUB_WORKSPACE}"/'#' | sort)
debug "GIT_IGNORED_FILES contents: ${GIT_IGNORED_FILES[*]}"
# Build an associative array to avoid looping throug the ignored files list
local i
declare -g -A GIT_IGNORED_FILES_INDEX
for i in "${!GIT_IGNORED_FILES[@]}"; do
eval GIT_IGNORED_FILES_INDEX["${GIT_IGNORED_FILES[$i]}"]="$i"
done
debug "--- GIT_IGNORED_FILES_INDEX contents ---"
debug "-----------------------"
for i in "${!GIT_IGNORED_FILES_INDEX[@]}"; do
debug "key: $i, value: ${GIT_IGNORED_FILES_INDEX[$i]}"
done
debug "---------------------------------------------"
#########################################
# Check if the Ansible directory exists #
#########################################
if [ -d "${ANSIBLE_DIRECTORY}" ]; then
debug "Adding ANSIBLE_DIRECTORY (${ANSIBLE_DIRECTORY}) to the list of files and directories to lint."
FILE_ARRAY_ANSIBLE+=("${ANSIBLE_DIRECTORY}")
else
debug "ANSIBLE_DIRECTORY (${ANSIBLE_DIRECTORY}) does NOT exist."
fi
################################################
# Iterate through the array of all files found #
################################################
info "---------------------------------"
info "------ File list to check: ------"
info "---------------------------------"
for FILE in "${RAW_FILE_ARRAY[@]}"; do
# Extract just the file extension
FILE_TYPE="$(GetFileExtension "$FILE")"
# get the baseFile for additonal logic, lowercase
BASE_FILE=$(basename "${FILE,,}")
##############
# Print file #
##############
debug "File:[${FILE}], File_type:[${FILE_TYPE}], Base_file:[${BASE_FILE}]"
##########################################################
# Check if the file exists on the filesystem, or skip it #
##########################################################
if [ ! -f "${FILE}" ]; then
# File not found in workspace
warn "File:{$FILE} existed in commit data, but not found on file system, skipping..."
continue
fi
########################################################
# Don't include test cases if not running in test mode #
########################################################
if [[ ${FILE} == *"${TEST_CASE_FOLDER}"* ]] && [ "${TEST_CASE_RUN}" != "true" ]; then
debug "TEST_CASE_RUN (${TEST_CASE_RUN}) is not true. Skipping ${FILE}..."
continue
##################################################
# Include test cases if not running in test mode #
##################################################
elif [[ ${FILE} != *"${TEST_CASE_FOLDER}"* ]] && [ "${TEST_CASE_RUN}" == "true" ]; then
debug "TEST_CASE_RUN (${TEST_CASE_RUN}) is true. Skipping ${FILE}..."
fi
###############################################
# Filter files if FILTER_REGEX_INCLUDE is set #
###############################################
if [[ -n "$FILTER_REGEX_INCLUDE" ]] && [[ ! (${FILE} =~ $FILTER_REGEX_INCLUDE) ]]; then
debug "FILTER_REGEX_INCLUDE didn't match. Skipping ${FILE}"
continue
fi
###############################################
# Filter files if FILTER_REGEX_EXCLUDE is set #
###############################################
if [[ -n "$FILTER_REGEX_EXCLUDE" ]] && [[ ${FILE} =~ $FILTER_REGEX_EXCLUDE ]]; then
debug "FILTER_REGEX_EXCLUDE match. Skipping ${FILE}"
continue
fi
###################################################
# Filter files if FILTER_REGEX_EXCLUDE is not set #
###################################################
if [ "${GIT_IGNORED_FILES_INDEX[$FILE]}" ] && [ "${IGNORE_GITIGNORED_FILES}" == "true" ]; then
debug "${FILE} is ignored by Git. Skipping ${FILE}"
continue
fi
#########################################
# Filter files with at-generated marker #
#########################################
if [ "${IGNORE_GENERATED_FILES}" == "true" ] && IsGenerated "$FILE"; then
debug "${FILE} is generated. Skipping ${FILE}"
continue
fi
# Editorconfig-checker should check every file
FILE_ARRAY_EDITORCONFIG+=("${FILE}")
if [ "${VALIDATE_JSCPD_ALL_CODEBASE}" == "true" ]; then
debug "Not adding ${FILE} to FILE_ARRAY_JSCPD because we're going to lint the whole codebase anyway."
else
# jscpd also runs an all files
FILE_ARRAY_JSCPD+=("${FILE}")
fi
# Need to make sure we dont check the secrets paterns
# for secrets, as it will pop!
if [ "${BASE_FILE}" != ".gitleaks.toml" ]; then
# GitLeaks also runs an all files
FILE_ARRAY_GITLEAKS+=("${FILE}")
fi
#######################
# Get the shell files #
#######################
if IsValidShellScript "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_BASH+=("${FILE}")
FILE_ARRAY_BASH_EXEC+=("${FILE}")
FILE_ARRAY_SHELL_SHFMT+=("${FILE}")
#########################
# Get the CLOJURE files #
#########################
elif [ "${FILE_TYPE}" == "clj" ] || [ "${FILE_TYPE}" == "cljs" ] ||
[ "${FILE_TYPE}" == "cljc" ] || [ "${FILE_TYPE}" == "edn" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CLOJURE+=("${FILE}")
#####################
# Get the C++ files #
#####################
elif [ "${FILE_TYPE}" == "cpp" ] || [ "${FILE_TYPE}" == "h" ] ||
[ "${FILE_TYPE}" == "cc" ] || [ "${FILE_TYPE}" == "hpp" ] ||
[ "${FILE_TYPE}" == "cxx" ] || [ "${FILE_TYPE}" == "cu" ] ||
[ "${FILE_TYPE}" == "hxx" ] || [ "${FILE_TYPE}" == "c++" ] ||
[ "${FILE_TYPE}" == "hh" ] || [ "${FILE_TYPE}" == "h++" ] ||
[ "${FILE_TYPE}" == "cuh" ] || [ "${FILE_TYPE}" == "c" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CPP+=("${FILE}")
FILE_ARRAY_CLANG_FORMAT+=("${FILE}")
########################
# Get the COFFEE files #
########################
elif [ "${FILE_TYPE}" == "coffee" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_COFFEESCRIPT+=("${FILE}")
########################
# Get the CSHARP files #
########################
elif [ "${FILE_TYPE}" == "cs" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CSHARP+=("${FILE}")
#####################
# Get the CSS files #
#####################
elif [ "${FILE_TYPE}" == "css" ] || [ "${FILE_TYPE}" == "scss" ] ||
[ "${FILE_TYPE}" == "sass" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CSS+=("${FILE}")
######################
# Get the DART files #
######################
elif [ "${FILE_TYPE}" == "dart" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_DART+=("${FILE}")
########################
# Get the DOCKER files #
########################
# Use BASE_FILE here because FILE_TYPE is not reliable when there is no file extension
elif [[ "${FILE_TYPE}" != "tap" ]] && [[ "${FILE_TYPE}" != "yml" ]] &&
[[ "${FILE_TYPE}" != "yaml" ]] && [[ "${FILE_TYPE}" != "json" ]] && [[ "${FILE_TYPE}" != "xml" ]] && [[ "${BASE_FILE}" =~ .*(contain|dock)erfile.* ]]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_DOCKERFILE_HADOLINT+=("${FILE}")
#####################
# Get the ENV files #
#####################
elif [ "${FILE_TYPE}" == "env" ] || [[ "${BASE_FILE}" == *".env."* ]]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_ENV+=("${FILE}")
#########################
# Get the Gherkin files #
#########################
elif [ "${FILE_TYPE}" == "feature" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_GHERKIN+=("${FILE}")
########################
# Get the Golang files #
########################
elif [ "${FILE_TYPE}" == "go" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_GO+=("${FILE}")
########################
# Get the GROOVY files #
########################
elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ] ||
[ "$FILE_TYPE" == "gradle" ] || [ "$FILE_TYPE" == "nf" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_GROOVY+=("$FILE")
######################
# Get the HTML files #
######################
elif [ "${FILE_TYPE}" == "html" ]; then
################################
# Append the file to the array #
##############################p##
FILE_ARRAY_HTML+=("${FILE}")
######################
# Get the Java files #
######################
elif [ "${FILE_TYPE}" == "java" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_JAVA+=("${FILE}")
FILE_ARRAY_GOOGLE_JAVA_FORMAT+=("${FILE}")
############################
# Get the JavaScript files #
############################
elif [ "${FILE_TYPE}" == "js" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_JAVASCRIPT_ES+=("${FILE}")
FILE_ARRAY_JAVASCRIPT_STANDARD+=("${FILE}")
FILE_ARRAY_JAVASCRIPT_PRETTIER+=("${FILE}")
#######################
# Get the JSONC files #
#######################
elif [ "$FILE_TYPE" == "jsonc" ] || [ "$FILE_TYPE" == "json5" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_JSONC+=("${FILE}")
######################
# Get the JSON files #
######################
elif [ "${FILE_TYPE}" == "json" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_JSON+=("${FILE}")
############################
# Check if file is OpenAPI #
############################
if DetectOpenAPIFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_OPENAPI+=("${FILE}")
fi
########################
# Check if file is ARM #
########################
if DetectARMFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_ARM+=("${FILE}")
fi
#####################################
# Check if the file is CFN template #
#####################################
if DetectCloudFormationFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CLOUDFORMATION+=("${FILE}")
fi
############################################
# Check if the file is AWS States Language #
############################################
if DetectAWSStatesFIle "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_STATES+=("${FILE}")
fi
#####################
# Get the JSX files #
#####################
elif [ "${FILE_TYPE}" == "jsx" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_JSX+=("${FILE}")
########################
# Get the KOTLIN files #
########################
elif [ "${FILE_TYPE}" == "kt" ] || [ "${FILE_TYPE}" == "kts" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_KOTLIN+=("${FILE}")
FILE_ARRAY_KOTLIN_ANDROID+=("${FILE}")
#####################
# Get the LUA files #
#####################
elif [ "$FILE_TYPE" == "lua" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_LUA+=("$FILE")
#######################
# Get the LaTeX files #
#######################
elif [ "${FILE_TYPE}" == "tex" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_LATEX+=("${FILE}")
##########################
# Get the MARKDOWN files #
##########################
elif [ "${FILE_TYPE}" == "md" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_MARKDOWN+=("${FILE}")
FILE_ARRAY_NATURAL_LANGUAGE+=("${FILE}")
######################
# Get the PHP files #
######################
elif [ "${FILE_TYPE}" == "php" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PHP_BUILTIN+=("${FILE}")
FILE_ARRAY_PHP_PHPCS+=("${FILE}")
FILE_ARRAY_PHP_PHPSTAN+=("${FILE}")
FILE_ARRAY_PHP_PSALM+=("${FILE}")
######################
# Get the PERL files #
######################
elif [ "${FILE_TYPE}" == "pl" ] || [ "${FILE_TYPE}" == "pm" ] ||
[ "${FILE_TYPE}" == "t" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PERL+=("${FILE}")
############################
# Get the Powershell files #
############################
elif [ "${FILE_TYPE}" == "ps1" ] ||
[ "${FILE_TYPE}" == "psm1" ] ||
[ "${FILE_TYPE}" == "psd1" ] ||
[ "${FILE_TYPE}" == "ps1xml" ] ||
[ "${FILE_TYPE}" == "pssc" ] ||
[ "${FILE_TYPE}" == "psrc" ] ||
[ "${FILE_TYPE}" == "cdxml" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_POWERSHELL+=("${FILE}")
#################################
# Get the PROTOCOL BUFFER files #
#################################
elif [ "${FILE_TYPE}" == "proto" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PROTOBUF+=("${FILE}")
########################
# Get the PYTHON files #
########################
elif [ "${FILE_TYPE}" == "py" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PYTHON_BLACK+=("${FILE}")
FILE_ARRAY_PYTHON_FLAKE8+=("${FILE}")
FILE_ARRAY_PYTHON_ISORT+=("${FILE}")
FILE_ARRAY_PYTHON_PYLINT+=("${FILE}")
FILE_ARRAY_PYTHON_MYPY+=("${FILE}")
######################
# Get the RAKU files #
######################
elif [ "${FILE_TYPE}" == "raku" ] || [ "${FILE_TYPE}" == "rakumod" ] ||
[ "${FILE_TYPE}" == "rakutest" ] || [ "${FILE_TYPE}" == "pm6" ] ||
[ "${FILE_TYPE}" == "pl6" ] || [ "${FILE_TYPE}" == "p6" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_RAKU+=("${FILE}")
####################
# Get the R files #
####################
elif [ "${FILE_TYPE}" == "r" ] || [ "${FILE_TYPE}" == "rmd" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_R+=("${FILE}")
######################
# Get the RUBY files #
######################
elif [ "${FILE_TYPE}" == "rb" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_RUBY+=("${FILE}")
######################
# Get the RUST files #
######################
elif [ "${FILE_TYPE}" == "rs" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_RUST_2015+=("${FILE}")
FILE_ARRAY_RUST_2018+=("${FILE}")
FILE_ARRAY_RUST_2021+=("${FILE}")
#######################
# Get the RUST crates #
#######################
elif [ "${BASE_FILE}" == "cargo.toml" ]; then
###############################################
# Append the crate manifest file to the array #
###############################################
FILE_ARRAY_RUST_CLIPPY+=("${FILE}")
###########################
# Get the SCALA files #
###########################
elif [ "${FILE_TYPE}" == "scala" ] || [ "${FILE_TYPE}" == "sc" ] || [ "${BASE_FILE}" == "??????" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_SCALAFMT+=("${FILE}")
###########################
# Get the SNAKEMAKE files #
###########################
elif [ "${FILE_TYPE}" == "smk" ] || [ "${BASE_FILE}" == "snakefile" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_SNAKEMAKE_LINT+=("${FILE}")
FILE_ARRAY_SNAKEMAKE_SNAKEFMT+=("${FILE}")
#####################
# Get the SQL files #
#####################
elif [ "${FILE_TYPE}" == "sql" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_SQL+=("${FILE}")
FILE_ARRAY_SQLFLUFF+=("${FILE}")
###########################
# Get the Terraform files #
###########################
elif [ "${FILE_TYPE}" == "tf" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_TERRAFORM_TFLINT+=("${FILE}")
FILE_ARRAY_TERRAFORM_TERRASCAN+=("${FILE}")
############################
# Get the Terragrunt files #
############################
elif [ "${FILE_TYPE}" == "hcl" ] && [[ ${FILE} != *".tflint.hcl"* ]] && [[ ${FILE} != *".pkr.hcl"* ]]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_TERRAGRUNT+=("${FILE}")
############################
# Get the TypeScript files #
############################
elif [ "${FILE_TYPE}" == "ts" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_TYPESCRIPT_ES+=("${FILE}")
FILE_ARRAY_TYPESCRIPT_STANDARD+=("${FILE}")
FILE_ARRAY_TYPESCRIPT_PRETTIER+=("${FILE}")
#####################
# Get the TSX files #
#####################
elif [ "${FILE_TYPE}" == "tsx" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_TSX+=("${FILE}")
#####################
# Get the XML files #
#####################
elif [ "${FILE_TYPE}" == "xml" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_XML+=("${FILE}")
################################
# Get the CLOUDFORMATION files #
################################
elif [ "${FILE_TYPE}" == "yml" ] || [ "${FILE_TYPE}" == "yaml" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_YAML+=("${FILE}")
###################################
# Check if file is GitHub Actions #
###################################
if DetectActions "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_GITHUB_ACTIONS+=("${FILE}")
fi
#####################################
# Check if the file is CFN template #
#####################################
if DetectCloudFormationFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CLOUDFORMATION+=("${FILE}")
fi
############################
# Check if file is OpenAPI #
############################
if DetectOpenAPIFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_OPENAPI+=("${FILE}")
fi
########################################
# Check if the file is Tekton template #
########################################
if DetectTektonFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_TEKTON+=("${FILE}")
fi
############################################
# Check if the file is Kubernetes template #
############################################
if DetectKubernetesFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_KUBERNETES_KUBEVAL+=("${FILE}")
fi
########################################################################
# We have something that we need to try to check file type another way #
########################################################################
else
##############################################
# Use file to see if we can parse what it is #
##############################################
CheckFileType "${FILE}"
fi
##########################################
# Print line break after each file debug #
##########################################
debug ""
done
if [ "${VALIDATE_JSCPD_ALL_CODEBASE}" == "true" ]; then
debug "Adding the root of the workspaces to the list of files and directories to lint with JSCPD..."
FILE_ARRAY_JSCPD+=("${GITHUB_WORKSPACE}")
fi
################
# Footer print #
################
info "----------------------------------------------"
info "Successfully gathered list of files..."
}