Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 1f92821

Browse files
committed
chore: use Deno from all ci scripts
1 parent 2e8d708 commit 1f92821

File tree

15 files changed

+153
-70
lines changed

15 files changed

+153
-70
lines changed

.github/workflows/integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
with:
2424
go-version: '^1.14'
2525
- name: integration tests
26-
run: ./ci/steps/integration.sh
26+
run: ./ci/steps/integration.ts

.github/workflows/test.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ jobs:
55
fmt:
66
runs-on: ubuntu-latest
77
steps:
8+
- run: apt-get update && apt-get install deno
89
- uses: actions/checkout@v1
910
- uses: actions/cache@v1
1011
with:
@@ -15,10 +16,11 @@ jobs:
1516
- name: fmt
1617
uses: ./ci/image
1718
with:
18-
args: ./ci/steps/fmt.sh
19+
args: ./ci/steps/fmt.ts
1920
lint:
2021
runs-on: ubuntu-latest
2122
steps:
23+
- run: apt-get update && apt-get install deno
2224
- uses: actions/checkout@v2
2325
- name: golangci-lint
2426
uses: golangci/golangci-lint-action@v2
@@ -28,6 +30,7 @@ jobs:
2830
test:
2931
runs-on: ubuntu-latest
3032
steps:
33+
- run: apt-get update && apt-get install deno
3134
- uses: actions/checkout@v1
3235
- uses: actions/cache@v1
3336
with:
@@ -38,10 +41,11 @@ jobs:
3841
- name: test
3942
uses: ./ci/image
4043
with:
41-
args: ./ci/steps/unit_test.sh
44+
args: ./ci/steps/unit_test.ts
4245
gendocs:
4346
runs-on: ubuntu-latest
4447
steps:
48+
- run: apt-get update && apt-get install deno
4549
- uses: actions/checkout@v1
4650
- uses: actions/cache@v1
4751
with:
@@ -52,4 +56,4 @@ jobs:
5256
- name: generate-docs
5357
uses: ./ci/image
5458
with:
55-
args: ./ci/steps/gendocs.sh
59+
args: ./ci/steps/gendocs.ts

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deno.enable": true
3+
}

ci/steps/fmt.sh

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

ci/steps/fmt.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env -S deno run --allow-all
2+
import { root, execInherit, requireNoFilesChanged, isCI } from "./lib.ts"
3+
4+
await root()
5+
6+
console.log("--- formatting")
7+
await execInherit("go mod tidy")
8+
await execInherit("gofmt -w -s .")
9+
await execInherit(`goimports -w "-local=$$(go list -m)" .`)
10+
11+
if (isCI()) {
12+
await requireNoFilesChanged()
13+
}

ci/steps/gendocs.sh

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

ci/steps/gendocs.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env -S deno run --allow-all
2+
import { root, execInherit, requireNoFilesChanged, isCI } from "./lib.ts"
3+
4+
await root()
5+
6+
console.log("--- regenerating documentation")
7+
await Deno.remove("./docs", { recursive: true })
8+
await Deno.mkdir("./docs")
9+
10+
await execInherit("go run ./cmd/coder gen-docs ./docs")
11+
if (isCI()) {
12+
await requireNoFilesChanged()
13+
}

ci/steps/integration.sh

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

ci/steps/integration.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env -S deno run --allow-all
2+
import { root, execInherit } from "./lib.ts"
3+
4+
await root()
5+
6+
console.info("--- building integration test image")
7+
await execInherit(
8+
"docker build -f ./ci/integration/Dockerfile -t coder-cli-integration:latest ."
9+
)
10+
11+
console.info("--- run go tests")
12+
await execInherit("go test ./ci/integration -count=1")

ci/steps/lib.ts

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,94 @@
1-
import { exec } from "https://cdn.depjs.com/exec/mod.ts"
1+
export const root = async () =>
2+
Deno.chdir(await exec("git rev-parse --show-toplevel"))
23

3-
export const root = async () => Deno.chdir(await exec("git rev-parse --show-toplevel"))
44
export const string = (a: Uint8Array): string => new TextDecoder().decode(a)
5+
56
export const bytes = (a: string): Uint8Array => new TextEncoder().encode(a)
7+
68
export const read = async (path: string): Promise<string> =>
79
string(await Deno.readFile(path))
10+
811
export const write = async (path: string, data: string): Promise<void> =>
912
Deno.writeFile(path, bytes(data))
13+
14+
const removeTrailingLineBreak = (str: string) => {
15+
return str.replace(/\n$/, "")
16+
}
17+
18+
export const execInherit = async (
19+
cmd: string | string[] | ExecOptions
20+
): Promise<void> => {
21+
let opts: Deno.RunOptions
22+
if (typeof cmd === "string") {
23+
opts = {
24+
cmd: ["sh", "-c", cmd],
25+
}
26+
} else if (Array.isArray(cmd)) {
27+
opts = {
28+
cmd,
29+
}
30+
} else {
31+
opts = cmd
32+
}
33+
34+
opts.stdout = "inherit"
35+
opts.stderr = "inherit"
36+
37+
const process = Deno.run(opts)
38+
const { success } = await process.status()
39+
if (!success) {
40+
process.close()
41+
throw new Error("exec: failed to execute command")
42+
}
43+
}
44+
45+
export type ExecOptions = Omit<Deno.RunOptions, "stdout" | "stderr">
46+
47+
export const exec = async (
48+
cmd: string | string[] | ExecOptions
49+
): Promise<string> => {
50+
let opts: Deno.RunOptions
51+
52+
if (typeof cmd === "string") {
53+
opts = {
54+
cmd: ["sh", "-c", cmd],
55+
}
56+
} else if (Array.isArray(cmd)) {
57+
opts = {
58+
cmd,
59+
}
60+
} else {
61+
opts = cmd
62+
}
63+
64+
opts.stdout = "piped"
65+
opts.stderr = "piped"
66+
67+
const process = Deno.run(opts)
68+
const decoder = new TextDecoder()
69+
const { success } = await process.status()
70+
71+
if (!success) {
72+
const msg = removeTrailingLineBreak(
73+
decoder.decode(await process.stderrOutput())
74+
)
75+
76+
process.close()
77+
78+
throw new Error(msg || "exec: failed to execute command")
79+
}
80+
81+
return removeTrailingLineBreak(decoder.decode(await process.output()))
82+
}
83+
84+
export const requireNoFilesChanged = async (): Promise<void> => {
85+
const changed = await exec(
86+
"git ls-files --other --modified --exclude-standard"
87+
)
88+
if (changed !== "") {
89+
throw Error(`Files needs generation or formatting:
90+
${changed}`)
91+
}
92+
}
93+
94+
export const isCI = (): boolean => !!Deno.env.get("CI")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy