diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ffcbd1..f3193a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,11 +16,11 @@ jobs: with: bun-version: latest - - name: Install Biome + - name: Install dependencies run: bun install - name: Lint (Biome) - run: bunx biome check packages/ + run: bun run lint - name: Install dependencies (pulse) working-directory: packages/pulse @@ -34,6 +34,10 @@ jobs: working-directory: packages/upulse run: bun install + - name: Install dependencies (pulse-hermes) + working-directory: packages/pulse-hermes + run: bun install + - name: Type check (pulse) working-directory: packages/pulse run: bunx tsc --noEmit @@ -42,10 +46,18 @@ jobs: working-directory: packages/upulse run: bunx tsc --noEmit + - name: Type check (pulse-hermes) + working-directory: packages/pulse-hermes + run: bunx tsc --noEmit + - name: Unit tests (pulse) working-directory: packages/pulse run: bun test + - name: Unit tests (pulse-hermes) + working-directory: packages/pulse-hermes + run: bun test + - name: Unit tests (upulse) working-directory: packages/upulse run: bun test src/config.test.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 66477e7..96152c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,9 +11,16 @@ ```bash git clone https://github.com/oc-xiaoju/pulse.git cd pulse -bun install +bun install # also installs pre-push hook ``` +### Git Hooks + +`bun install` 自动安装 pre-push hook(via `scripts/install-hooks.mjs`),push 前自动跑 lint + tests。 + +手动跑检查:`bun run precheck` +删除 `.git/hooks/pre-push` 可禁用。 + ## 代码结构 ``` diff --git a/package.json b/package.json index 8545ea3..04e5d13 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,11 @@ "name": "pulse-monorepo", "private": true, "scripts": { - "lint": "biome check packages/", - "lint:fix": "biome check --write packages/" + "lint": "bun x @biomejs/biome check packages/", + "lint:fix": "bun x @biomejs/biome check --fix packages/", + "test": "cd packages/pulse && bun test && cd ../pulse-hermes && bun test", + "precheck": "bun run lint && bun run test", + "postinstall": "node scripts/install-hooks.mjs || true" }, "devDependencies": { "@biomejs/biome": "^2.4.11" diff --git a/packages/pulse/src/index.ts b/packages/pulse/src/index.ts index c346853..d6a94e4 100644 --- a/packages/pulse/src/index.ts +++ b/packages/pulse/src/index.ts @@ -107,7 +107,7 @@ export function findEffectiveEpoch(store: PulseStore): EventRecord | null { // Corrupted meta — skip this rollback event, fall through to latest promote return store.getLatest('promote'); } - const targetRev = meta.to || rollback.codeRev; + const targetRev = (meta.to as string | undefined) || rollback.codeRev; if (targetRev) { return store.getLatestWhere({ kind: 'promote', codeRev: targetRev }); } diff --git a/scripts/install-hooks.mjs b/scripts/install-hooks.mjs new file mode 100644 index 0000000..89153ab --- /dev/null +++ b/scripts/install-hooks.mjs @@ -0,0 +1,54 @@ +#!/usr/bin/env node +/** + * Install git pre-push hook. + * Zero dependencies — just writes a shell script to .git/hooks/pre-push. + * Runs on `bun install` via postinstall. + */ +import { writeFileSync, readFileSync, chmodSync, existsSync } from 'node:fs'; +import { join } from 'node:path'; + +const hookPath = join(process.cwd(), '.git', 'hooks', 'pre-push'); + +// Don't overwrite if user has a custom hook +if (existsSync(hookPath)) { + let content = ''; + try { content = readFileSync(hookPath, 'utf-8'); } catch {} + if (content && !content.includes('pulse-auto-hook')) { + console.log('[hooks] pre-push hook already exists (custom), skipping'); + process.exit(0); + } +} + +const hook = `#!/bin/sh +# pulse-auto-hook — installed by scripts/install-hooks.mjs +# Runs lint + tests before pushing. Delete this file to disable. + +echo "[pre-push] Running lint..." +bun x @biomejs/biome check packages/ || { + echo "\\n❌ Lint failed. Fix with: bun run lint:fix" + exit 1 +} + +echo "[pre-push] Running tests (pulse)..." +cd packages/pulse && bun test || { + echo "\\n❌ Tests failed (pulse)" + exit 1 +} + +echo "[pre-push] Running tests (pulse-hermes)..." +cd ../pulse-hermes && bun test || { + echo "\\n❌ Tests failed (pulse-hermes)" + exit 1 +} + +echo "✅ All checks passed" +`; + +try { + writeFileSync(hookPath, hook); + chmodSync(hookPath, 0o755); + console.log('[hooks] pre-push hook installed'); +} catch (err) { + // Non-fatal — CI and shallow clones may not have .git/hooks + console.log('[hooks] Could not install pre-push hook (non-fatal):', err.message); +}