Skip to content

Commit 8fe496c

Browse files
committed
ci: bootstrap
1 parent 6ebd8de commit 8fe496c

File tree

6 files changed

+185
-10
lines changed

6 files changed

+185
-10
lines changed

.github/workflows/ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Bun
18+
uses: oven-sh/setup-bun@v2
19+
with:
20+
bun-version: latest
21+
22+
- name: Install dependencies
23+
run: bun install --frozen-lockfile
24+
25+
- name: Run lint
26+
run: bun lint
27+
28+
fmt-check:
29+
name: Format Check
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
35+
- name: Setup Bun
36+
uses: oven-sh/setup-bun@v2
37+
with:
38+
bun-version: latest
39+
40+
- name: Install dependencies
41+
run: bun install --frozen-lockfile
42+
43+
- name: Check formatting
44+
run: bun fmt:check
45+
46+
test:
47+
name: Test
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v4
52+
53+
- name: Setup Bun
54+
uses: oven-sh/setup-bun@v2
55+
with:
56+
bun-version: latest
57+
58+
- name: Install dependencies
59+
run: bun install --frozen-lockfile
60+
61+
- name: Run tests
62+
run: bun test

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
"build:preload": "bun build src/preload.ts --format=cjs --target=node --external=electron --outfile=dist/preload.js",
1313
"build:renderer": "vite build",
1414
"start": "bun build:preload && electron .",
15-
"typecheck": "tsc --noEmit",
16-
"typecheck:main": "tsc --noEmit -p tsconfig.main.json",
15+
"typecheck": "./scripts/typecheck.sh",
16+
"typecheck:main": "./scripts/typecheck.sh --main",
1717
"debug": "bun src/debug/index.ts",
18-
"lint": "eslint 'src/**/*.{ts,tsx}' && bun run typecheck && bun run typecheck:main",
19-
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
20-
"fmt": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json}\" \"*.{json,md}\"",
21-
"fmt:shell": "shfmt -i 2 -ci -bn -w scripts",
22-
"fmt:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json}\" \"*.{json,md}\"",
23-
"test": "jest",
24-
"test:watch": "jest --watch",
25-
"test:coverage": "jest --coverage",
18+
"lint": "./scripts/lint.sh",
19+
"lint:fix": "./scripts/lint.sh --fix",
20+
"fmt": "./scripts/fmt.sh",
21+
"fmt:shell": "./scripts/fmt.sh --shell",
22+
"fmt:check": "./scripts/fmt.sh --check",
23+
"test": "./scripts/test.sh",
24+
"test:watch": "./scripts/test.sh --watch",
25+
"test:coverage": "./scripts/test.sh --coverage",
2626
"dist": "bun run build && electron-builder",
2727
"dist:mac": "bun run build && electron-builder --mac",
2828
"dist:win": "bun run build && electron-builder --win",

scripts/fmt.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
7+
8+
cd "$PROJECT_ROOT"
9+
10+
PRETTIER_PATTERNS=("src/**/*.{ts,tsx,js,jsx,json}" "*.{json,md}")
11+
12+
format_typescript() {
13+
local mode="$1"
14+
if [ "$mode" = "--check" ]; then
15+
echo "Checking TypeScript/JSON/Markdown formatting..."
16+
prettier --check "${PRETTIER_PATTERNS[@]}"
17+
else
18+
echo "Formatting TypeScript/JSON/Markdown files..."
19+
prettier --write "${PRETTIER_PATTERNS[@]}"
20+
fi
21+
}
22+
23+
format_shell() {
24+
if ! command -v shfmt &>/dev/null; then
25+
echo "shfmt not found. Installing via brew..."
26+
if command -v brew &>/dev/null; then
27+
brew install shfmt
28+
else
29+
echo "Error: brew not found. Please install shfmt manually:"
30+
echo " macOS: brew install shfmt"
31+
echo " Linux: apt-get install shfmt or snap install shfmt"
32+
echo " Go: go install mvdan.cc/sh/v3/cmd/shfmt@latest"
33+
exit 1
34+
fi
35+
fi
36+
echo "Formatting shell scripts..."
37+
shfmt -i 2 -ci -bn -w scripts
38+
}
39+
40+
if [ "$1" = "--check" ]; then
41+
format_typescript --check
42+
elif [ "$1" = "--shell" ]; then
43+
format_shell
44+
elif [ "$1" = "--all" ]; then
45+
format_typescript
46+
format_shell
47+
else
48+
format_typescript
49+
fi

scripts/lint.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
7+
8+
cd "$PROJECT_ROOT"
9+
10+
ESLINT_PATTERN='src/**/*.{ts,tsx}'
11+
12+
if [ "$1" = "--fix" ]; then
13+
echo "Running eslint with --fix..."
14+
eslint "$ESLINT_PATTERN" --fix
15+
else
16+
echo "Running eslint..."
17+
eslint "$ESLINT_PATTERN"
18+
echo "Running typecheck (renderer)..."
19+
bun run typecheck
20+
echo "Running typecheck (main)..."
21+
bun run typecheck:main
22+
echo "All lint checks passed!"
23+
fi

scripts/test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
7+
8+
cd "$PROJECT_ROOT"
9+
10+
if [ "$1" = "--watch" ]; then
11+
echo "Running tests in watch mode..."
12+
jest --watch
13+
elif [ "$1" = "--coverage" ]; then
14+
echo "Running tests with coverage..."
15+
jest --coverage
16+
else
17+
echo "Running tests..."
18+
jest
19+
fi

scripts/typecheck.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
7+
8+
cd "$PROJECT_ROOT"
9+
10+
if [ "$1" = "--main" ]; then
11+
echo "Running typecheck (main)..."
12+
tsc --noEmit -p tsconfig.main.json
13+
elif [ "$1" = "--renderer" ]; then
14+
echo "Running typecheck (renderer)..."
15+
tsc --noEmit
16+
else
17+
echo "Running typecheck (renderer)..."
18+
tsc --noEmit
19+
echo "Running typecheck (main)..."
20+
tsc --noEmit -p tsconfig.main.json
21+
echo "All typechecks passed!"
22+
fi

0 commit comments

Comments
 (0)