Kaynağa Gözat

Merge pull request #734 from Smarticles101/speed-up-travis-build

Implement suggestions from #410
Logan Stucki 9 yıl önce
ebeveyn
işleme
64a0683b66
3 değiştirilmiş dosya ile 74 ekleme ve 3 silme
  1. 2
    2
      .travis.yml
  2. 44
    1
      bin/journey-test.sh
  3. 28
    0
      bin/run-journey-test-from-ci.sh

+ 2
- 2
.travis.yml Dosyayı Görüntüle

@@ -4,7 +4,8 @@ jdk:
4 4
   - oraclejdk8
5 5
 env:
6 6
   - SCRIPT=bin/unit-tests.sh
7
-  - SCRIPT=bin/journey-test.sh
7
+
8
+  - SCRIPT=bin/run-journey-test-from-ci.sh
8 9
 
9 10
 # http://docs.travis-ci.com/user/migrating-from-legacy
10 11
 sudo: false
@@ -17,7 +18,6 @@ addons:
17 18
 before_install:
18 19
   - rvm install 2.2.5
19 20
   - rvm use 2.2.5
20
-  - bin/build-jq.sh  # we want jq 1.5 features; not avail through pkg repo.
21 21
 
22 22
 # https://docs.travis-ci.com/user/customizing-the-build#Skipping-the-Installation-Step
23 23
 install: true  # if we don't skip install, ./gradlew assemble is invoked, but this task is not available.

+ 44
- 1
bin/journey-test.sh Dosyayı Görüntüle

@@ -4,6 +4,7 @@ TRACK=java
4 4
 TRACK_REPO="$TRACK"
5 5
 TRACK_SRC_EXT="java"
6 6
 CPU_CORES=`getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1`
7
+EXERCISES_TO_SOLVE=$@
7 8
 
8 9
 on_exit() {
9 10
   echo ">>> on_exit()"
@@ -256,6 +257,42 @@ solve_all_exercises() {
256 257
   popd
257 258
 }
258 259
 
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
+
259 296
 main() {
260 297
   # all functions assume current working directory is repository root.
261 298
   cd "${SCRIPTPATH}/.."
@@ -296,7 +333,13 @@ main() {
296 333
   # Create a CLI install and config just for this build; this script does not use your CLI install.
297 334
   configure_exercism_cli "${exercism_home}" "${exercism_configfile}" "${xapi_port}"
298 335
 
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
300 343
 }
301 344
 
302 345
 ##########################################################################

+ 28
- 0
bin/run-journey-test-from-ci.sh Dosyayı Görüntüle

@@ -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