build: git钩子

This commit is contained in:
LOG1997
2025-12-10 00:10:33 +08:00
parent 80480213b8
commit 45e84db6d1
22 changed files with 121 additions and 10 deletions

2
.husky/_/applypatch-msg Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/commit-msg Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

22
.husky/_/h Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env sh
[ "$HUSKY" = "2" ] && set -x
n=$(basename "$0")
s=$(dirname "$(dirname "$0")")/$n
[ ! -f "$s" ] && exit 0
if [ -f "$HOME/.huskyrc" ]; then
echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
fi
i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
[ -f "$i" ] && . "$i"
[ "${HUSKY-}" = "0" ] && exit 0
export PATH="node_modules/.bin:$PATH"
sh -e "$s" "$@"
c=$?
[ $c != 0 ] && echo "husky - $n script failed (code $c)"
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
exit $c

9
.husky/_/husky.sh Normal file
View File

@@ -0,0 +1,9 @@
echo "husky - DEPRECATED
Please remove the following two lines from $0:
#!/usr/bin/env sh
. \"\$(dirname -- \"\$0\")/_/husky.sh\"
They WILL FAIL in v10.0.0
"

2
.husky/_/post-applypatch Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/post-checkout Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/post-commit Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/post-merge Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/post-rewrite Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/pre-applypatch Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/pre-auto-gc Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/pre-commit Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/pre-push Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

2
.husky/_/pre-rebase Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname "$0")/h"

12
.husky/pre-push Normal file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# 获取最新的 tag
TAG=$(git describe --tags --abbrev=0 2>/dev/null)
if [ $? -eq 0 ]; then
echo "🏷️ 检查最新的 tag: $TAG"
node .husky/scripts/verifyTagVersion.js $TAG
else
echo "⚠️ 没有找到任何 tag跳过版本校验"
fi

View File

@@ -3,18 +3,18 @@ import fs from "fs";
const msg = fs.readFileSync(".git/COMMIT_EDITMSG", "utf-8").trim();
const commitRE =
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/;
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/;
const mergeRe = /^(Merge pull request|Merge branch)/;
if (!commitRE.test(msg)) {
if (!mergeRe.test(msg)) {
console.log("git commit信息校验不通过");
if (!mergeRe.test(msg)) {
console.log("git commit信息校验不通过");
console.error(`git commit的信息格式不对, 需要使用 title(scope): desc的格式
console.error(`git commit的信息格式不对, 需要使用 title(scope): desc的格式
比如 fix: xxbug
feat(test): add new
`);
process.exit(1);
}
process.exit(1);
}
} else {
console.log("git commit信息校验通过");
console.log("git commit信息校验通过");
}

View File

@@ -0,0 +1,30 @@
import fs from 'fs';
try {
// 读取 package.json 中的版本号
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
const packageVersion = packageJson.version;
// 获取命令行参数中的 tag 名称
const tag = process.argv[2];
if (!tag) {
console.log('⚠️ 未提供 tag 参数,跳过版本校验');
process.exit(0);
}
// 检查 tag 是否与 package.json 版本匹配
const validTags = [`v${packageVersion}`, packageVersion];
if (!validTags.includes(tag)) {
console.log('🏷️ Git tag 版本校验不通过');
console.error(`当前 package.json 版本为: ${packageVersion}`);
console.error(`提供的 tag 为: ${tag}`);
process.exit(1);
} else {
console.log('✅ Git tag 版本校验通过');
}
} catch (error) {
console.error('❌ 校验过程中发生错误:', error.message);
process.exit(1);
}