From 85ac42b65bf1a50ec708b7ef3ac51850b428e4d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BA=9A=E7=90=AA?= Date: Thu, 27 Jun 2024 14:35:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A6=81=E6=AD=A2=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=9C=A8alpha=E5=88=86=E6=94=AF=E3=80=81master=E5=88=86?= =?UTF-8?q?=E6=94=AF=E5=88=9B=E5=BB=BA=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/commit-msg | 1 + git-hooks/check-commit.cjs | 16 ++++++++++++++++ package.json | 4 ++-- readme.md | 10 +++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .husky/commit-msg create mode 100644 git-hooks/check-commit.cjs diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 00000000..f67cae7d --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +npm run check-commit -- $1 diff --git a/git-hooks/check-commit.cjs b/git-hooks/check-commit.cjs new file mode 100644 index 00000000..e79ede4b --- /dev/null +++ b/git-hooks/check-commit.cjs @@ -0,0 +1,16 @@ +const fs = require('fs') +const { + execSync +} = require('child_process') + +const message = fs.readFileSync(process.argv[2]).toString('utf8').toLowerCase() +const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim() + +if ( + (branch === 'master' || branch === 'alpha') && + !message.startsWith('merge') && + !message.startsWith('*') +) { + console.log('You are not allowed to commit directly to master or alpha branch') + process.exit(1) +} diff --git a/package.json b/package.json index fb33c8fa..06a8cdd2 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "version": "1.0.24", "description": "演示 uni-app x 框架的组件、接口、模板", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "check-commit": "node ./git-hooks/check-commit.cjs" }, "repository": "https://gitcode.net/dcloud/hello-uni-app-x", "keywords": [ @@ -88,4 +88,4 @@ } } } -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index 93313705..e02edb4f 100644 --- a/readme.md +++ b/readme.md @@ -6,10 +6,18 @@ uni-app x [开发文档](https://uniapp.dcloud.net.cn/uni-app-x/) 项目下的js文件为自动化测试的nodejs文件,uni-app x手机端没有js引擎,是纯原生的。[自动化测试详见](https://uniapp.dcloud.net.cn/worktile/auto/quick-start.html) #### 页面截图对比测试 -测试用例文件路径:pages/pages.test.js +测试用例文件路径:pages/pages.test.js 其中 pages 变量中保存了所有需要截图对比测试的页面地址,如果有新增示例页面需要截图对比测试将页面地址添加到此变量即可。 **注意** - 添加到截图对比测试的页面列表,修改内容涉及到变更,需要在测试平台删除基准图 - 动态内容页面不适合截图对比测试,不要添加到截图对比测试的页面列表中 + +#### 代码提交 + +仅dev分支允许创建新的提交,master分支与alpha分支仅允许从其他分支cherry-pick或merge。为防止提交代码到错误的分支,可以通过如下方式创建git hook在提交代码时进行检查。 + +```bash +npx husky@9.0.11 +``` -- GitLab