diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 0000000000000000000000000000000000000000..f67cae7dd57f05ed0c2ce5d82c940854bcffabc0 --- /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 0000000000000000000000000000000000000000..e79ede4b65767bbb3b4b94bef54722adedc6d7a8 --- /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 fb33c8fa2ea59a6d201471167e68110e8ea44a2a..06a8cdd22ce7988d00ec51d4e156e3fd518c85a8 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 933137058e221dcf123b6e0419ca43a4a6dce650..e02edb4f8abc6c3a660abbcd2267c7eb6a45d9ed 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 +```