ci.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. 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 --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" = "types-package" ]; then
  31. npm run generate-types-package 0.0.0
  32. npm run tsc -- --noEmit --esModuleInterop packages/types/tests/test.ts
  33. elif [ "$1" = "client" ]; then
  34. npm run build
  35. feedsFiles=$(findTestFiles ./dist/server/tests/feeds)
  36. helperFiles=$(findTestFiles ./dist/server/tests/helpers)
  37. libFiles=$(findTestFiles ./dist/server/tests/lib)
  38. miscFiles="./dist/server/tests/client.js ./dist/server/tests/misc-endpoints.js"
  39. # Not in their own task, they need an index.html
  40. pluginFiles="./dist/server/tests/plugins/html-injection.js ./dist/server/tests/api/server/plugins.js"
  41. MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $feedsFiles $helperFiles $miscFiles $pluginFiles $libFiles
  42. elif [ "$1" = "cli-plugin" ]; then
  43. npm run build:server
  44. npm run setup:cli
  45. pluginsFiles=$(findTestFiles ./dist/server/tests/plugins html-injection.js)
  46. cliFiles=$(findTestFiles ./dist/server/tests/cli)
  47. MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $pluginsFiles
  48. runTest "$1" 1 $cliFiles
  49. elif [ "$1" = "api-1" ]; then
  50. npm run build:server
  51. checkParamFiles=$(findTestFiles ./dist/server/tests/api/check-params)
  52. notificationsFiles=$(findTestFiles ./dist/server/tests/api/notifications)
  53. searchFiles=$(findTestFiles ./dist/server/tests/api/search)
  54. MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $notificationsFiles $searchFiles $checkParamFiles
  55. elif [ "$1" = "api-2" ]; then
  56. npm run build:server
  57. liveFiles=$(findTestFiles ./dist/server/tests/api/live)
  58. serverFiles=$(findTestFiles ./dist/server/tests/api/server plugins.js)
  59. usersFiles=$(findTestFiles ./dist/server/tests/api/users)
  60. MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $liveFiles $serverFiles $usersFiles
  61. elif [ "$1" = "api-3" ]; then
  62. npm run build:server
  63. videosFiles=$(findTestFiles ./dist/server/tests/api/videos)
  64. viewsFiles=$(findTestFiles ./dist/server/tests/api/views)
  65. MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $viewsFiles $videosFiles
  66. elif [ "$1" = "api-4" ]; then
  67. npm run build:server
  68. moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation)
  69. redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy)
  70. objectStorageFiles=$(findTestFiles ./dist/server/tests/api/object-storage)
  71. activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub)
  72. MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $moderationFiles $redundancyFiles $activitypubFiles $objectStorageFiles
  73. elif [ "$1" = "api-5" ]; then
  74. npm run build:server
  75. transcodingFiles=$(findTestFiles ./dist/server/tests/api/transcoding)
  76. MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $transcodingFiles
  77. elif [ "$1" = "external-plugins" ]; then
  78. npm run build:server
  79. externalPluginsFiles=$(findTestFiles ./dist/server/tests/external-plugins)
  80. runTest "$1" 1 $externalPluginsFiles
  81. elif [ "$1" = "lint" ]; then
  82. npm run eslint -- --ext .ts "./server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts"
  83. npm run swagger-cli -- validate support/doc/api/openapi.yaml
  84. ( cd client
  85. npm run lint
  86. )
  87. fi