Skip to content

Commit 947ee72

Browse files
authored
ci: add CI workflow + fix tsc strict union narrowing in api.ts (#4)
1 parent 19c85ad commit 947ee72

2 files changed

Lines changed: 44 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
typecheck:
11+
name: Typecheck
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: oven-sh/setup-bun@v2
16+
with:
17+
bun-version: latest
18+
- run: bun install --frozen-lockfile
19+
- run: bunx tsc --noEmit
20+
21+
shellcheck:
22+
name: ShellCheck
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Run shellcheck
27+
run: |
28+
shopt -s nullglob
29+
fail=0
30+
for f in bin/*; do
31+
if head -n1 "$f" | grep -qE '^#!.*\b(bash|sh)\b'; then
32+
echo "▶ shellcheck $f"
33+
shellcheck "$f" || fail=1
34+
fi
35+
done
36+
exit "$fail"

src/api.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ api.get("/project", async (c) => {
4444
});
4545

4646
api.post("/project/run-task", async (c) => {
47-
const body = await c.req.json<{ task?: string }>().catch(() => ({}));
47+
const body: { task?: string } = await c.req.json<{ task?: string }>().catch(() => ({}));
4848
const task = body.task;
4949
if (!task || !/^[A-Za-z0-9_-]+$/.test(task)) {
5050
return c.json({ error: "invalid task name" }, 400);
@@ -60,7 +60,7 @@ api.post("/project/run-task", async (c) => {
6060
});
6161

6262
api.post("/project/run-lane", async (c) => {
63-
const body = await c.req.json<{ lane?: string }>().catch(() => ({}));
63+
const body: { lane?: string } = await c.req.json<{ lane?: string }>().catch(() => ({}));
6464
const lane = body.lane;
6565
if (!lane || !/^[A-Za-z0-9_-]+$/.test(lane)) {
6666
return c.json({ error: "invalid lane name" }, 400);
@@ -103,7 +103,10 @@ api.get("/plugins/search", async (c) => {
103103
});
104104

105105
api.post("/plugins/install", async (c) => {
106-
const body = await c.req.json<{ source?: string; force?: boolean }>().catch(() => ({}));
106+
const body: { source?: string; force?: boolean } = await c
107+
.req
108+
.json<{ source?: string; force?: boolean }>()
109+
.catch(() => ({}));
107110
if (!body.source) return c.json({ error: "source required" }, 400);
108111
// --yes is required because FLEDGE_NON_INTERACTIVE is set in the env and
109112
// install would otherwise bail on the trust-prompt.
@@ -119,7 +122,7 @@ api.post("/plugins/install", async (c) => {
119122
});
120123

121124
api.post("/plugins/remove", async (c) => {
122-
const body = await c.req.json<{ name?: string }>().catch(() => ({}));
125+
const body: { name?: string } = await c.req.json<{ name?: string }>().catch(() => ({}));
123126
if (!body.name) return c.json({ error: "name required" }, 400);
124127
const result = await fledge(["plugins", "remove", body.name, "--json"]);
125128
return c.json({
@@ -131,7 +134,7 @@ api.post("/plugins/remove", async (c) => {
131134
});
132135

133136
api.post("/plugins/update", async (c) => {
134-
const body = await c.req.json<{ name?: string }>().catch(() => ({}));
137+
const body: { name?: string } = await c.req.json<{ name?: string }>().catch(() => ({}));
135138
const args = ["plugins", "update"];
136139
if (body.name) args.push(body.name);
137140
args.push("--json");

0 commit comments

Comments
 (0)