Skip to content

Commit fa344af

Browse files
more retries logic, moved into a function
1 parent 5d800d0 commit fa344af

File tree

2 files changed

+77
-28
lines changed

2 files changed

+77
-28
lines changed

bin/qa

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ CI=${CI:-'false'}
109109

110110
#### PROCESS #################################################
111111

112+
hasBeenRestarted="false"
113+
112114
# override configs with project configs
113115
overridePath="$projectConfigPath/qaConfig.inc.bash"
114116

@@ -198,20 +200,27 @@ Running PHPStan
198200
---------------------
199201
"
200202
set +e
201-
phpNoXdebug -f bin/phpstan -- analyse "$srcDir" "$testsDir" "$binDir" -l7 -c "$phpstanConfigPath"
202-
phpStanExitCode=$?
203-
#exit code 0 = fine, 1 = ran fine but found errors, else it means it crashed
204-
if (( $phpStanExitCode > 0 ))
205-
then
206-
if (( $phpStanExitCode > 1 ))
203+
set +e
204+
phpStanExitCode=99
205+
while (( phpStanExitCode > 0 ))
206+
do
207+
phpNoXdebug -f bin/phpstan -- analyse "$srcDir" "$testsDir" "$binDir" -l7 -c "$phpstanConfigPath"
208+
phpStanExitCode=$?
209+
set +x
210+
#exit code 0 = fine, 1 = ran fine but found errors, else it means it crashed
211+
if (( phpStanExitCode > 1 ))
207212
then
208213
printf "\n\n\nPHPStan Crashed....\n\nrunning again with debug mode:\n\n\n"
209214
phpNoXdebug -f bin/phpstan -- analyse "$srcDir" "$testsDir" "$binDir" -l7 -c "$phpstanConfigPath" --debug
215+
exit 1
210216
fi
211-
exit $phpStanExitCode
212-
fi
217+
if (( phpStanExitCode > 0 ))
218+
then
219+
tryAgainOrAbort "PHPStan"
220+
fi
221+
done
213222
set -e
214-
set +x
223+
215224

216225
echo "
217226
@@ -255,7 +264,7 @@ Running PHP Mess Detector
255264
"
256265
set +e
257266
phpMdExitCode=99
258-
while [[ "$phpMdExitCode" != 0 ]]
267+
while (( phpMdExitCode > 0 ))
259268
do
260269
phpNoXdebug -f bin/phpmd -- \
261270
"$srcDir","$testsDir","$binDir" \
@@ -269,16 +278,9 @@ do
269278
| sed -e 's#\. #\.\n#'
270279
phpMdExitCode=$?
271280
set +x
272-
if [[ "0" != "$phpMdExitCode" ]]
281+
if (( phpMdExitCode > 0 ))
273282
then
274-
printf "\n\nPHP Mess Detector Failed, would you like to try again? (y/n)\n\n"
275-
read -n 1 tryAgainOrAbort
276-
if [[ "y" != "$tryAgainOrAbort" ]]
277-
then
278-
printf "\n\nAborting...\n\n"
279-
exit 1
280-
fi
281-
printf "\n\nTrying again, good luck!\n\n"
283+
tryAgainOrAbort "PHP Mess Detector"
282284
fi
283285
done
284286
set +x
@@ -322,16 +324,26 @@ Running Code Sniffer on src and tests
322324
phpNoXdebug -f bin/phpcs -- \
323325
--config-set ignore_warnings_on_exit "$phpcsFailOnWarning"
324326
set +x
325-
phpNoXdebug -f bin/phpcs -- \
326-
--standard="$phpcsCodingStandardsPath" \
327-
--colors \
328-
--cache="$cacheDir"/phpcs.cache \
329-
-s \
330-
--report-full \
331-
--report-summary \
332-
"$srcDir" "$testsDir" "$binDir"
333-
set +x
327+
set +e
328+
phpcsExitCode=99
329+
while (( phpcsExitCode > 0 ))
330+
do
331+
phpNoXdebug -f bin/phpcs -- \
332+
--standard="$phpcsCodingStandardsPath" \
333+
--colors \
334+
--cache="$cacheDir"/phpcs.cache \
335+
-s \
336+
--report-full \
337+
--report-summary \
338+
"$srcDir" "$testsDir" "$binDir"
339+
phpcsExitCode=$?
340+
set +x
341+
if (( phpcsExitCode > 0 ))
342+
then
343+
tryAgainOrAbort "Code Sniffer"
344+
fi
334345

346+
done
335347

336348
echo '
337349
@@ -371,6 +383,20 @@ Running Post Hook $projectConfigPath/hookPost.bash
371383
source $projectConfigPath/hookPost.bash
372384
fi
373385

386+
if [[ "false" != "$hasBeenRestarted" ]]
387+
then
388+
echo "
389+
390+
####################################################################
391+
392+
WARNING - RAN WITH RETRIES
393+
394+
As you have restarted steps in this run,
395+
you should run the whole process again to be sure everything is fine
396+
397+
####################################################################
398+
"
399+
fi
374400

375401
echo "
376402
===========================================

includes/functions.inc.bash

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ function checkForUncommittedChanges {
8585
fi
8686
}
8787

88+
function tryAgainOrAbort(){
89+
toolname="$1"
90+
echo "
91+
92+
==================================================
93+
94+
$toolname Failed...
95+
96+
would you like to try again? (y/n)
97+
98+
==================================================
99+
100+
"
101+
read -n 1 tryAgainOrAbort
102+
if [[ "y" != "$tryAgainOrAbort" ]]
103+
then
104+
printf "\n\nAborting...\n\n"
105+
exit 1
106+
fi
107+
printf "\n\nTrying again, good luck!\n\n"
108+
hasBeenRestarted="true"
109+
}
110+
88111
function findTestsDir(){
89112
testsDir="$(find $projectRoot -maxdepth 1 -type d \( -name test -o -name tests \) | head -n1)"
90113
if [[ "" == "$testsDir" ]]

0 commit comments

Comments
 (0)