aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/ci.sh
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /scripts/ci.sh
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'scripts/ci.sh')
-rwxr-xr-xscripts/ci.sh104
1 files changed, 64 insertions, 40 deletions
diff --git a/scripts/ci.sh b/scripts/ci.sh
index 9fb67f634..64968cf94 100755
--- a/scripts/ci.sh
+++ b/scripts/ci.sh
@@ -10,7 +10,7 @@ fi
10retries=3 10retries=3
11speedFactor="${2:-1}" 11speedFactor="${2:-1}"
12 12
13runTest () { 13runJSTest () {
14 jobname=$1 14 jobname=$1
15 shift 15 shift
16 16
@@ -24,7 +24,7 @@ runTest () {
24 joblog="$jobname-ci.log" 24 joblog="$jobname-ci.log"
25 25
26 parallel -j $jobs --retries $retries \ 26 parallel -j $jobs --retries $retries \
27 "echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --bail {}" \ 27 "echo Trying {} >> $joblog; npm run mocha -- --timeout 30000 --no-config -c --exit --bail {}" \
28 ::: $files 28 ::: $files
29 29
30 cat "$joblog" | sort | uniq -c 30 cat "$joblog" | sort | uniq -c
@@ -32,92 +32,116 @@ runTest () {
32} 32}
33 33
34findTestFiles () { 34findTestFiles () {
35 exception="-not -name index.js" 35 exception="-not -name index.js -not -name index.ts -not -name *.d.ts"
36 36
37 if [ ! -z ${2+x} ]; then 37 if [ ! -z ${2+x} ]; then
38 exception="$exception -not -name $2" 38 exception="$exception -not -name $2"
39 fi 39 fi
40 40
41 find $1 -type f -name "*.js" $exception | xargs echo 41 find $1 -type f \( -name "*.js" -o -name "*.ts" \) $exception | xargs echo
42} 42}
43 43
44if [ "$1" = "types-package" ]; then 44if [ "$1" = "types-package" ]; then
45 npm run generate-types-package 0.0.0 45 npm run generate-types-package 0.0.0
46 npm run tsc -- --noEmit --esModuleInterop packages/types/tests/test.ts 46
47 # Test on in independent directory
48 rm -fr /tmp/types-generator
49 mkdir -p /tmp/types-generator
50 cp -r packages/types-generator/tests /tmp/types-generator/tests
51 cp -r packages/types-generator/dist /tmp/types-generator/dist
52 (cd /tmp/types-generator/dist && npm install)
53
54 npm run tsc -- --noEmit --esModuleInterop --moduleResolution node16 /tmp/types-generator/tests/test.ts
55 rm -r /tmp/types-generator
47elif [ "$1" = "client" ]; then 56elif [ "$1" = "client" ]; then
48 npm run build 57 npm run build
58 npm run build:tests
49 59
50 feedsFiles=$(findTestFiles ./dist/server/tests/feeds) 60 feedsFiles=$(findTestFiles ./packages/tests/dist/feeds)
51 helperFiles=$(findTestFiles ./dist/server/tests/helpers) 61 miscFiles="./packages/tests/dist/client.js ./packages/tests/dist/misc-endpoints.js"
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 62 # 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" 63 pluginFiles="./packages/tests/dist/plugins/html-injection.js ./packages/tests/dist/api/server/plugins.js"
64
65 MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $feedsFiles $miscFiles $pluginFiles
56 66
57 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $feedsFiles $helperFiles $miscFiles $pluginFiles $libFiles 67 # Use TS tests directly because we import server files
68 helperFiles=$(findTestFiles ./packages/tests/src/server-helpers)
69 libFiles=$(findTestFiles ./packages/tests/src/server-lib)
70
71 npm run mocha -- --timeout 30000 -c --exit --bail $libFiles $helperFiles
58elif [ "$1" = "cli-plugin" ]; then 72elif [ "$1" = "cli-plugin" ]; then
59 # Simulate HTML 73 # Simulate HTML
60 mkdir -p "./client/dist/en-US/" 74 mkdir -p "./client/dist/en-US/"
61 cp "./client/src/index.html" "./client/dist/en-US/index.html" 75 cp "./client/src/index.html" "./client/dist/en-US/index.html"
62 76
63 npm run build:server 77 npm run build:server
64 npm run setup:cli 78 npm run build:tests
79 npm run build:peertube-cli
65 80
66 pluginsFiles=$(findTestFiles ./dist/server/tests/plugins html-injection.js) 81 # html-injection test needs an HTML file
67 cliFiles=$(findTestFiles ./dist/server/tests/cli) 82 pluginsFiles=$(findTestFiles ./packages/tests/dist/plugins html-injection.js)
83 cliFiles=$(findTestFiles ./packages/tests/dist/cli)
68 84
69 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $pluginsFiles 85 MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $pluginsFiles
70 runTest "$1" 1 $cliFiles 86 runJSTest "$1" 1 $cliFiles
71elif [ "$1" = "api-1" ]; then 87elif [ "$1" = "api-1" ]; then
72 npm run build:server 88 npm run build:server
89 npm run build:tests
73 90
74 checkParamFiles=$(findTestFiles ./dist/server/tests/api/check-params) 91 checkParamFiles=$(findTestFiles ./packages/tests/dist/api/check-params)
75 notificationsFiles=$(findTestFiles ./dist/server/tests/api/notifications) 92 notificationsFiles=$(findTestFiles ./packages/tests/dist/api/notifications)
76 searchFiles=$(findTestFiles ./dist/server/tests/api/search) 93 searchFiles=$(findTestFiles ./packages/tests/dist/api/search)
77 94
78 MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $notificationsFiles $searchFiles $checkParamFiles 95 MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $notificationsFiles $searchFiles $checkParamFiles
79elif [ "$1" = "api-2" ]; then 96elif [ "$1" = "api-2" ]; then
80 npm run build:server 97 npm run build:server
98 npm run build:tests
81 99
82 liveFiles=$(findTestFiles ./dist/server/tests/api/live) 100 liveFiles=$(findTestFiles ./packages/tests/dist/api/live)
83 serverFiles=$(findTestFiles ./dist/server/tests/api/server plugins.js) 101 # plugins test needs an HTML file
84 usersFiles=$(findTestFiles ./dist/server/tests/api/users) 102 serverFiles=$(findTestFiles ./packages/tests/dist/api/server plugins.js)
103 usersFiles=$(findTestFiles ./packages/tests/dist/api/users)
85 104
86 MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $liveFiles $serverFiles $usersFiles 105 MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $liveFiles $serverFiles $usersFiles
87elif [ "$1" = "api-3" ]; then 106elif [ "$1" = "api-3" ]; then
88 npm run build:server 107 npm run build:server
108 npm run build:tests
89 109
90 videosFiles=$(findTestFiles ./dist/server/tests/api/videos) 110 videosFiles=$(findTestFiles ./packages/tests/dist/api/videos)
91 viewsFiles=$(findTestFiles ./dist/server/tests/api/views) 111 viewsFiles=$(findTestFiles ./packages/tests/dist/api/views)
92 112
93 MOCHA_PARALLEL=true runTest "$1" $((3*$speedFactor)) $viewsFiles $videosFiles 113 MOCHA_PARALLEL=true runJSTest "$1" $((3*$speedFactor)) $viewsFiles $videosFiles
94elif [ "$1" = "api-4" ]; then 114elif [ "$1" = "api-4" ]; then
95 npm run build:server 115 npm run build:server
116 npm run build:tests
96 117
97 moderationFiles=$(findTestFiles ./dist/server/tests/api/moderation) 118 moderationFiles=$(findTestFiles ./packages/tests/dist/api/moderation)
98 redundancyFiles=$(findTestFiles ./dist/server/tests/api/redundancy) 119 redundancyFiles=$(findTestFiles ./packages/tests/dist/api/redundancy)
99 objectStorageFiles=$(findTestFiles ./dist/server/tests/api/object-storage) 120 objectStorageFiles=$(findTestFiles ./packages/tests/dist/api/object-storage)
100 activitypubFiles=$(findTestFiles ./dist/server/tests/api/activitypub) 121 activitypubFiles=$(findTestFiles ./packages/tests/dist/api/activitypub)
101 122
102 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $moderationFiles $redundancyFiles $activitypubFiles $objectStorageFiles 123 MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $moderationFiles $redundancyFiles $activitypubFiles $objectStorageFiles
103elif [ "$1" = "api-5" ]; then 124elif [ "$1" = "api-5" ]; then
104 npm run build:server 125 npm run build:server
126 npm run build:tests
105 127
106 transcodingFiles=$(findTestFiles ./dist/server/tests/api/transcoding) 128 transcodingFiles=$(findTestFiles ./packages/tests/dist/api/transcoding)
107 runnersFiles=$(findTestFiles ./dist/server/tests/api/runners) 129 runnersFiles=$(findTestFiles ./packages/tests/dist/api/runners)
108 130
109 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $transcodingFiles $runnersFiles 131 MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $transcodingFiles $runnersFiles
110elif [ "$1" = "external-plugins" ]; then 132elif [ "$1" = "external-plugins" ]; then
111 npm run build:server 133 npm run build:server
134 npm run build:tests
112 npm run build:peertube-runner 135 npm run build:peertube-runner
113 136
114 externalPluginsFiles=$(findTestFiles ./dist/server/tests/external-plugins) 137 externalPluginsFiles=$(findTestFiles ./packages/tests/dist/external-plugins)
115 peertubeRunnerFiles=$(findTestFiles ./dist/server/tests/peertube-runner) 138 peertubeRunnerFiles=$(findTestFiles ./packages/tests/dist/peertube-runner)
116 139
117 runTest "$1" 1 $externalPluginsFiles 140 runJSTest "$1" 1 $externalPluginsFiles
118 MOCHA_PARALLEL=true runTest "$1" $((2*$speedFactor)) $peertubeRunnerFiles 141 MOCHA_PARALLEL=true runJSTest "$1" $((2*$speedFactor)) $peertubeRunnerFiles
119elif [ "$1" = "lint" ]; then 142elif [ "$1" = "lint" ]; then
120 npm run eslint -- --ext .ts "./server/**/*.ts" "shared/**/*.ts" "scripts/**/*.ts" 143 npm run eslint -- --ext .ts "server/**/*.ts" "scripts/**/*.ts" "packages/**/*.ts" "apps/**/*.ts"
144
121 npm run swagger-cli -- validate support/doc/api/openapi.yaml 145 npm run swagger-cli -- validate support/doc/api/openapi.yaml
122 146
123 ( cd client 147 ( cd client