]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/ci.sh
Merge branch 'master' into release/3.3.0
[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 killall -q peertube || true
11
12 retries=3
13
14 runTest () {
15 jobname=$1
16 shift
17
18 jobs=$1
19 shift
20
21 files=$@
22
23 echo $files
24
25 joblog="$jobname-ci.log"
26
27 parallel -j $jobs --retries $retries \
28 "echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --require ./dist/server/tests/register.js --bail {}" \
29 ::: $files
30
31 cat "$joblog" | uniq -c
32 rm "$joblog"
33 }
34
35 findTestFiles () {
36 exception="-not -name index.js"
37
38 if [ ! -z ${2+x} ]; then
39 exception="$exception -not -name $2"
40 fi
41
42 find $1 -type f -name "*.js" $exception | xargs echo
43 }
44
45 if [ "$1" = "client" ]; then
46 npm run build
47
48 feedsFiles=$(findTestFiles ./dist/server/tests/feeds)
49 helperFiles=$(findTestFiles ./dist/server/tests/helpers)
50 miscFiles="./dist/server/tests/client.js ./dist/server/tests/misc-endpoints.js"
51 # Not in plugin task, it needs an index.html
52 pluginFiles="./dist/server/tests/plugins/html-injection.js"
53
54 MOCHA_PARALLEL=true runTest "$1" 2 $feedsFiles $helperFiles $miscFiles $pluginFiles
55 elif [ "$1" = "cli-plugin" ]; then
56 npm run build:server
57 npm run setup:cli
58
59 pluginsFiles=$(findTestFiles ./dist/server/tests/plugins html-injection.js)
60 cliFiles=$(findTestFiles ./dist/server/tests/cli)
61
62 MOCHA_PARALLEL=true runTest "$1" 2 $pluginsFiles
63 runTest "$1" 1 $cliFiles
64 elif [ "$1" = "api-1" ]; then
65 npm run build:server
66
67 checkParamFiles=$(findTestFiles ./dist/server/tests/api/check-params)
68 notificationsFiles=$(findTestFiles ./dist/server/tests/api/notifications)
69 searchFiles=$(findTestFiles ./dist/server/tests/api/search)
70
71 MOCHA_PARALLEL=true runTest "$1" 3 $notificationsFiles $searchFiles $checkParamFiles
72 elif [ "$1" = "api-2" ]; then
73 npm run build:server
74
75 liveFiles=$(findTestFiles ./dist/server/tests/api/live)
76 serverFiles=$(findTestFiles ./dist/server/tests/api/server)
77 usersFiles=$(findTestFiles ./dist/server/tests/api/users)
78
79 MOCHA_PARALLEL=true runTest "$1" 3 $serverFiles $usersFiles $liveFiles
80 elif [ "$1" = "api-3" ]; then
81 npm run build:server
82
83 videosFiles=$(findTestFiles ./dist/server/tests/api/videos)
84
85 MOCHA_PARALLEL=true runTest "$1" 3 $videosFiles
86 elif [ "$1" = "api-4" ]; then
87 npm run build:server
88
89 moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation)
90 redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy)
91 activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub)
92
93 MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $moderationFiles $redundancyFiles $activitypubFiles
94 elif [ "$1" = "external-plugins" ]; then
95 npm run build:server
96
97 externalPluginsFiles=$(findTestFiles ./dist/server/tests/external-plugins)
98
99 runTest "$1" 1 $externalPluginsFiles
100 elif [ "$1" = "lint" ]; then
101 npm run eslint -- --ext .ts "./server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts"
102 npm run swagger-cli -- validate support/doc/api/openapi.yaml
103
104 ( cd client
105 npm run lint
106 )
107 fi