Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bb30510

Browse files
committedFeb 4, 2020
Add linting steps and improve testing steps
1 parent b29346e commit bb30510

File tree

7 files changed

+173
-86
lines changed

7 files changed

+173
-86
lines changed
 

‎.drone.yml

+89-53
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,29 @@ platform:
66
arch: amd64
77

88
steps:
9-
- name: submodules
10-
image: alpine/git
9+
- name: cache:restore
10+
image: codercom/nbin:centos
1111
commands:
12-
- git submodule update --init
12+
- yum install -y libxkbfile-devel libsecret-devel
13+
- . /opt/rh/devtoolset-6/enable
14+
- ./scripts/cacher.sh
1315

14-
- name: cache:restore
16+
- name: lint
1517
image: node:12
1618
commands:
17-
- ./scripts/cacher.sh
19+
- yarn lint
20+
21+
- name: test
22+
image: codercom/nbin:centos
23+
commands:
24+
- yarn test
1825

1926
- name: build
2027
image: codercom/nbin:centos
2128
commands:
2229
- yum install -y libxkbfile-devel libsecret-devel
2330
- . /opt/rh/devtoolset-6/enable
24-
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing so we can preserve cache for the next run'
31+
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing to preserve cache for the next run'
2532

2633
- name: cache:package
2734
image: node:12
@@ -40,10 +47,10 @@ steps:
4047
when:
4148
event: push
4249

43-
- name: test
44-
image: node:12
50+
- name: test:build
51+
image: codercom/nbin:centos
4552
commands:
46-
- yarn test
53+
- yarn test:build
4754

4855
- name: publish:github
4956
image: plugins/github-release
@@ -90,21 +97,28 @@ platform:
9097
arch: amd64
9198

9299
steps:
93-
- name: submodules
94-
image: alpine/git
95-
commands:
96-
- git submodule update --init
97-
98100
- name: cache:restore
99101
image: node:12-alpine
100102
commands:
103+
- apk add libxkbfile-dev libsecret-dev build-base git bash python
101104
- ./scripts/cacher.sh
102105

106+
- name: lint
107+
image: node:12-alpine
108+
commands:
109+
- yarn lint
110+
111+
- name: test
112+
image: node:12-alpine
113+
commands:
114+
- apk add openssl
115+
- yarn test
116+
103117
- name: build
104118
image: node:12-alpine
105119
commands:
106120
- apk add libxkbfile-dev libsecret-dev build-base git bash python
107-
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing so we can preserve cache for the next run'
121+
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing to preserve cache for the next run'
108122

109123
- name: cache:package
110124
image: node:12-alpine
@@ -123,10 +137,10 @@ steps:
123137
when:
124138
event: push
125139

126-
- name: test
140+
- name: test:build
127141
image: node:12-alpine
128142
commands:
129-
- yarn test
143+
- yarn test:build
130144

131145
- name: publish:github
132146
image: plugins/github-release
@@ -159,22 +173,27 @@ platform:
159173
arch: arm64
160174

161175
steps:
162-
- name: submodules
163-
image: alpine
164-
commands:
165-
- apk add git
166-
- git submodule update --init
167-
168176
- name: cache:restore
169177
image: node:12
170178
commands:
179+
- apt update && apt install -y build-essential git libsecret-1-dev libx11-dev libxkbfile-dev
171180
- ./scripts/cacher.sh
172181

182+
- name: lint
183+
image: node:12
184+
commands:
185+
- yarn lint
186+
187+
- name: test
188+
image: node:12
189+
commands:
190+
- yarn test
191+
173192
- name: build
174193
image: node:12
175194
commands:
176195
- apt update && apt install -y build-essential git libsecret-1-dev libx11-dev libxkbfile-dev
177-
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing so we can preserve cache for the next run'
196+
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing to preserve cache for the next run'
178197

179198
- name: cache:package
180199
image: node:12
@@ -193,10 +212,10 @@ steps:
193212
when:
194213
event: push
195214

196-
- name: test
215+
- name: test:build
197216
image: node:12
198217
commands:
199-
- yarn test
218+
- yarn test:build
200219

201220
- name: publish:github
202221
image: plugins/github-release
@@ -243,22 +262,28 @@ platform:
243262
arch: arm64
244263

