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