Skip to content

Commit b6e7d63

Browse files
committed
Set default before early exiting
1 parent c6fa899 commit b6e7d63

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

.github/workflows/build-check-install.yaml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,24 @@ jobs:
543543
# Bash script run
544544
commit_msg=$( git log -1 --pretty=%B )
545545
546+
# Set default TESTING_DEPTH
547+
td=$TESTING_DEPTH
548+
if [ -z "$td" ]
549+
then {
550+
echo "No TESTING_DEPTH default"
551+
echo "TESTING_DEPTH=5" >> "$GITHUB_ENV"
552+
td=5
553+
} fi
554+
546555
echo "Commit msg is: ${commit_msg}"
547556
# Exit early if tag is on commit message even if it set to true
548557
test_all=$( echo "${commit_msg}" | grep -zvF "[run-all-tests]" | tr -d '\0')
549558
550559
if [ -z "$test_all" ]
551560
then {
552561
echo "Last commit message forces to test everything."
562+
echo Using "TESTING_DEPTH=$td"
563+
echo "TESTING_DEPTH=$td" >> "$GITHUB_ENV"
553564
exit 0
554565
} fi
555566
@@ -558,18 +569,11 @@ jobs:
558569
if [ -z "$ALL_CHANGED_FILES" ]
559570
then {
560571
echo "No R files affected: test everything."
572+
echo Using "TESTING_DEPTH=$td"
573+
echo "TESTING_DEPTH=$td" >> "$GITHUB_ENV"
561574
exit 0
562575
} fi
563576
564-
# Set default TESTING_DEPTH
565-
td=$TESTING_DEPTH
566-
if [ -z "$td" ]
567-
then {
568-
echo "No TESTING_DEPTH default"
569-
td=5
570-
} fi
571-
572-
echo "$ALL_CHANGED_FILES"
573577
# Loop through each modified file and determine which tests to run
574578
for file in $ALL_CHANGED_FILES; do
575579
@@ -580,31 +584,27 @@ jobs:
580584
# R/foo.R -> foo
581585
base_name=$(basename "$file" .R | sed s/test-shinytest2-//g)
582586
# Find matching test files (parenthesis to not match arguments)
583-
test_files=$(grep -l "$base_name(" "$test_dir"test-shinytest2-*.R)
584-
587+
test_files=$(grep -l "$base_name(" "$test_dir"test-shinytest2-*.R || echo "")
585588
# Modify in place so that only modified modules are tested.
586-
if [ -n "$test_files" ];
589+
if [ -z "$test_files" ];
587590
then {
588-
sed -i 's/skip_if_too_deep(5)/skip_if_too_deep(3)/g' "$test_files"
589-
TESTING_DEPTH="3"
590-
echo "Testing with shinytest2 for $test_files";
591-
} else {
592-
# Flag for helpers
593-
helper_modified="yes"
594591
git restore $test_dir
595592
echo "Run all tests"
596-
break;
597-
} fi
598-
599-
# R file without corresponding test file: reset the testing depth
600-
if [ -n "$helper_modified" ] || [ -z "$test_all" ];
601-
then {
602-
echo "Skip step or helper modifications detected."
593+
echo "Helper modifications detected."
603594
TESTING_DEPTH="$td";
595+
break;
596+
} else {
597+
if [ -n "$test_files" ];
598+
then {
599+
sed -i 's/skip_if_too_deep(5)/skip_if_too_deep(3)/g' "$test_files"
600+
TESTING_DEPTH="3"
601+
echo "Testing with shinytest2 for $test_files";
602+
} else {
603+
echo "Something unexpected happened"
604+
} fi
604605
} fi
605606
done
606607
607-
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
608608
echo Using "TESTING_DEPTH=${TESTING_DEPTH}"
609609
echo "TESTING_DEPTH=${TESTING_DEPTH}" >> "$GITHUB_ENV"
610610
shell: bash

0 commit comments

Comments
 (0)