245264
steps:
246-
- name: submodules
247-
image: alpine
248-
commands:
249-
- apk add git
250-
- git submodule update --init
251-
252265
- name: cache:restore
253266
image: node:12-alpine
254267
commands:
268+
- apk add libxkbfile-dev libsecret-dev build-base git bash python
255269
- ./scripts/cacher.sh
256270

271+
- name: lint
272+
image: node:12-alpine
273+
commands:
274+
- yarn lint
275+
276+
- name: test
277+
image: node:12-alpine
278+
commands:
279+
- apk add openssl
280+
- yarn test
281+
257282
- name: build
258283
image: node:12-alpine
259284
commands:
260285
- apk add libxkbfile-dev libsecret-dev build-base git bash python
261-
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing so we can preserve cache for the next run'
286+
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing to preserve cache for the next run'
262287

263288
- name: cache:package
264289
image: node:12-alpine
@@ -277,10 +302,10 @@ steps:
277302
when:
278303
event: push
279304

280-
- name: test
305+
- name: test:build
281306
image: node:12-alpine
282307
commands:
283-
- yarn test
308+
- yarn test:build
284309

285310
- name: publish:github
286311
image: plugins/github-release
@@ -313,22 +338,27 @@ platform:
313338
arch: arm
314339

315340
steps:
316-
- name: submodules
317-
image: alpine
318-
commands:
319-
- apk add git
320-
- git submodule update --init
321-
322341
- name: cache:restore
323342
image: node:12
324343
commands:
344+
- apt update && apt install -y build-essential git libsecret-1-dev libx11-dev libxkbfile-dev
325345
- ./scripts/cacher.sh
326346

347+
- name: lint
348+
image: node:12
349+
commands:
350+
- yarn lint
351+
352+
- name: test
353+
image: node:12
354+
commands:
355+
- yarn test
356+
327357
- name: build
328358
image: node:12
329359
commands:
330360
- apt update && apt install -y build-essential git libsecret-1-dev libx11-dev libxkbfile-dev
331-
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing so we can preserve cache for the next run'
361+
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing to preserve cache for the next run'
332362

333363
- name: cache:package
334364
image: node:12
@@ -347,11 +377,11 @@ steps:
347377
when:
348378
event: push
349379

350-
- name: test
380+
- name: test:build
351381
image: node:12
352382
failure: ignore
353383
commands:
354-
- yarn test
384+
- yarn test:build
355385

356386
# - name: publish:github
357387
# image: plugins/github-release
@@ -388,22 +418,28 @@ platform:
388418
arch: arm
389419

390420
steps:
391-
- name: submodules
392-
image: alpine
393-
commands:
394-
- apk add git
395-
- git submodule update --init
396-
397421
- name: cache:restore
398422
image: node:12-alpine
399423
commands:
424+
- apk add libxkbfile-dev libsecret-dev build-base git bash python
400425
- ./scripts/cacher.sh
401426

427+
- name: lint
428+
image: node:12-alpine
429+
commands:
430+
- yarn lint
431+
432+
- name: test
433+
image: node:12-alpine
434+
commands:
435+
- apk add openssl
436+
- yarn test
437+
402438
- name: build
403439
image: node:12-alpine
404440
commands:
405441
- apk add libxkbfile-dev libsecret-dev build-base git bash python
406-
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing so we can preserve cache for the next run'
442+
- timeout 50m ./scripts/ci.bash || echo 'Timed out or failed; continuing to preserve cache for the next run'
407443

408444
- name: cache:package
409445
image: node:12-alpine
@@ -422,11 +458,11 @@ steps:
422458
when:
423459
event: push
424460

425-
- name: test
461+
- name: test:build
426462
image: node:12-alpine
427463
failure: ignore
428464
commands:
429-
- yarn test
465+
- yarn test:build
430466

431467
# - name: publish:github
432468
# image: plugins/github-release

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"patch:generate": "cd ./lib/vscode && git diff HEAD > ../../scripts/vscode.patch",
1010
"patch:apply": "cd ./lib/vscode && git apply ../../scripts/vscode.patch",
1111
"test": "mocha -r ts-node/register ./test/*.test.ts",
12-
"lint:js": "eslint {src,test,scripts} --ext .ts,.tsx",
12+
"test:build": "./scripts/test.sh",
13+
"lint:js": "eslint src test scripts --ext .ts,.tsx",
1314
"lint:css": "stylelint 'src/**/*.css'",
1415
"lint": "./scripts/lint.sh",
1516
"watch": "yarn runner watch",

