Skip to content

Commit 6fc9ea4

Browse files
committed
Switch CI to Typescript
Significantly faster locally since **everything** runs in parallel. Also much easier to maintain than bash.
1 parent d81a14e commit 6fc9ea4

24 files changed

+1958
-180
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ on: [push]
44
jobs:
55
fmt:
66
runs-on: ubuntu-latest
7-
container: docker://nhooyr/websocket-ci@sha256:b6331f8f64803c8b1bbd2a0ee9e2547317e0de2348bccd9c8dbcc1d88ff5747f
7+
container: nhooyr/websocket-ci@sha256:7f5513545dcbaa3ed06a2919acfd1cfbff1e6e0decc1602c98672a4aad2f68ab
88
steps:
99
- uses: actions/checkout@v1
10-
- run: ./ci/fmt.sh
10+
- run: yarn --frozen-lockfile && yarn fmt
1111
lint:
1212
runs-on: ubuntu-latest
13-
container: docker://nhooyr/websocket-ci@sha256:b6331f8f64803c8b1bbd2a0ee9e2547317e0de2348bccd9c8dbcc1d88ff5747f
13+
container: nhooyr/websocket-ci@sha256:7f5513545dcbaa3ed06a2919acfd1cfbff1e6e0decc1602c98672a4aad2f68ab
1414
steps:
1515
- uses: actions/checkout@v1
16-
- run: ./ci/lint.sh
16+
- run: yarn --frozen-lockfile && yarn lint
1717
test:
1818
runs-on: ubuntu-latest
19-
container: docker://nhooyr/websocket-ci@sha256:b6331f8f64803c8b1bbd2a0ee9e2547317e0de2348bccd9c8dbcc1d88ff5747f
19+
container: nhooyr/websocket-ci@sha256:7f5513545dcbaa3ed06a2919acfd1cfbff1e6e0decc1602c98672a4aad2f68ab
2020
steps:
2121
- uses: actions/checkout@v1
22-
- run: ./ci/test.sh
22+
- run: yarn --frozen-lockfile && yarn test
2323
env:
2424
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2525
- name: Upload coverage.html
@@ -29,7 +29,7 @@ jobs:
2929
path: ci/out/coverage.html
3030
wasm:
3131
runs-on: ubuntu-latest
32-
container: docker://nhooyr/websocket-ci@sha256:b6331f8f64803c8b1bbd2a0ee9e2547317e0de2348bccd9c8dbcc1d88ff5747f
32+
container: nhooyr/websocket-ci@sha256:7f5513545dcbaa3ed06a2919acfd1cfbff1e6e0decc1602c98672a4aad2f68ab
3333
steps:
3434
- uses: actions/checkout@v1
35-
- run: ./ci/wasm.sh
35+
- run: yarn --frozen-lockfile && yarn wasm

ci/.eslintrc.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
parser: "@typescript-eslint/parser"
2+
env:
3+
node: true
4+
5+
parserOptions:
6+
ecmaVersion: 2018
7+
sourceType: module
8+
9+
extends:
10+
# https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage
11+
- eslint:recommended
12+
- plugin:@typescript-eslint/eslint-recommended
13+
- plugin:@typescript-eslint/recommended
14+
# https://www.npmjs.com/package/eslint-plugin-import#typescript
15+
- plugin:import/recommended
16+
- plugin:import/typescript
17+
# https://dev.to/robertcoopercode/using-eslint-and-prettier-in-a-typescript-project-53jb
18+
- prettier/@typescript-eslint
19+
20+
rules:
21+
"@typescript-eslint/no-use-before-define": off
22+
"@typescript-eslint/explicit-function-return-type": off
23+
"@typescript-eslint/no-non-null-assertion": off

ci/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

ci/all.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env -S npx ts-node -P ci/tsconfig.json
2+
3+
import { fmt, gen } from "./fmt"
4+
import { main } from "./lib"
5+
import { lint } from "./lint"
6+
import { test } from "./test"
7+
import { wasm } from "./wasm"
8+
9+
main(run)
10+
11+
async function run(ctx: Promise<unknown>) {
12+
await gen(ctx)
13+
14+
await Promise.all([
15+
fmt(ctx),
16+
lint(ctx),
17+
test(ctx),
18+
wasm(ctx),
19+
])
20+
}

ci/fmt.sh

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

ci/fmt.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env -S npx ts-node -P ci/tsconfig.json
2+
3+
import { exec, main } from "./lib"
4+
5+
if (process.argv[1] === __filename) {
6+
main(async (ctx: Promise<unknown>) => {
7+
await gen(ctx)
8+
await fmt(ctx)
9+
})
10+
}
11+
12+
export async function fmt(ctx: Promise<unknown>) {
13+
await Promise.all([
14+
exec(ctx, "go mod tidy"),
15+
exec(ctx, "gofmt -w -s ."),
16+
exec(ctx, `go run go.coder.com/go-tools/cmd/goimports -w "-local=$(go list -m)" .`),
17+
exec(ctx, `npx prettier --write --print-width=120 --no-semi --trailing-comma=all --loglevel=silent $(git ls-files "*.yaml" "*.yml" "*.md")`),
18+
],
19+
)
20+
21+
if (process.env.CI) {
22+
const r = await exec(ctx, "git ls-files --other --modified --exclude-standard")
23+
const files = r.stdout.toString().trim()
24+
if (files.length) {
25+
console.log(`files need generation or are formatted incorrectly:
26+
${files}
27+
28+
please run:
29+
./ci/fmt.js`)
30+
process.exit(1)
31+
}
32+
}
33+
}
34+
35+
export async function gen(ctx: Promise<unknown>) {
36+
await exec(ctx, "go generate ./...")
37+
}

ci/image/Dockerfile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
FROM golang:1
22

3-
ENV DEBIAN_FRONTEND=noninteractive
3+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
4+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
5+
6+
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
7+
RUN apt-get install -y nodejs chromium yarn
8+
9+
RUN git config --global color.ui always
10+
411
ENV GOPATH=/root/gopath
512
ENV PATH=$GOPATH/bin:$PATH
613
ENV GOFLAGS="-mod=readonly"
714
ENV PAGER=cat
815
ENV CI=true
916

10-
RUN apt-get update && \
11-
apt-get install -y shellcheck npm chromium && \
12-
npm install -g prettier
13-
14-
# https://github.com/golang/go/wiki/WebAssembly#running-tests-in-the-browser
15-
RUN go get github.com/agnivade/wasmbrowsertest && \
16-
mv $GOPATH/bin/wasmbrowsertest $GOPATH/bin/go_js_wasm_exec
17-
18-
RUN git config --global color.ui always
17+
RUN mkdir -p ~/.config/git
18+
COPY ./ci/image/gitignore ~/.config/git/ignore
1919

20-
# Cache go modules and build cache.
20+
# Cache go modules, build cache and yarn cache.
2121
COPY . /tmp/websocket
2222
RUN cd /tmp/websocket && \
23-
CI= ./ci/run.sh && \
23+
yarn && CI= yarn ci && \
2424
rm -rf /tmp/websocket

ci/image/dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

ci/image/gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
.idea
4+
.gitignore
5+
.dockerignore

ci/image/push.sh

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

0 commit comments

Comments
 (0)