ci.sh 3.1 KB
Newer Older
Chocobozzz's avatar
Chocobozzz committed
1
#!/bin/bash
Léo Andrès's avatar
Léo Andrès committed
2
3

set -eu
4
5
6
7
8
9

if [ $# -eq 0 ]; then
    echo "Need test suite argument."
    exit -1
fi

Chocobozzz's avatar
Chocobozzz committed
10
11
killall -q peertube || true

12
13
14
retries=3

runTest () {
Chocobozzz's avatar
Chocobozzz committed
15
16
17
    jobname=$1
    shift

18
19
    jobs=$1
    shift
Chocobozzz's avatar
Chocobozzz committed
20

21
22
23
24
    files=$@

    echo $files

Chocobozzz's avatar
Chocobozzz committed
25
26
    joblog="$jobname-ci.log"

Chocobozzz's avatar
Chocobozzz committed
27
    parallel -j $jobs --retries $retries \
Chocobozzz's avatar
Chocobozzz committed
28
        "echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --require ./dist/server/tests/register.js --bail {}" \
29
        ::: $files
Chocobozzz's avatar
Chocobozzz committed
30

Chocobozzz's avatar
Chocobozzz committed
31
    cat "$joblog" | uniq -c
Chocobozzz's avatar
Chocobozzz committed
32
    rm "$joblog"
33
34
35
}

findTestFiles () {
Chocobozzz's avatar
Chocobozzz committed
36
37
38
39
40
41
42
    exception="-not -name index.js"

    if [ ! -z ${2+x} ]; then
        exception="$exception -not -name $2"
    fi

    find $1 -type f -name "*.js" $exception | xargs echo
43
}
44

Chocobozzz's avatar
Chocobozzz committed
45
if [ "$1" = "client" ]; then
Chocobozzz's avatar
Chocobozzz committed
46
    npm run build
47

Chocobozzz's avatar
Chocobozzz committed
48
49
    feedsFiles=$(findTestFiles ./dist/server/tests/feeds)
    helperFiles=$(findTestFiles ./dist/server/tests/helpers)
Chocobozzz's avatar
Chocobozzz committed
50
    libFiles=$(findTestFiles ./dist/server/tests/lib)
Chocobozzz's avatar
Chocobozzz committed
51
    miscFiles="./dist/server/tests/client.js ./dist/server/tests/misc-endpoints.js"
Chocobozzz's avatar
Chocobozzz committed
52
53
    # Not in plugin task, it needs an index.html
    pluginFiles="./dist/server/tests/plugins/html-injection.js"
54

Chocobozzz's avatar
Chocobozzz committed
55
    MOCHA_PARALLEL=true runTest "$1" 2 $feedsFiles $helperFiles $miscFiles $pluginFiles $libFiles
Chocobozzz's avatar
Chocobozzz committed
56
elif [ "$1" = "cli-plugin" ]; then
57
    npm run build:server
Chocobozzz's avatar
Chocobozzz committed
58
    npm run setup:cli
59

Chocobozzz's avatar
Chocobozzz committed
60
    pluginsFiles=$(findTestFiles ./dist/server/tests/plugins html-injection.js)
Chocobozzz's avatar
Chocobozzz committed
61
    cliFiles=$(findTestFiles ./dist/server/tests/cli)
62

Chocobozzz's avatar
Chocobozzz committed
63
    MOCHA_PARALLEL=true runTest "$1" 2 $pluginsFiles
Chocobozzz's avatar
Chocobozzz committed
64
    runTest "$1" 1 $cliFiles
Chocobozzz's avatar
Chocobozzz committed
65
elif [ "$1" = "api-1" ]; then
66
    npm run build:server
67

Chocobozzz's avatar
Chocobozzz committed
68
69
70
    checkParamFiles=$(findTestFiles ./dist/server/tests/api/check-params)
    notificationsFiles=$(findTestFiles ./dist/server/tests/api/notifications)
    searchFiles=$(findTestFiles ./dist/server/tests/api/search)
71

Chocobozzz's avatar
Chocobozzz committed
72
    MOCHA_PARALLEL=true runTest "$1" 3 $notificationsFiles $searchFiles $checkParamFiles
Chocobozzz's avatar
Chocobozzz committed
73
elif [ "$1" = "api-2" ]; then
74
    npm run build:server
75

Chocobozzz's avatar
Chocobozzz committed
76
    liveFiles=$(findTestFiles ./dist/server/tests/api/live)
Chocobozzz's avatar
Chocobozzz committed
77
78
    serverFiles=$(findTestFiles ./dist/server/tests/api/server)
    usersFiles=$(findTestFiles ./dist/server/tests/api/users)
79

Chocobozzz's avatar
Chocobozzz committed
80
    MOCHA_PARALLEL=true runTest "$1" 3 $serverFiles $usersFiles $liveFiles
Chocobozzz's avatar
Chocobozzz committed
81
82
elif [ "$1" = "api-3" ]; then
    npm run build:server
83

Chocobozzz's avatar
Chocobozzz committed
84
    videosFiles=$(findTestFiles ./dist/server/tests/api/videos)
85

Chocobozzz's avatar
Chocobozzz committed
86
    MOCHA_PARALLEL=true runTest "$1" 3 $videosFiles
Chocobozzz's avatar
Chocobozzz committed
87
elif [ "$1" = "api-4" ]; then
Chocobozzz's avatar
Chocobozzz committed
88
    npm run build:server
89

Chocobozzz's avatar
Chocobozzz committed
90
91
92
    moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation)
    redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy)
    activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub)
93

Chocobozzz's avatar
Chocobozzz committed
94
    MOCHA_PARALLEL=true TS_NODE_FILES=true runTest "$1" 2 $moderationFiles $redundancyFiles $activitypubFiles
Chocobozzz's avatar
Chocobozzz committed
95
96
elif [ "$1" = "external-plugins" ]; then
    npm run build:server
97

Chocobozzz's avatar
Chocobozzz committed
98
    externalPluginsFiles=$(findTestFiles ./dist/server/tests/external-plugins)
99

Chocobozzz's avatar
Chocobozzz committed
100
    runTest "$1" 1 $externalPluginsFiles
101
elif [ "$1" = "lint" ]; then
Chocobozzz's avatar
Chocobozzz committed
102
    npm run eslint -- --ext .ts "./server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts"
Chocobozzz's avatar
Chocobozzz committed
103
    npm run swagger-cli -- validate support/doc/api/openapi.yaml
Chocobozzz's avatar
Chocobozzz committed
104

Léo Andrès's avatar
Léo Andrès committed
105
106
107
    ( cd client
      npm run lint
    )
108
fi