From f554f4e38c2abc730d9c42e5e33088c301cbb2f0 Mon Sep 17 00:00:00 2001 From: Nicholai Date: Sat, 24 Jan 2026 14:23:14 -0700 Subject: [PATCH] ci: add branch protection, CI workflow, and PR template - husky pre-commit hook blocks direct commits to main - github actions CI runs lint + build on PRs - PR template and CONTRIBUTING.md for workflow docs --- .github/pull_request_template.md | 15 +++++++++ .github/workflows/ci.yml | 26 ++++++++++++++++ .husky/pre-commit | 8 +++++ CONTRIBUTING.md | 52 ++++++++++++++++++++++++++++++++ bun.lock | 3 ++ package.json | 6 ++-- 6 files changed, 108 insertions(+), 2 deletions(-) create mode 100755 .github/pull_request_template.md create mode 100755 .github/workflows/ci.yml create mode 100755 .husky/pre-commit create mode 100755 CONTRIBUTING.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100755 index 0000000..05d4de7 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,15 @@ +## what + + + +## why + + + +## how to test + + + +## notes + + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100755 index 0000000..d1b3c79 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install --frozen-lockfile + - run: bun run lint + + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install --frozen-lockfile + - run: bun run build diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..e349b26 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,8 @@ +#!/bin/sh + +branch=$(git rev-parse --abbrev-ref HEAD) +if [ "$branch" = "main" ]; then + echo "direct commits to main are blocked." + echo "create a feature branch: git checkout -b /" + exit 1 +fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100755 index 0000000..79410af --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,52 @@ +contributing +=== + +local setup +--- + +```bash +git clone git@github.com:High-Performance-Structures/compass.git +cd compass +bun install +bun dev +``` + +branching +--- + +branch off main using the format `/`: + +```bash +git checkout -b nicholai/add-gantt-zoom +``` + +direct commits to main are blocked by a pre-commit hook. + +commits +--- + +use conventional commits: + +``` +type(scope): subject +``` + +- types: feat, fix, docs, style, refactor, perf, test, build, ci, chore +- subject: imperative mood, 50 chars max +- body: 72 chars max width, explain *why* not *what* + +pull requests +--- + +1. push your branch and open a PR against main +2. CI runs lint + build automatically +3. both checks must pass before merge +4. PRs are squash-and-merged (single clean commit on main) + +the PR template will guide you on what to include. + +deployment +--- + +deployment to cloudflare workers happens manually via `bun deploy`. +this is separate from the PR/merge workflow. diff --git a/bun.lock b/bun.lock index 066ab87..743ca94 100755 --- a/bun.lock +++ b/bun.lock @@ -71,6 +71,7 @@ "drizzle-kit": "^0.31.8", "eslint": "^9", "eslint-config-next": "15.4.6", + "husky": "^9.1.7", "tailwindcss": "^4", "typescript": "^5", "wrangler": "^4.59.3", @@ -1194,6 +1195,8 @@ "humanize-ms": ["humanize-ms@1.2.1", "", { "dependencies": { "ms": "^2.0.0" } }, "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ=="], + "husky": ["husky@9.1.7", "", { "bin": { "husky": "bin.js" } }, "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA=="], + "iconv-lite": ["iconv-lite@0.7.2", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw=="], "ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], diff --git a/package.json b/package.json index 6b26c10..25b3886 100755 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "cf-typegen": "wrangler types --env-interface CloudflareEnv ./cloudflare-env.d.ts", "db:generate": "drizzle-kit generate", "db:migrate:local": "wrangler d1 migrations apply compass-db --local", - "db:migrate:prod": "wrangler d1 migrations apply compass-db --remote" + "db:migrate:prod": "wrangler d1 migrations apply compass-db --remote", + "prepare": "husky" }, "dependencies": { "@dnd-kit/core": "^6.3.1", @@ -82,8 +83,9 @@ "drizzle-kit": "^0.31.8", "eslint": "^9", "eslint-config-next": "15.4.6", + "husky": "^9.1.7", "tailwindcss": "^4", "typescript": "^5", "wrangler": "^4.59.3" } -} \ No newline at end of file +}