Skip to content

Commit 4407a4a

Browse files
committed
Update run-journey-test-from-ci
The run-journey-test-from-ci script should: - Check which files have been changed in the PR - If it doesn't get a correct response from travis then run all exercises - If a setup file (*.gradle, *.sh or config.json) has been changed then run all exercises - Otherwise only run the exercises that have been changed This should mean that we don't run more tests that are necessary but we still test all new changes.
1 parent 73f1339 commit 4407a4a

1 file changed

Lines changed: 74 additions & 24 deletions

File tree

bin/run-journey-test-from-ci.sh

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,82 @@
11
#!/bin/bash
22

3-
trap 'exit 1' ERR
4-
bin/build-jq.sh
3+
contains_setup_file() {
4+
local files=$1
5+
for file in $files; do
6+
if [[ $file == *.gradle || $file == *.sh || $file == config.json ]]; then
7+
return 0
8+
fi
9+
done
10+
return 1
11+
}
12+
13+
contains_exercise() {
14+
local files=$1
15+
for file in $files; do
16+
if [[ $file == exercises* ]]; then
17+
return 0
18+
fi
19+
done
20+
return 1
21+
}
522

6-
pr_files_json=`curl -s https://api.github.com/repos/exercism/java/pulls/${TRAVIS_PULL_REQUEST}/files`
23+
run_journey_test_with_modified_exercises() {
24+
local modded_files=$1
25+
local last_modded_exercise=""
26+
local modded_exercises=""
727

8-
echo "Pull request number: ${TRAVIS_PULL_REQUEST}"
9-
echo "Changes in pr json: ${pr_files_json}"
28+
for file in $modded_files; do
29+
if [[ $file == exercises* ]] && [[ $file != exercises/settings.gradle ]] && [[ $file != exercises/build.gradle ]]; then
30+
local modded_exercise=${file#exercises/}
31+
modded_exercise=${modded_exercise%%/*}
32+
if [[ $last_modded_exercise != $modded_exercise ]]; then
33+
modded_exercises=$modded_exercises$modded_exercise$'\n'
34+
fi
35+
last_modded_exercise=$modded_exercise
36+
fi
37+
done
1038

11-
# if jq fails to get the required data, then that means TRAVIS_PULL_REQUEST was not set (not run in travis-ci),
12-
# or was false (not a pull request). In that case, we should fall back with testing every exercise
39+
echo "Running journey test with modified exercise(s): ${modded_exercises}"
40+
bin/journey-test.sh $modded_exercises
41+
}
1342

14-
modded_files=`echo $pr_files_json | bin/jq -r '.[].filename'` || bin/journey-test.sh
43+
run_journey_test_with_all_exercises() {
44+
echo "Running journey test with all exercises"
45+
bin/journey-test.sh
46+
}
1547

16-
for file in $modded_files
17-
do if [[ $file == exercises* ]] || [[ $file == config.json ]]
18-
then
19-
for file2 in $modded_files
20-
do if [[ $file2 == exercises* ]] && [[ $file2 != exercises/settings.gradle ]] && [[ $file2 != exercises/build.gradle ]]
21-
then modded_exercise=${file2#exercises/}
22-
modded_exercise=${modded_exercise%%/*}
23-
if [[ $last_modded_exercise != $modded_exercise ]]
24-
then modded_exercises=$modded_exercises$modded_exercise$'\n'
25-
fi
26-
last_modded_exercise=$modded_exercise
27-
fi
28-
done
29-
bin/journey-test.sh $modded_exercises
30-
break
48+
main() {
49+
bin/build-jq.sh
50+
51+
local pr_files_json=`curl -s https://api.github.com/repos/exercism/java/pulls/${TRAVIS_PULL_REQUEST}/files`
52+
53+
echo "Pull request number: ${TRAVIS_PULL_REQUEST}"
54+
echo "Changes in pr json: ${pr_files_json}"
55+
56+
# if jq fails to get the required data, then that means TRAVIS_PULL_REQUEST was not set (not run in travis-ci),
57+
# or was false (not a pull request), or the api limit was reached, or some other error occurred.
58+
# In that case, we should fall back with testing every exercise
59+
local pr_files_json_type=`echo $pr_files_json | bin/jq -r 'type'`
60+
if [[ $pr_files_json_type != "array" ]]; then
61+
echo "Didn't get pr changes from travis"
62+
run_journey_test_with_all_exercises
63+
return
3164
fi
32-
done
65+
66+
local modded_files=`echo $pr_files_json | bin/jq -r '.[].filename'`
67+
68+
# If the changed files contain a .sh file or .gradle file or config.json then we should run all the exercises
69+
if contains_setup_file "${modded_files}"; then
70+
echo "Pr changes contain setup file(s): ${modded_files}"
71+
run_journey_test_with_all_exercises
72+
return
73+
fi
74+
75+
if contains_exercise "${modded_files}"; then
76+
echo "Pr changes contain modified exercise file(s)"
77+
run_journey_test_with_modified_exercises "${modded_files}"
78+
fi
79+
}
80+
81+
trap 'exit 1' ERR
82+
main

0 commit comments

Comments
 (0)