ci.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. set -eu
  3. if [ $# -eq 0 ]; then
  4. echo "Need test suite argument."
  5. exit -1
  6. fi
  7. killall -q peertube || true
  8. retries=3
  9. runTest () {
  10. jobname=$1
  11. shift
  12. jobs=$1
  13. shift
  14. files=$@
  15. echo $files
  16. joblog="$jobname-ci.log"
  17. parallel -j $jobs --retries $retries \
  18. "echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --require ./dist/server/tests/register.js --bail {}" \
  19. ::: $files
  20. cat "$joblog" | uniq -c
  21. rm "$joblog"
  22. }
  23. findTestFiles () {
  24. exception="-not -name index.js"
  25. if [ ! -z ${2+x} ]; then
  26. exception="$exception -not -name $2"
  27. fi
  28. find $1 -type f -name "*.js" $exception | xargs echo
  29. }
  30. if [ "$1" = "client" ]; then
  31. npm run build
  32. feedsFiles=$(findTestFiles ./dist/server/tests/feeds)
  33. helperFiles=$(findTestFiles ./dist/server/tests/helpers)
  34. libFiles=$(findTestFiles ./dist/server/tests/lib)
  35. miscFiles="./dist/server/tests/client.js ./dist/server/tests/misc-endpoints.js"
  36. # Not in plugin task, it needs an index.html
  37. pluginFiles="./dist/server/tests/plugins/html-injection.js"
  38. MOCHA_PARALLEL=true runTest "$1" 2 $feedsFiles $helperFiles $miscFiles $pluginFiles $libFiles
  39. elif [ "$1" = "cli-plugin" ]; then
  40. npm run build:server
  41. npm run setup:cli
  42. pluginsFiles=$(findTestFiles ./dist/server/tests/plugins html-injection.js)
  43. cliFiles=$(findTestFiles ./dist/server/tests/cli)
  44. MOCHA_PARALLEL=true runTest "$1" 2 $pluginsFiles
  45. runTest "$1" 1 $cliFiles
  46. elif [ "$1" = "api-1" ]; then
  47. npm run build:server
  48. checkParamFiles=$(findTestFiles ./dist/server/tests/api/check-params)
  49. notificationsFiles=$(findTestFiles ./dist/server/tests/api/notifications)
  50. searchFiles=$(findTestFiles ./dist/server/tests/api/search)
  51. MOCHA_PARALLEL=true runTest "$1" 3 $notificationsFiles $searchFiles $checkParamFiles
  52. elif [ "$1" = "api-2" ]; then
  53. npm run build:server
  54. liveFiles=$(findTestFiles ./dist/server/tests/api/live)
  55. serverFiles=$(findTestFiles ./dist/server/tests/api/server)
  56. usersFiles=$(findTestFiles ./dist/server/tests/api/users)
  57. MOCHA_PARALLEL=true runTest "$1" 3 $liveFiles $serverFiles $usersFiles
  58. elif [ "$1" = "api-3" ]; then
  59. npm run build:server
  60. videosFiles=$(findTestFiles ./dist/server/tests/api/videos)
  61. MOCHA_PARALLEL=true runTest "$1" 3 $videosFiles
  62. elif [ "$1" = "api-4" ]; then
  63. npm run build:server
  64. moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation)
  65. redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy)
  66. objectStorageFiles=$(findTestFiles ./dist/server/tests/api/object-storage)
  67. activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub)
  68. MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $moderationFiles $redundancyFiles $activitypubFiles $objectStorageFiles
  69. elif [ "$1" = "external-plugins" ]; then
  70. npm run build:server
  71. externalPluginsFiles=$(findTestFiles ./dist/server/tests/external-plugins)
  72. runTest "$1" 1 $externalPluginsFiles
  73. elif [ "$1" = "lint" ]; then
  74. npm run eslint -- --ext .ts "./server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts"
  75. npm run swagger-cli -- validate support/doc/api/openapi.yaml
  76. ( cd client
  77. npm run lint
  78. )
  79. fi