]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/ci.sh
Add watching and views endpoints to benchmark
[github/Chocobozzz/PeerTube.git] / scripts / ci.sh
1 #!/bin/bash
2
3 set -eu
4
5 if [ $# -eq 0 ]; then
6 echo "Need test suite argument."
7 exit -1
8 fi
9
10 retries=3
11 speedFactor="${2:-1}"
12
13 runTest () {
14 jobname=$1
15 shift
16
17 jobs=$1
18 shift
19
20 files=$@
21
22 echo $files
23
24 joblog="$jobname-ci.log"
25
26 parallel -j $jobs --retries $retries \
27 "echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --bail {}" \
28 ::: $files
29
30 cat "$joblog" | uniq -c
31 rm "$joblog"
32 }
33
34 findTestFiles () {
35 exception="-not -name index.js"
36
37 if [ ! -z ${2+x} ]; then
38 exception="$exception -not -name $2"
39 fi
40
41 find $1 -type f -name "*.js" $exception | xargs echo
42 }
43
44 if [ "$1" = "types-package" ]; then
45 npm run generate-types-package 0.0.0
46 npm run tsc -- --noEmit --esModuleInterop packages/types/tests/test.ts
47 elif [ "$1" = "client" ]; then
48 npm run build
49
50 feedsFiles=$(findTestFiles ./dist/server/tests/feeds)
51 helperFiles=$(findTestFiles ./dist/server/tests/helpers)
52 libFiles=$(findTestFiles ./dist/server/tests/lib)
53 miscFiles="./dist/server/tests/client.js ./dist/server/tests/misc-endpoints.js"
54 # Not in their own task, they need an index.html
55 pluginFiles="./dist/server/tests/plugins/html-injection.js ./dist/server/tests/api/server/plugins.js"
56
57 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $feedsFiles $helperFiles $miscFiles $pluginFiles $libFiles
58 elif [ "$1" = "cli-plugin" ]; then
59 npm run build:server
60 npm run setup:cli
61
62 pluginsFiles=$(findTestFiles ./dist/server/tests/plugins html-injection.js)
63 cliFiles=$(findTestFiles ./dist/server/tests/cli)
64
65 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $pluginsFiles
66 runTest "$1" 1 $cliFiles
67 elif [ "$1" = "api-1" ]; then
68 npm run build:server
69
70 checkParamFiles=$(findTestFiles ./dist/server/tests/api/check-params)
71 notificationsFiles=$(findTestFiles ./dist/server/tests/api/notifications)
72 searchFiles=$(findTestFiles ./dist/server/tests/api/search)
73
74 MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $notificationsFiles $searchFiles $checkParamFiles
75 elif [ "$1" = "api-2" ]; then
76 npm run build:server
77
78 liveFiles=$(findTestFiles ./dist/server/tests/api/live)
79 serverFiles=$(findTestFiles ./dist/server/tests/api/server plugins.js)
80 usersFiles=$(findTestFiles ./dist/server/tests/api/users)
81
82 MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $liveFiles $serverFiles $usersFiles
83 elif [ "$1" = "api-3" ]; then
84 npm run build:server
85
86 videosFiles=$(findTestFiles ./dist/server/tests/api/videos)
87
88 MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $videosFiles
89 elif [ "$1" = "api-4" ]; then
90 npm run build:server
91
92 moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation)
93 redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy)
94 objectStorageFiles=$(findTestFiles ./dist/server/tests/api/object-storage)
95 activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub)
96
97 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $moderationFiles $redundancyFiles $activitypubFiles $objectStorageFiles
98 elif [ "$1" = "api-5" ]; then
99 npm run build:server
100
101 transcodingFiles=$(findTestFiles ./dist/server/tests/api/transcoding)
102
103 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $transcodingFiles
104 elif [ "$1" = "external-plugins" ]; then
105 npm run build:server
106
107 externalPluginsFiles=$(findTestFiles ./dist/server/tests/external-plugins)
108
109 runTest "$1" 1 $externalPluginsFiles
110 elif [ "$1" = "lint" ]; then
111 npm run eslint -- --ext .ts "./server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts"
112 npm run swagger-cli -- validate support/doc/api/openapi.yaml
113
114 ( cd client
115 npm run lint
116 )
117 fi