build: replace lefthook with husky, commitlint and commit-and-tag-version
This commit is contained in:
parent
fa913d1561
commit
92ed47ebdf
11 changed files with 3607 additions and 73 deletions
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
|
|
@ -19,29 +19,15 @@ jobs:
|
|||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Validate conventional commits
|
||||
run: |
|
||||
base="${{ github.event.pull_request.base.sha }}"
|
||||
head="${{ github.event.pull_request.head.sha }}"
|
||||
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?(!)?: .{1,}$'
|
||||
|
||||
failed=0
|
||||
while IFS= read -r msg; do
|
||||
first_line=$(echo "$msg" | head -1)
|
||||
if ! echo "$first_line" | grep -qE "$pattern"; then
|
||||
echo "FAIL: $first_line"
|
||||
failed=1
|
||||
fi
|
||||
done < <(git log --format="%s" "$base".."$head")
|
||||
|
||||
if [ "$failed" -eq 1 ]; then
|
||||
echo ""
|
||||
echo "Some commits do not follow Conventional Commits format."
|
||||
echo "Expected: <type>[scope][!]: <description>"
|
||||
echo "See: https://www.conventionalcommits.org/"
|
||||
exit 1
|
||||
fi
|
||||
echo "All commits follow Conventional Commits format."
|
||||
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
|
||||
|
||||
build-and-test:
|
||||
name: Build & test
|
||||
|
|
|
|||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -19,10 +19,6 @@ desktop.ini
|
|||
/tmp/
|
||||
*.tmp
|
||||
|
||||
# Lefthook
|
||||
lefthook-local.yml
|
||||
.lefthookrc.local
|
||||
|
||||
# Environment
|
||||
.env
|
||||
.env.local
|
||||
|
|
|
|||
1
.husky/commit-msg
Normal file
1
.husky/commit-msg
Normal file
|
|
@ -0,0 +1 @@
|
|||
npx --no -- commitlint --edit $1
|
||||
2
.husky/pre-commit
Normal file
2
.husky/pre-commit
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
npx lint-staged
|
||||
npx tsc --noEmit
|
||||
1
.husky/pre-push
Normal file
1
.husky/pre-push
Normal file
|
|
@ -0,0 +1 @@
|
|||
npm test
|
||||
15
.versionrc
Normal file
15
.versionrc
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"types": [
|
||||
{ "type": "feat", "section": "Features" },
|
||||
{ "type": "fix", "section": "Bug Fixes" },
|
||||
{ "type": "perf", "section": "Performance" },
|
||||
{ "type": "revert", "section": "Reverts" },
|
||||
{ "type": "docs", "section": "Documentation", "hidden": true },
|
||||
{ "type": "style", "hidden": true },
|
||||
{ "type": "refactor", "hidden": true },
|
||||
{ "type": "test", "hidden": true },
|
||||
{ "type": "build", "hidden": true },
|
||||
{ "type": "ci", "hidden": true },
|
||||
{ "type": "chore", "hidden": true }
|
||||
]
|
||||
}
|
||||
22
Makefile
22
Makefile
|
|
@ -1,4 +1,4 @@
|
|||
.PHONY: build test fmt lint typecheck version version-next release install-tools hooks clean
|
||||
.PHONY: build test fmt lint typecheck version release release-minor release-major install clean
|
||||
|
||||
build:
|
||||
npm run build
|
||||
|
|
@ -17,18 +17,20 @@ lint: fmt typecheck
|
|||
version:
|
||||
@node -p "require('./package.json').version"
|
||||
|
||||
version-next:
|
||||
@echo "Use: npm version [patch|minor|major] --no-git-tag-version"
|
||||
|
||||
release:
|
||||
@echo "Use: npm version <patch|minor|major>, then git push origin v<version>"
|
||||
npm run release
|
||||
@echo "Run: git push --follow-tags origin main"
|
||||
|
||||
install-tools:
|
||||
release-minor:
|
||||
npm run release:minor
|
||||
@echo "Run: git push --follow-tags origin main"
|
||||
|
||||
release-major:
|
||||
npm run release:major
|
||||
@echo "Run: git push --follow-tags origin main"
|
||||
|
||||
install:
|
||||
npm install
|
||||
@command -v lefthook >/dev/null 2>&1 || npm install -g lefthook
|
||||
|
||||
hooks:
|
||||
lefthook install
|
||||
|
||||
clean:
|
||||
rm -rf build coverage
|
||||
|
|
|
|||
1
commitlint.config.js
Normal file
1
commitlint.config.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
export default { extends: ["@commitlint/config-conventional"] };
|
||||
36
lefthook.yml
36
lefthook.yml
|
|
@ -1,36 +0,0 @@
|
|||
commit-msg:
|
||||
commands:
|
||||
validate:
|
||||
run: |
|
||||
msg=$(head -1 {1})
|
||||
if ! echo "$msg" | grep -qE '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?(!)?: .{1,}$'; then
|
||||
echo ""
|
||||
echo "ERROR: Invalid commit message format."
|
||||
echo ""
|
||||
echo " Got: $msg"
|
||||
echo ""
|
||||
echo " Expected: <type>[optional scope][!]: <description>"
|
||||
echo ""
|
||||
echo " Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
|
||||
echo " Examples:"
|
||||
echo " feat: add new audio codec detection"
|
||||
echo " fix(scanner): correct HDR10 detection for MKV files"
|
||||
echo " feat!: redesign output format"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pre-commit:
|
||||
parallel: true
|
||||
commands:
|
||||
prettier:
|
||||
glob: "*.{ts,js,json,md,yml,yaml}"
|
||||
run: npx prettier --check {staged_files}
|
||||
typecheck:
|
||||
glob: "*.ts"
|
||||
run: npx tsc --noEmit
|
||||
|
||||
pre-push:
|
||||
commands:
|
||||
test:
|
||||
run: npm test
|
||||
3554
package-lock.json
generated
3554
package-lock.json
generated
File diff suppressed because it is too large
Load diff
14
package.json
14
package.json
|
|
@ -18,7 +18,14 @@
|
|||
"fmt": "prettier --write .",
|
||||
"fmt:check": "prettier --check .",
|
||||
"lint": "tsc --noEmit",
|
||||
"prepublishOnly": "npm run build"
|
||||
"prepublishOnly": "npm run build",
|
||||
"prepare": "husky",
|
||||
"release": "commit-and-tag-version",
|
||||
"release:minor": "commit-and-tag-version --release-as minor",
|
||||
"release:major": "commit-and-tag-version --release-as major"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{ts,js,json,md,yml,yaml}": "prettier --check"
|
||||
},
|
||||
"keywords": [
|
||||
"mcp",
|
||||
|
|
@ -55,8 +62,13 @@
|
|||
"zod": "^3.24.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^20.4.1",
|
||||
"@commitlint/config-conventional": "^20.4.1",
|
||||
"@types/node": "^22.0.0",
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"commit-and-tag-version": "^12.6.1",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.2.7",
|
||||
"prettier": "^3.8.1",
|
||||
"tsx": "^4.19.0",
|
||||
"typescript": "^5.7.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue