File tree Expand file tree Collapse file tree 2 files changed +45
-14
lines changed
Expand file tree Collapse file tree 2 files changed +45
-14
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,21 @@ source "$SCRIPT_DIR/../lib/util.sh"
1717
1818util::parse_cmdline " $@ "
1919
20- error=0
21-
20+ pids=()
2221for file in " ${FILES[@]} " ; do
23- if ! packer fmt " ${ARGS[@]} " -- " $file " ; then
22+ # Check each path in parallel
23+ {
24+ packer fmt " ${ARGS[@]} " -- " $file "
25+ } &
26+ pids+=(" $! " )
27+ done
28+
29+ error=0
30+ exit_code=0
31+ for pid in " ${pids[@]} " ; do
32+ wait " $pid " || exit_code=$?
33+ if [[ $exit_code -ne 0 ]]; then
2434 error=1
25- echo
26- echo " Failed path: $file "
27- echo " ================================"
2835 fi
2936done
3037
Original file line number Diff line number Diff line change @@ -4,6 +4,25 @@ set -o nounset
44set -o errexit
55set -o pipefail
66
7+ function packer_validate() {
8+ local exit_code=0
9+
10+ packer init . > /dev/null
11+
12+ # Allow us to get output if the validation fails
13+ set +o errexit
14+ validate_output=$( packer validate " ${ARGS[@]} " . 2>&1 )
15+ exit_code=$?
16+ set -o errexit
17+
18+ if [[ $exit_code -ne 0 ]]; then
19+ echo " Validation failed in $path "
20+ echo -e " $validate_output \n\n"
21+ fi
22+
23+ return $exit_code
24+ }
25+
726if [ -z " $( command -v packer) " ]; then
827 echo " packer is required"
928 exit 1
@@ -19,17 +38,22 @@ util::parse_cmdline "$@"
1938
2039util::get_unique_directory_paths " ${FILES[@]} "
2140
22- error=0
23-
41+ pids=()
2442for path in " ${UNIQUE_PATHS[@]} " ; do
25- pushd " $path " > /dev/null
43+ # Check each path in parallel
44+ {
45+ pushd " $path " > /dev/null
46+ packer_validate
47+ } &
48+ pids+=(" $! " )
49+ done
2650
27- packer init . > /dev/null
28- if ! packer validate " ${ARGS[@]} " . ; then
51+ error=0
52+ exit_code=0
53+ for pid in " ${pids[@]} " ; do
54+ wait " $pid " || exit_code=$?
55+ if [[ $exit_code -ne 0 ]]; then
2956 error=1
30- echo
31- echo " Failed path: $path "
32- echo " ================================"
3357 fi
3458done
3559
You can’t perform that action at this time.
0 commit comments