ci.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash
  2. set -eu
  3. if [ $# -eq 0 ]; then
  4. echo "Need test suite argument."
  5. exit -1
  6. fi
  7. retries=3
  8. speedFactor="${2:-1}"
  9. runJSTest () {
  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 -- --timeout 30000 --no-config -c --exit --bail {}" \
  19. ::: $files
  20. cat "$joblog" | sort | uniq -c
  21. rm "$joblog"
  22. }
  23. findTestFiles () {
  24. exception="-not -name index.js -not -name index.ts -not -name *.d.ts"
  25. if [ ! -z ${2+x} ]; then
  26. exception="$exception -not -name $2"
  27. fi
  28. find $1 -type f \( -name "*.js" -o -name "*.ts" \) $exception | xargs echo
  29. }
  30. if [ "$1" = "types-package" ]; then
  31. npm run generate-types-package 0.0.0
  32. # Test on in independent directory
  33. rm -fr /tmp/types-generator
  34. mkdir -p /tmp/types-generator
  35. cp -r packages/types-generator/tests /tmp/types-generator/tests
  36. cp -r packages/types-generator/dist /tmp/types-generator/dist
  37. (cd /tmp/types-generator/dist && npm install)
  38. npm run tsc -- --noEmit --esModuleInterop --moduleResolution node16 --module Node16 /tmp/types-generator/tests/test.ts
  39. rm -r /tmp/types-generator
  40. elif [ "$1" = "client" ]; then
  41. npm run build
  42. npm run build:tests
  43. feedsFiles=$(findTestFiles ./packages/tests/dist/feeds)
  44. clientFiles=$(findTestFiles ./packages/tests/dist/client)
  45. miscFiles="./packages/tests/dist/misc-endpoints.js ./packages/tests/dist/nginx.js"
  46. # Not in their own task, they need an index.html
  47. pluginFiles="./packages/tests/dist/plugins/html-injection.js ./packages/tests/dist/api/server/plugins.js"
  48. MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $feedsFiles $miscFiles $pluginFiles $clientFiles
  49. # Use TS tests directly because we import server files
  50. helperFiles=$(findTestFiles ./packages/tests/src/server-helpers)
  51. libFiles=$(findTestFiles ./packages/tests/src/server-lib)
  52. npm run mocha -- --timeout 30000 -c --exit --bail $libFiles $helperFiles
  53. elif [ "$1" = "cli-plugin" ]; then
  54. # Simulate HTML
  55. mkdir -p "./client/dist/en-US/"
  56. cp "./client/src/index.html" "./client/dist/en-US/index.html"
  57. npm run build:server
  58. npm run build:tests
  59. npm run build:peertube-cli
  60. # html-injection test needs an HTML file
  61. pluginsFiles=$(findTestFiles ./packages/tests/dist/plugins html-injection.js)
  62. cliFiles=$(findTestFiles ./packages/tests/dist/cli)
  63. MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $pluginsFiles
  64. runJSTest "$1" 1 $cliFiles
  65. elif [ "$1" = "api-1" ]; then
  66. npm run build:server
  67. npm run build:tests
  68. checkParamFiles=$(findTestFiles ./packages/tests/dist/api/check-params)
  69. notificationsFiles=$(findTestFiles ./packages/tests/dist/api/notifications)
  70. searchFiles=$(findTestFiles ./packages/tests/dist/api/search)
  71. MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $notificationsFiles $searchFiles $checkParamFiles
  72. elif [ "$1" = "api-2" ]; then
  73. npm run build:server
  74. npm run build:tests
  75. liveFiles=$(findTestFiles ./packages/tests/dist/api/live)
  76. # plugins test needs an HTML file
  77. serverFiles=$(findTestFiles ./packages/tests/dist/api/server plugins.js)
  78. usersFiles=$(findTestFiles ./packages/tests/dist/api/users)
  79. MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $liveFiles $serverFiles $usersFiles
  80. elif [ "$1" = "api-3" ]; then
  81. npm run build:server
  82. npm run build:tests
  83. videosFiles=$(findTestFiles ./packages/tests/dist/api/videos)
  84. viewsFiles=$(findTestFiles ./packages/tests/dist/api/views)
  85. MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $viewsFiles $videosFiles
  86. elif [ "$1" = "api-4" ]; then
  87. npm run build:server
  88. npm run build:tests
  89. moderationFiles=$(findTestFiles ./packages/tests/dist/api/moderation)
  90. redundancyFiles=$(findTestFiles ./packages/tests/dist/api/redundancy)
  91. objectStorageFiles=$(findTestFiles ./packages/tests/dist/api/object-storage)
  92. activitypubFiles=$(findTestFiles ./packages/tests/dist/api/activitypub)
  93. MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $moderationFiles $redundancyFiles $activitypubFiles $objectStorageFiles
  94. elif [ "$1" = "api-5" ]; then
  95. npm run build:server
  96. npm run build:tests
  97. transcodingFiles=$(findTestFiles ./packages/tests/dist/api/transcoding)
  98. runnersFiles=$(findTestFiles ./packages/tests/dist/api/runners)
  99. MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $transcodingFiles $runnersFiles
  100. elif [ "$1" = "external-plugins" ]; then
  101. npm run build:server
  102. npm run build:tests
  103. npm run build:peertube-runner
  104. externalPluginsFiles=$(findTestFiles ./packages/tests/dist/external-plugins)
  105. peertubeRunnerFiles=$(findTestFiles ./packages/tests/dist/peertube-runner)
  106. runJSTest "$1" 1 $externalPluginsFiles
  107. MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $peertubeRunnerFiles
  108. elif [ "$1" = "lint" ]; then
  109. npm run eslint -- --ext .ts "server/**/*.ts" "scripts/**/*.ts" "packages/**/*.ts" "apps/**/*.ts"
  110. npm run swagger-cli -- validate support/doc/api/openapi.yaml
  111. ( cd client && npm run lint )
  112. fi