Skip to content

Commit 64a0683

Browse files
Merge pull request exercism#734 from Smarticles101/speed-up-travis-build
Implement suggestions from exercism#410
2 parents 833394a + 750176d commit 64a0683

3 files changed

Lines changed: 74 additions & 3 deletions

File tree

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ jdk:
44
- oraclejdk8
55
env:
66
- SCRIPT=bin/unit-tests.sh
7-
- SCRIPT=bin/journey-test.sh
7+
8+
- SCRIPT=bin/run-journey-test-from-ci.sh
89

910
# http://docs.travis-ci.com/user/migrating-from-legacy
1011
sudo: false
@@ -17,7 +18,6 @@ addons:
1718
before_install:
1819
- rvm install 2.2.5
1920
- rvm use 2.2.5
20-
- bin/build-jq.sh # we want jq 1.5 features; not avail through pkg repo.
2121

2222
# https://docs.travis-ci.com/user/customizing-the-build#Skipping-the-Installation-Step
2323
install: true # if we don't skip install, ./gradlew assemble is invoked, but this task is not available.

bin/journey-test.sh

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ TRACK=java
44
TRACK_REPO="$TRACK"
55
TRACK_SRC_EXT="java"
66
CPU_CORES=`getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1`
7+
EXERCISES_TO_SOLVE=$@
78

89
on_exit() {
910
echo ">>> on_exit()"
@@ -256,6 +257,42 @@ solve_all_exercises() {
256257
popd
257258
}
258259

260+
solve_single_exercise() {
261+
local exercism_exercises_dir="$1"
262+
local exercism_configfile="$2"
263+
local exercise_to_solve="$3"
264+
echo ">>> solve_all_exercises(exercism_exercises_dir=\"${exercism_exercises_dir}\", exercism_configfile=\"${exercism_configfile}\", exercise_to_solve=\"$exercise_to_solve\")"
265+
266+
local track_root=$( pwd )
267+
local exercism_cli="./exercism --config ${exercism_configfile}"
268+
local tempfile="${TMPDIR:-/tmp}/journey-test.sh-unignore_all_tests.txt"
269+
270+
pushd ${exercism_exercises_dir}
271+
272+
echo -e "\n\n"
273+
echo "=================================================="
274+
echo "Solving ${exercise_to_solve}"
275+
echo "=================================================="
276+
277+
${exercism_cli} fetch ${TRACK} $exercise_to_solve
278+
cp -R -H ${track_root}/exercises/${exercise_to_solve}/src/example/${TRACK}/* ${exercism_exercises_dir}/${TRACK}/${exercise_to_solve}/src/main/${TRACK}/
279+
280+
pushd ${exercism_exercises_dir}/${TRACK}/${exercise_to_solve}
281+
# Check that tests compile before we strip @Ignore annotations
282+
"$EXECPATH"/gradlew compileTestJava
283+
# Ensure we run all the tests (as delivered, all but the first is @Ignore'd)
284+
for testfile in `find . -name "*Test.${TRACK_SRC_EXT}"`; do
285+
# Strip @Ignore annotations to ensure we run the tests (as delivered, all but the first is @Ignore'd).
286+
# Note that unit-test.sh also strips @Ignore annotations via the Gradle task copyTestsFilteringIgnores.
287+
# The stripping implementations here and in copyTestsFilteringIgnores should be kept consistent.
288+
sed 's/@Ignore\(\(.*\)\)\{0,1\}//' ${testfile} > "${tempfile}" && mv "${tempfile}" "${testfile}"
289+
done
290+
"$EXECPATH"/gradlew test
291+
popd
292+
293+
popd
294+
}
295+
259296
main() {
260297
# all functions assume current working directory is repository root.
261298
cd "${SCRIPTPATH}/.."
@@ -296,7 +333,13 @@ main() {
296333
# Create a CLI install and config just for this build; this script does not use your CLI install.
297334
configure_exercism_cli "${exercism_home}" "${exercism_configfile}" "${xapi_port}"
298335

299-
solve_all_exercises "${exercism_home}" "${exercism_configfile}"
336+
if [[ $EXERCISES_TO_SOLVE == "" ]]; then
337+
solve_all_exercises "${exercism_home}" "${exercism_configfile}"
338+
else
339+
for exercise in $EXERCISES_TO_SOLVE
340+
do solve_single_exercise "${exercism_home}" "${exercism_configfile}" "${exercise}"
341+
done
342+
fi
300343
}
301344

302345
##########################################################################

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
bin/build-jq.sh
4+
5+
pr_files_json=`curl -s https://api.github.com/repos/exercism/java/pulls/${TRAVIS_PULL_REQUEST}/files`
6+
7+
# if jq fails to get the required data, then that means TRAVIS_PULL_REQUEST was not set (not run in travis-ci),
8+
# or was false (not a pull request). In that case, we should fall back with testing every exercise
9+
10+
modded_files=`echo $pr_files_json | bin/jq -r '.[].filename'` || bin/journey-test.sh
11+
12+
for file in $modded_files
13+
do if [[ $file == exercises* ]] || [[ $file == config.json ]]
14+
then
15+
for file2 in $modded_files
16+
do if [[ $file2 == exercises* ]]
17+
then modded_exercise=${file2#exercises/}
18+
modded_exercise=${modded_exercise%%/*}
19+
if [[ $last_modded_exercise != $modded_exercise ]]
20+
then modded_exercises=$modded_exercises$modded_exercise$'\n'
21+
fi
22+
last_modded_exercise=$modded_exercise
23+
fi
24+
done
25+
bin/journey-test.sh $modded_exercises
26+
break
27+
fi
28+
done

0 commit comments

Comments
 (0)