]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - scripts/ci.sh
Faster ci using compiled ts files
[github/Chocobozzz/PeerTube.git] / scripts / ci.sh
index 9ff640c8e7ff35e9b9781aa27567491bad4bda73..7360a03ce8853286e82f2b05acf0bffc1683cdb6 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 set -eu
 
@@ -9,38 +9,90 @@ fi
 
 killall -q peertube || true
 
-perl -0777 -i  -pe 's#proxy:(\n\s+)enabled: false\n\s+url: ""#proxy:$1enabled: true$1url: "'"$PROXY_URL"'"#' config/test.yaml
+retries=3
+
+runTest () {
+    jobname=$1
+    shift
+
+    jobs=$1
+    shift
+
+    files=$@
+
+    echo $files
+
+    joblog="$jobname-ci.log"
+
+    parallel -j $jobs --retries $retries \
+        "echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --require ./dist/server/tests/register.js --bail {}" \
+        ::: $files
+
+    cat "$joblog" | uniq -c
+    rm "$joblog"
+}
+
+findTestFiles () {
+    find $1 -type f -name "*.js" | grep -v "/index.js" | xargs echo
+}
 
 if [ "$1" = "misc" ]; then
-    npm run build -- --light-fr
-    mocha --timeout 5000 --exit --require ts-node/register --require tsconfig-paths/register --bail server/tests/client.ts \
-        server/tests/feeds/index.ts \
-        server/tests/misc-endpoints.ts \
-        server/tests/helpers/index.ts \
-        server/tests/plugins/index.ts
+    npm run build
+
+    feedsFiles=$(findTestFiles ./dist/server/tests/feeds)
+    helperFiles=$(findTestFiles ./dist/server/tests/helpers)
+    pluginsFiles=$(findTestFiles ./dist/server/tests/plugins)
+    miscFiles="./dist/server/tests/client.js ./dist/server/tests/misc-endpoints.js"
+
+    MOCHA_PARALLEL=true runTest "$1" 2 $feedsFiles $helperFiles $pluginsFiles $miscFiles
 elif [ "$1" = "cli" ]; then
     npm run build:server
-    CC=gcc-4.9 CXX=g++-4.9 npm run setup:cli
-    mocha --timeout 5000 --exit --require ts-node/register --require tsconfig-paths/register --bail server/tests/cli/index.ts
+    npm run setup:cli
+
+    cliFiles=$(findTestFiles ./dist/server/tests/cli)
+
+    runTest "$1" 1 $cliFiles
 elif [ "$1" = "api-1" ]; then
     npm run build:server
-    sh ./server/tests/api/ci-1.sh 2
+
+    checkParamFiles=$(findTestFiles ./dist/server/tests/api/check-params)
+    notificationsFiles=$(findTestFiles ./dist/server/tests/api/notifications)
+    searchFiles=$(findTestFiles ./dist/server/tests/api/search)
+
+    MOCHA_PARALLEL=true runTest "$1" 3 $notificationsFiles $searchFiles $checkParamFiles
 elif [ "$1" = "api-2" ]; then
     npm run build:server
-    sh ./server/tests/api/ci-2.sh 2
+
+    serverFiles=$(findTestFiles ./dist/server/tests/api/server)
+    usersFiles=$(findTestFiles ./dist/server/tests/api/users)
+    liveFiles=$(findTestFiles ./dist/server/tests/api/live)
+
+    MOCHA_PARALLEL=true runTest "$1" 3 $serverFiles $usersFiles $liveFiles
 elif [ "$1" = "api-3" ]; then
     npm run build:server
-    sh ./server/tests/api/ci-3.sh 2
+
+    videosFiles=$(findTestFiles ./dist/server/tests/api/videos)
+
+    MOCHA_PARALLEL=true runTest "$1" 3 $videosFiles
 elif [ "$1" = "api-4" ]; then
     npm run build:server
-    sh ./server/tests/api/ci-4.sh 2
+
+    moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation)
+    redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy)
+    activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub)
+
+    MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $moderationFiles $redundancyFiles $activitypubFiles
+elif [ "$1" = "external-plugins" ]; then
+    npm run build:server
+
+    externalPluginsFiles=$(findTestFiles ./dist/server/tests/external-plugins)
+
+    runTest "$1" 1 $externalPluginsFiles
 elif [ "$1" = "lint" ]; then
-    npm run tslint -- --project ./tsconfig.json -c ./tslint.json server.ts "server/**/*.ts" "shared/**/*.ts"
+    npm run eslint -- --ext .ts "./server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts"
     npm run swagger-cli -- validate support/doc/api/openapi.yaml
 
     ( cd client
       npm run lint
     )
 fi
-
-git checkout -- config/test.yaml