aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/ci.sh
blob: 64968cf943da7012463550df0196117525e7a3fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash

set -eu

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

retries=3
speedFactor="${2:-1}"

runJSTest () {
    jobname=$1
    shift

    jobs=$1
    shift

    files=$@

    echo $files

    joblog="$jobname-ci.log"

    parallel -j $jobs --retries $retries \
        "echo Trying {} >> $joblog; npm run mocha -- --timeout 30000 --no-config -c --exit --bail {}" \
        ::: $files

    cat "$joblog" | sort | uniq -c
    rm "$joblog"
}

findTestFiles () {
    exception="-not -name index.js -not -name index.ts -not -name *.d.ts"

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

    find $1 -type f \( -name "*.js" -o -name "*.ts" \) $exception | xargs echo
}

if [ "$1" = "types-package" ]; then
    npm run generate-types-package 0.0.0

    # Test on in independent directory
    rm -fr /tmp/types-generator
    mkdir -p /tmp/types-generator
    cp -r packages/types-generator/tests /tmp/types-generator/tests
    cp -r packages/types-generator/dist /tmp/types-generator/dist
    (cd /tmp/types-generator/dist && npm install)

    npm run tsc -- --noEmit --esModuleInterop --moduleResolution node16 /tmp/types-generator/tests/test.ts
    rm -r /tmp/types-generator
elif [ "$1" = "client" ]; then
    npm run build
    npm run build:tests

    feedsFiles=$(findTestFiles ./packages/tests/dist/feeds)
    miscFiles="./packages/tests/dist/client.js ./packages/tests/dist/misc-endpoints.js"
    # Not in their own task, they need an index.html
    pluginFiles="./packages/tests/dist/plugins/html-injection.js ./packages/tests/dist/api/server/plugins.js"

    MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $feedsFiles $miscFiles $pluginFiles

    # Use TS tests directly because we import server files
    helperFiles=$(findTestFiles ./packages/tests/src/server-helpers)
    libFiles=$(findTestFiles ./packages/tests/src/server-lib)

    npm run mocha -- --timeout 30000 -c --exit --bail $libFiles $helperFiles
elif [ "$1" = "cli-plugin" ]; then
    # Simulate HTML
    mkdir -p "./client/dist/en-US/"
    cp "./client/src/index.html" "./client/dist/en-US/index.html"

    npm run build:server
    npm run build:tests
    npm run build:peertube-cli

    # html-injection test needs an HTML file
    pluginsFiles=$(findTestFiles ./packages/tests/dist/plugins html-injection.js)
    cliFiles=$(findTestFiles ./packages/tests/dist/cli)

    MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $pluginsFiles
    runJSTest "$1" 1 $cliFiles
elif [ "$1" = "api-1" ]; then
    npm run build:server
    npm run build:tests

    checkParamFiles=$(findTestFiles ./packages/tests/dist/api/check-params)
    notificationsFiles=$(findTestFiles ./packages/tests/dist/api/notifications)
    searchFiles=$(findTestFiles ./packages/tests/dist/api/search)

    MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $notificationsFiles $searchFiles $checkParamFiles
elif [ "$1" = "api-2" ]; then
    npm run build:server
    npm run build:tests

    liveFiles=$(findTestFiles ./packages/tests/dist/api/live)
    # plugins test needs an HTML file
    serverFiles=$(findTestFiles ./packages/tests/dist/api/server plugins.js)
    usersFiles=$(findTestFiles ./packages/tests/dist/api/users)

    MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $liveFiles $serverFiles $usersFiles
elif [ "$1" = "api-3" ]; then
    npm run build:server
    npm run build:tests

    videosFiles=$(findTestFiles ./packages/tests/dist/api/videos)
    viewsFiles=$(findTestFiles ./packages/tests/dist/api/views)

    MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $viewsFiles $videosFiles
elif [ "$1" = "api-4" ]; then
    npm run build:server
    npm run build:tests

    moderationFiles=$(findTestFiles ./packages/tests/dist/api/moderation)
    redundancyFiles=$(findTestFiles ./packages/tests/dist/api/redundancy)
    objectStorageFiles=$(findTestFiles ./packages/tests/dist/api/object-storage)
    activitypubFiles=$(findTestFiles ./packages/tests/dist/api/activitypub)

    MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $moderationFiles $redundancyFiles $activitypubFiles $objectStorageFiles
elif [ "$1" = "api-5" ]; then
    npm run build:server
    npm run build:tests

    transcodingFiles=$(findTestFiles ./packages/tests/dist/api/transcoding)
    runnersFiles=$(findTestFiles ./packages/tests/dist/api/runners)

    MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $transcodingFiles $runnersFiles
elif [ "$1" = "external-plugins" ]; then
    npm run build:server
    npm run build:tests
    npm run build:peertube-runner

    externalPluginsFiles=$(findTestFiles ./packages/tests/dist/external-plugins)
    peertubeRunnerFiles=$(findTestFiles ./packages/tests/dist/peertube-runner)

    runJSTest "$1" 1 $externalPluginsFiles
    MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $peertubeRunnerFiles
elif [ "$1" = "lint" ]; then
    npm run eslint -- --ext .ts "server/**/*.ts"  "scripts/**/*.ts" "packages/**/*.ts" "apps/**/*.ts"

    npm run swagger-cli -- validate support/doc/api/openapi.yaml

    ( cd client
      npm run lint
    )
fi