21a8c38040
* chore: add pre-push hook for lint + tests (closes #29) - scripts/install-hooks.mjs: zero-dep hook installer, runs on postinstall - Pre-push runs: biome lint + pulse tests + pulse-hermes tests - CI: add pulse-hermes type check + tests, use bun run lint - CONTRIBUTING.md: document hook setup Uses pure Node.js APIs (no Bun dependency) so postinstall works with any runtime. Users can delete .git/hooks/pre-push to opt out. * fix: TS2322 in findEffectiveEpoch — cast meta.to to string meta is Record<string, unknown>, so meta.to is unknown. Explicit cast to (string | undefined) satisfies codeRev: string param. --------- Co-authored-by: 鹿鸣 <luming@shazhou.work>
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
#!/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);
|
|
}
|