forked from doctly/switchboard
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
167 lines (149 loc) · 5.73 KB
/
Copy pathTaskfile.yaml
File metadata and controls
167 lines (149 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# https://taskfile.dev
version: "3"
set: [pipefail]
vars:
SWITCHBOARD_DB: "{{.HOME}}/.switchboard/switchboard.db"
SWITCHBOARD_DEV_DATA_DIR: "{{.HOME}}/.switchboard-dev"
tasks:
default:
desc: List all available tasks
silent: true
cmds:
- task --list
install:
desc: Install npm dependencies
cmds:
- npm install
dev:
desc: Launch Switchboard in development mode (Electron, no-sandbox, isolated DB)
silent: true
env:
# Force a separate SQLite DB so a running AppImage isn't disturbed by the
# dev electron sharing session_cache. Override per-run with
# `SWITCHBOARD_DATA_DIR=/some/other/dir task dev`.
SWITCHBOARD_DATA_DIR: "{{.SWITCHBOARD_DEV_DATA_DIR}}"
cmds:
- npx electron . --no-sandbox
"db:reset:dev":
desc: Wipe just the dev SQLite database
cmds:
- rm -f "{{.SWITCHBOARD_DEV_DATA_DIR}}/switchboard.db" "{{.SWITCHBOARD_DEV_DATA_DIR}}/switchboard.db-wal" "{{.SWITCHBOARD_DEV_DATA_DIR}}/switchboard.db-shm"
- echo "Removed {{.SWITCHBOARD_DEV_DATA_DIR}}/switchboard.db"
build:
desc: Build Linux distribution packages (AppImage + deb)
silent: true
cmds:
- npm run build:linux
test:
desc: Run the node:test suite (24 tests)
cmds:
- npm test
coverage:
desc: Run the test suite under c8 (text + lcov in ./coverage)
cmds:
- npm run coverage
lint:
desc: Run ESLint across the codebase
cmds:
- |
if [ ! -f eslint.config.js ] && [ ! -f .eslintrc.js ] && [ ! -f .eslintrc.json ] && [ ! -f .eslintrc.yaml ] && [ ! -f .eslintrc.yml ]; then
echo "ESLint not yet configured; run \`task install:lint\` first"
exit 1
fi
npx eslint .
"install:lint":
desc: Install ESLint + jsdom dev deps (idempotent)
cmds:
- |
MISSING=""
node -e "require('eslint')" 2>/dev/null || MISSING="$MISSING eslint"
node -e "require('jsdom')" 2>/dev/null || MISSING="$MISSING jsdom"
if [ -n "$MISSING" ]; then
npm install --save-dev $MISSING
else
echo "ESLint and jsdom already installed — nothing to do."
fi
check:
desc: Run tests + lint (pre-commit / pre-push gate)
deps: [test, lint]
ci:
desc: CI gate — runs test then lint, verbose, exits on first failure
cmds:
- npm test
- npx eslint .
clean:
desc: Remove dist/, codemirror bundle, and local DB (asks for confirmation)
interactive: true
cmds:
- |
read -p "This will delete dist/, public/codemirror-bundle.js, and {{.SWITCHBOARD_DB}}. Type YES to confirm: " ans
[ "$ans" = "YES" ]
- rm -rf dist/
- rm -f public/codemirror-bundle.js
- rm -f "{{.SWITCHBOARD_DB}}"
- echo "Clean complete."
"db:reset":
desc: Wipe the local Switchboard SQLite database (no confirmation)
cmds:
- rm -f "{{.SWITCHBOARD_DB}}"
- echo "Removed {{.SWITCHBOARD_DB}}"
test-pr:
desc: "Run a PR live, isolated, alongside the running AppImage — requires PR=<number>. See docs/testing-a-pr.md"
silent: true
env:
# PR reaches the script as an environment variable, NOT as a {{.PR}}
# template splice. Splicing would paste the raw value into the script
# before the shell parses it, so a crafted value like `$(cmd)` executes
# during parsing — before any guard can reject it, and regardless of
# quoting. An environment variable's value is never re-parsed as shell
# syntax; the numeric guard below then handles everything else
# (path traversal, option-looking strings).
PR: "{{.PR}}"
cmds:
- |
case "$PR" in
''|*[!0-9]*)
echo "Usage: task test-pr PR=<number> (numeric only)" >&2
exit 1
;;
esac
set -e
WORKTREE=".worktrees/pr-$PR-test"
git fetch origin "pull/$PR/head"
PR_SHA="$(git rev-parse FETCH_HEAD)"
if [ -d "$WORKTREE" ]; then
git -C "$WORKTREE" checkout --detach "$PR_SHA"
else
git worktree add --detach "$WORKTREE" "$PR_SHA"
fi
# Symlink node_modules instead of `npm install` in the worktree: fast, and the
# native modules (better-sqlite3, node-pty) stay the electron-ABI ones already
# rebuilt in the primary checkout. INVALID if the PR bumped package-lock.json
# or the electron version — run `npm ci` in the worktree instead when it did.
git fetch origin main
if [ -n "$(git diff --stat origin/main..."$PR_SHA" -- package-lock.json)" ]; then
echo "WARNING: package-lock.json differs on this PR — the node_modules symlink is invalid." >&2
echo "Run 'npm ci' inside $WORKTREE before launching." >&2
fi
ln -sfn "$(pwd)/node_modules" "$WORKTREE/node_modules"
echo "Launching PR #$PR from $WORKTREE (isolated DB + triggers)..."
echo "Do not pipe this command's output (| head, tee-in-a-script-that-exits, ...) — see docs/testing-a-pr.md." >&2
cd "$WORKTREE" && SWITCHBOARD_DATA_DIR="$HOME/.switchboard-dev-pr$PR" SWITCHBOARD_TRIGGERS_DIR="$HOME/.switchboard-dev-pr$PR/triggers" npx electron . --no-sandbox
"test-pr:clean":
desc: "Remove the test-pr worktree and its isolated data dir — requires PR=<number>"
silent: true
env:
# Same rationale as in test-pr: env, never a {{.PR}} template splice.
PR: "{{.PR}}"
cmds:
- |
case "$PR" in
''|*[!0-9]*)
echo "Usage: task test-pr:clean PR=<number> (numeric only)" >&2
exit 1
;;
esac
set -e
git worktree remove --force ".worktrees/pr-$PR-test"
rm -rf "$HOME/.switchboard-dev-pr$PR"
echo "Cleaned up worktree and data dir for PR #$PR"