‎scripts/cacher.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,18 @@ main() {
4646

4747
# The action is determined by the name of the step.
4848
case $DRONE_STEP_NAME in
49-
*restore*) restore "$branch" "$DRONE_REPO_BRANCH" ;;
49+
*restore*)
50+
# Sub-modules must be pulled first since extracting the cache directories
51+
# will prevent git from cloning into them.
52+
git submodule update --init
53+
54+
restore "$branch" "$DRONE_REPO_BRANCH"
55+
56+
# Now make sure the pulled Node modules are up to date.
57+
YARN_CACHE_FOLDER="$(pwd)/yarn-cache"
58+
export YARN_CACHE_FOLDER
59+
yarn
60+
;;
5061
*rebuild*|*package*) package "$branch" ;;
5162
*) exit 1 ;;
5263
esac

‎scripts/ci.bash

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
set -euo pipefail
55

6+
# This script assumes that yarn has already ran.
67
function main() {
78
cd "$(dirname "${0}")/.."
89

@@ -21,10 +22,6 @@ function main() {
2122
export PACKAGE="true"
2223
fi
2324

24-
if [[ -z ${SKIP_YARN:-} ]] ; then
25-
yarn
26-
fi
27-
2825
yarn build
2926
yarn binary
3027
if [[ -n ${PACKAGE:-} ]] ; then

‎scripts/test.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env sh
2+
# test.sh -- Simple build test.
3+
4+
set -eu
5+
6+
main() {
7+
cd "$(dirname "$0")/.."
8+
9+
# The main goal here is to ensure that the build fully completed and the
10+
# result looks usable.
11+
version=$(node ./build/out/node/entry.js --version --json)
12+
echo "Got '$version' for the version"
13+
case $version in
14+
"{ codeServer":*) exit 0 ;;
15+
*) exit 1 ;;
16+
esac
17+
}
18+
19+
main "$@"

‎src/node/entry.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const main = async (args: Args = {}): Promise<void> => {
4949
new VscodeHttpProvider([], { base: "/vscode-embed", auth, password })
5050
)
5151

52-
ipcMain.onDispose(() => httpServer.dispose())
52+
ipcMain().onDispose(() => httpServer.dispose())
5353

5454
const serverAddress = await httpServer.listen()
5555
logger.info(`Server listening on ${serverAddress}`)
@@ -84,4 +84,18 @@ const main = async (args: Args = {}): Promise<void> => {
8484
}
8585
}
8686

87-
wrap(main)
87+
// TODO: Implement CLI parser.
88+
if (process.argv.includes("--version")) {
89+
const version = require("../../package.json").version
90+
if (process.argv.includes("--json")) {
91+
console.log({
92+
codeServer: version,
93+
vscode: require("../../lib/vscode/package.json").version,
94+
})
95+
} else {
96+
console.log(version)
97+
}
98+
process.exit(0)
99+
} else {
100+
wrap(main)
101+
}

‎src/node/wrapper.ts

+34-25
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ export class ProcessError extends Error {
2121
}
2222
}
2323

24-
/**
25-
* Ensure we control when the process exits.
26-
*/
27-
const exit = process.exit
28-
process.exit = function(code?: number) {
29-
logger.warn(`process.exit() was prevented: ${code || "unknown code"}.`)
30-
} as (code?: number) => never
31-
3224
/**
3325
* Allows the wrapper and inner processes to communicate.
3426
*/
@@ -37,19 +29,26 @@ export class IpcMain {
3729
public readonly onMessage = this._onMessage.event
3830
private readonly _onDispose = new Emitter<NodeJS.Signals | undefined>()
3931
public readonly onDispose = this._onDispose.event
32+
public readonly exit: (code?: number) => never
4033

4134
public constructor(public readonly parentPid?: number) {
4235
process.on("SIGINT", () => this._onDispose.emit("SIGINT"))
4336
process.on("SIGTERM", () => this._onDispose.emit("SIGTERM"))
4437
process.on("exit", () => this._onDispose.emit(undefined))
4538

39+
// Ensure we control when the process exits.
40+
this.exit = process.exit
41+
process.exit = function(code?: number) {
42+
logger.warn(`process.exit() was prevented: ${code || "unknown code"}.`)
43+
} as (code?: number) => never
44+
4645
this.onDispose((signal) => {
4746
// Remove listeners to avoid possibly triggering disposal again.
4847
process.removeAllListeners()
4948

5049
// Let any other handlers run first then exit.
5150
logger.debug(`${parentPid ? "inner process" : "wrapper"} ${process.pid} disposing`, field("code", signal))
52-
setTimeout(() => exit(0), 0)
51+
setTimeout(() => this.exit(0), 0)
5352
})
5453

5554
// Kill the inner process if the parent dies. This is for the case where the
@@ -117,9 +116,17 @@ export class IpcMain {
117116
}
118117
}
119118

120-
export const ipcMain = new IpcMain(
121-
typeof process.env.CODE_SERVER_PARENT_PID !== "undefined" ? parseInt(process.env.CODE_SERVER_PARENT_PID) : undefined
122-
)
119+
let _ipcMain: IpcMain
120+
export const ipcMain = (): IpcMain => {
121+
if (!_ipcMain) {
122+
_ipcMain = new IpcMain(
123+
typeof process.env.CODE_SERVER_PARENT_PID !== "undefined"
124+
? parseInt(process.env.CODE_SERVER_PARENT_PID)
125+
: undefined
126+
)
127+
}
128+
return _ipcMain
129+
}
123130

124131
export interface WrapperOptions {
125132
maxMemory?: number
@@ -135,14 +142,14 @@ export class WrapperProcess {
135142
private started?: Promise<void>
136143

137144
public constructor(private currentVersion: string, private readonly options?: WrapperOptions) {
138-
ipcMain.onDispose(() => {
145+
ipcMain().onDispose(() => {
139146
if (this.process) {
140147
this.process.removeAllListeners()
141148
this.process.kill()
142149
}
143150
})
144151

145-
ipcMain.onMessage(async (message) => {
152+
ipcMain().onMessage(async (message) => {
146153
switch (message.type) {
147154
case "relaunch":
148155
logger.info(`Relaunching: ${this.currentVersion} -> ${message.version}`)
@@ -156,7 +163,7 @@ export class WrapperProcess {
156163
await this.start()
157164
} catch (error) {
158165
logger.error(error.message)
159-
exit(typeof error.code === "number" ? error.code : 1)
166+
ipcMain().exit(typeof error.code === "number" ? error.code : 1)
160167
}
161168
break
162169
default:
@@ -170,12 +177,14 @@ export class WrapperProcess {
170177
if (!this.started) {
171178
const child = this.spawn()
172179
logger.debug(`spawned inner process ${child.pid}`)
173-
this.started = ipcMain.handshake(child).then(() => {
174-
child.once("exit", (code) => {
175-
logger.debug(`inner process ${child.pid} exited unexpectedly`)
176-
exit(code || 0)
180+
this.started = ipcMain()
181+
.handshake(child)
182+
.then(() => {
183+
child.once("exit", (code) => {
184+
logger.debug(`inner process ${child.pid} exited unexpectedly`)
185+
ipcMain().exit(code || 0)
186+
})
177187
})
178-
})
179188
this.process = child
180189
}
181190
return this.started
@@ -201,23 +210,23 @@ export class WrapperProcess {
201210
// // It's possible that the pipe has closed (for example if you run code-server
202211
// // --version | head -1). Assume that means we're done.
203212
if (!process.stdout.isTTY) {
204-
process.stdout.on("error", () => exit())
213+
process.stdout.on("error", () => ipcMain().exit())
205214
}
206215

207216
export const wrap = (fn: () => Promise<void>): void => {
208-
if (ipcMain.parentPid) {
209-
ipcMain
217+
if (ipcMain().parentPid) {
218+
ipcMain()
210219
.handshake()
211220
.then(() => fn())
212221
.catch((error: ProcessError): void => {
213222
logger.error(error.message)
214-
exit(typeof error.code === "number" ? error.code : 1)
223+
ipcMain().exit(typeof error.code === "number" ? error.code : 1)
215224
})
216225
} else {
217226
const wrapper = new WrapperProcess(require("../../package.json").version)
218227
wrapper.start().catch((error) => {
219228
logger.error(error.message)
220-
exit(typeof error.code === "number" ? error.code : 1)
229+
ipcMain().exit(typeof error.code === "number" ? error.code : 1)
221230
})
222231
}
223232
}

0 commit comments

Comments
 (0)
Please sign in to comment.