Skip to content

Commit 862b00f

Browse files
committed
Update docs and remove separate wasm CI step
Integrated into the appropriate existing steps.
1 parent 6fc9ea4 commit 862b00f

File tree

12 files changed

+120
-115
lines changed

12 files changed

+120
-115
lines changed

.github/CONTRIBUTING.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,29 @@ CI must pass on your changes for them to be merged.
2727

2828
### CI
2929

30-
CI will ensure your code is formatted correctly, passes linting and tests.
30+
CI will ensure your code is formatted, lints and passes tests.
3131
It will collect coverage and report it to [codecov](https://codecov.io/gh/nhooyr/websocket)
32-
and also upload a `coverage` artifact that you can download to inspect browse coverage.
32+
and also upload a html `coverage` artifact that you can download to browse coverage.
3333

34-
You can run CI locally. The various steps are located in [ci/\*.sh](../ci).
34+
You can run CI locally. You only need [Go](https://golang.org), [nodejs](https://nodejs.org/en/) and [yarn](https://yarnpkg.com).
3535

36-
1. [fmt.sh](../ci/fmt.sh) which requires node (specifically prettier).
37-
1. [lint.sh](../ci/lint.sh) which requires [shellcheck](https://github.com/koalaman/shellcheck#installing).
38-
1. [test.sh](../ci/test.sh)
39-
1. [run.sh](../ci/run.sh) which runs the above scripts in order.
36+
See the scripts in [package.json](../package.json).
4037

41-
For coverage details locally, see `ci/out/coverage.html` after running [test.sh](../ci/test.sh).
38+
1. `yarn fmt` performs code generation and formatting.
39+
1. `yarn lint` performs linting.
40+
1. `yarn test` runs tests.
41+
1. `yarn all` runs the above scripts in parallel.
42+
43+
For coverage details locally, see `ci/out/coverage.html` after running `yarn test`.
44+
45+
CI is written with nodejs to enable running as much as possible concurrently.
4246

4347
See [ci/image/Dockerfile](../ci/image/Dockerfile) for the installation of the CI dependencies on Ubuntu.
4448

45-
You can also run tests normally with `go test`. [test.sh](../ci/test.sh) just passes a default set of flags to
46-
`go test` to collect coverage and also prettify the output.
49+
You can also run tests normally with `go test`. `yarn test` just passes a default set of flags to
50+
`go test` to collect coverage and runs the WASM tests.
4751

48-
You can pass flags to [test.sh](../ci/test.sh) if you want to run a specific test or otherwise
52+
You can pass flags to `yarn test` if you want to run a specific test or otherwise
4953
control the behaviour of `go test` but also get coverage.
5054

5155
Coverage percentage from codecov and the CI scripts will be different because they are calculated differently.

.github/workflows/ci.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ on: [push]
44
jobs:
55
fmt:
66
runs-on: ubuntu-latest
7-
container: nhooyr/websocket-ci@sha256:7f5513545dcbaa3ed06a2919acfd1cfbff1e6e0decc1602c98672a4aad2f68ab
7+
container: nhooyr/websocket-ci@sha256:f8b6e53a9fd256bcf6c90029276385b9ec730b76a0d7ccf3ff19084bce210c50
88
steps:
99
- uses: actions/checkout@v1
1010
- run: yarn --frozen-lockfile && yarn fmt
1111
lint:
1212
runs-on: ubuntu-latest
13-
container: nhooyr/websocket-ci@sha256:7f5513545dcbaa3ed06a2919acfd1cfbff1e6e0decc1602c98672a4aad2f68ab
13+
container: nhooyr/websocket-ci@sha256:f8b6e53a9fd256bcf6c90029276385b9ec730b76a0d7ccf3ff19084bce210c50
1414
steps:
1515
- uses: actions/checkout@v1
1616
- run: yarn --frozen-lockfile && yarn lint
1717
test:
1818
runs-on: ubuntu-latest
19-
container: nhooyr/websocket-ci@sha256:7f5513545dcbaa3ed06a2919acfd1cfbff1e6e0decc1602c98672a4aad2f68ab
19+
container: nhooyr/websocket-ci@sha256:f8b6e53a9fd256bcf6c90029276385b9ec730b76a0d7ccf3ff19084bce210c50
2020
steps:
2121
- uses: actions/checkout@v1
2222
- run: yarn --frozen-lockfile && yarn test
@@ -27,9 +27,3 @@ jobs:
2727
with:
2828
name: coverage
2929
path: ci/out/coverage.html
30-
wasm:
31-
runs-on: ubuntu-latest
32-
container: nhooyr/websocket-ci@sha256:7f5513545dcbaa3ed06a2919acfd1cfbff1e6e0decc1602c98672a4aad2f68ab
33-
steps:
34-
- uses: actions/checkout@v1
35-
- run: yarn --frozen-lockfile && yarn wasm

ci/all.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { fmt, gen } from "./fmt"
44
import { main } from "./lib"
55
import { lint } from "./lint"
66
import { test } from "./test"
7-
import { wasm } from "./wasm"
87

98
main(run)
109

@@ -15,6 +14,5 @@ async function run(ctx: Promise<unknown>) {
1514
fmt(ctx),
1615
lint(ctx),
1716
test(ctx),
18-
wasm(ctx),
1917
])
2018
}

ci/fmt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { exec, main } from "./lib"
44

5-
if (process.argv[1] === __filename) {
5+
if (require.main === module) {
66
main(async (ctx: Promise<unknown>) => {
77
await gen(ctx)
88
await fmt(ctx)

ci/image/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
66
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
77
RUN apt-get install -y nodejs chromium yarn
88

9-
RUN git config --global color.ui always
9+
COPY ./ci/image/gitignore /etc/git/ignore
10+
RUN git config --system color.ui always
11+
# Need to set set this explicitly for the system since github uses HOME=/home/github.
12+
RUN git config --system core.excludesfile /etc/git/ignore
1013

1114
ENV GOPATH=/root/gopath
1215
ENV PATH=$GOPATH/bin:$PATH
1316
ENV GOFLAGS="-mod=readonly"
1417
ENV PAGER=cat
1518
ENV CI=true
1619

17-
RUN mkdir -p ~/.config/git
18-
COPY ./ci/image/gitignore ~/.config/git/ignore
19-
2020
# Cache go modules, build cache and yarn cache.
2121
COPY . /tmp/websocket
2222
RUN cd /tmp/websocket && \

ci/image/push.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ async function run(ctx: Promise<unknown>) {
1313

1414
try {
1515
await spawn(ctx, "docker build -f ./ci/image/Dockerfile -t nhooyr/websocket-ci .", [], {
16-
timeout: 180_000,
1716
stdio: "inherit",
1817
})
1918
await spawn(ctx, "docker push nhooyr/websocket-ci", [], {
20-
timeout: 30_000,
2119
stdio: "inherit",
2220
})
2321
} finally {

ci/lib.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ExecOptions, SpawnOptions } from "child_process"
55
export async function main(fn: (ctx: Promise<unknown>) => void, opts: {
66
timeout: number
77
} = {
8-
timeout: 180_000,
8+
timeout: 3 * 60_000,
99
}) {
1010

1111
const timer = new Timeout();
@@ -45,7 +45,6 @@ export async function main(fn: (ctx: Promise<unknown>) => void, opts: {
4545
// TODO promisify native versions
4646
export async function exec(ctx: Promise<unknown>, cmd: string, opts?: ExecOptions) {
4747
opts = {
48-
timeout: 60_000,
4948
...opts,
5049
}
5150
const p = cp.exec(cmd, opts)
@@ -62,7 +61,6 @@ export async function spawn(ctx: Promise<unknown>, cmd: string, args: string[],
6261
args = []
6362
}
6463
opts = {
65-
timeout: 60_000,
6664
shell: true,
6765
...opts,
6866
}
@@ -115,3 +113,10 @@ export function withCancel<T>(p: Promise<T>) {
115113
p: p,
116114
}
117115
}
116+
117+
118+
export const wasmEnv = {
119+
...process.env,
120+
GOOS: "js",
121+
GOARCH: "wasm",
122+
}

ci/lint.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env -S npx ts-node -P ci/tsconfig.json
22

3-
import { exec, main } from "./lib"
3+
import { exec, main, wasmEnv } from "./lib"
44

5-
if (process.argv[1] === __filename) {
5+
if (require.main === module) {
66
main(lint)
77
}
88

@@ -13,6 +13,15 @@ export async function lint(ctx: Promise<unknown>) {
1313
exec(ctx, "git ls-files '*.ts' | xargs npx eslint --max-warnings 0 --fix", {
1414
cwd: "ci",
1515
}),
16+
wasmLint(ctx),
1617
],
1718
)
1819
}
20+
21+
22+
async function wasmLint(ctx: Promise<unknown>) {
23+
await exec(ctx, "go install golang.org/x/lint/golint")
24+
await exec(ctx, "golint -set_exit_status ./...", {
25+
env: wasmEnv,
26+
})
27+
}

ci/test.ts

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env -S npx ts-node -P ci/tsconfig.json
22

3-
import * as https from "https"
3+
import cp from "child_process"
4+
import * as events from "events"
5+
import * as readline from "readline"
46
import replaceInFile from "replace-in-file"
5-
import { exec, main, selectCtx, spawn } from "./lib"
7+
import { exec, main, selectCtx, spawn, wasmEnv } from "./lib"
68

7-
if (process.argv[1] === __filename) {
9+
if (require.main === module) {
810
main(test)
911
}
1012

@@ -26,32 +28,67 @@ export async function test(ctx: Promise<unknown>) {
2628
args.push("./...")
2729
}
2830

29-
await spawn(ctx, "go", ["test", ...args], {
30-
timeout: 60_000,
31+
const p1 = spawn(ctx, "go", ["test", ...args], {
3132
stdio: "inherit",
3233
})
34+
const p2 = wasmTest(ctx)
35+
await Promise.all([p1, p2])
3336

3437
// Depending on the code tested, we may not have replaced anything so we do not
3538
// check whether anything was replaced.
3639
await selectCtx(ctx, replaceInFile({
3740
files: "./ci/out/coverage.prof",
3841
from: [
39-
/.+frame_stringer.go:.+\n/g,
40-
/.+wsjstest:.+\n/g,
41-
/.+wsecho:.+\n/g,
42+
/.+frame_stringer.go.+\n/g,
43+
/.+wsjstest.+\n/g,
44+
/.+wsecho.+\n/g,
4245
],
4346
to: "",
4447
}))
4548

4649
let p: Promise<unknown> = exec(ctx, "go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html")
4750

4851
if (process.env.CI) {
49-
const script = https.get("https://codecov.io/bash")
50-
const p2 = spawn(ctx, "bash -Z -R . -f ci/out/coverage.prof", [], {
51-
stdio: [script],
52-
})
53-
p = Promise.all([p, p2])
52+
p = Promise.all([p, codecov(ctx)])
5453
}
5554

5655
await p
5756
}
57+
58+
59+
async function wasmTest(ctx: Promise<unknown>) {
60+
await Promise.all([
61+
exec(ctx, "go install ./internal/wsjstest"),
62+
exec(ctx, "go install github.com/agnivade/wasmbrowsertest"),
63+
])
64+
65+
const url = await startWasmTestServer(ctx)
66+
67+
await exec(ctx, "go test -exec=wasmbrowsertest ./...", {
68+
env: {
69+
...wasmEnv,
70+
WS_ECHO_SERVER_URL: url,
71+
},
72+
})
73+
}
74+
75+
async function startWasmTestServer(ctx: Promise<unknown>): Promise<string> {
76+
const wsjstest = cp.spawn("wsjstest")
77+
ctx.finally(wsjstest.kill.bind(wsjstest))
78+
79+
const rl = readline.createInterface({
80+
input: wsjstest.stdout!,
81+
})
82+
83+
try {
84+
const p = events.once(rl, "line")
85+
const a = await selectCtx(ctx, p)
86+
return a[0]
87+
} finally {
88+
rl.close()
89+
}
90+
}
91+
92+
function codecov(ctx: Promise<unknown>) {
93+
return exec(ctx, "curl -s https://codecov.io/bash | bash -s -- -Z -f ci/out/coverage.prof")
94+
}

ci/wasm.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)