【发布时间】:2021-07-22 05:01:53
【问题描述】:
我有一个 Github 存储库,在本地安装了 commitlint and husky,并希望在验证拉取请求时设置一个在每次推送提交时运行 commitlint 的工作流。 在主分支上,较旧的提交不遵循传统的提交规则。
我根据这条评论创建了一个单独的分支
https://github.com/conventional-changelog/commitlint/issues/586#issuecomment-657226800
我从这个工作流程开始
name: Run commitlint on pull request
on: pull_request
jobs:
run-commitlint-on-pull-request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Install dependencies
run: npm install
- name: Validate all commits from PR
run: npx commitlint --from HEAD~${{ github.event.pull_request.commits }} --to HEAD --verbose
我按照传统的提交规则又做了两次提交并开始了一个拉取请求
- 我预计工作流不会运行,因为我在主分支上还不存在。
- 实际上它运行
- 我希望工作流只检查 PR 提交
- 工作流失败,因为它开始验证主分支中的每个提交。而且由于我知道旧的提交不遵守规则,所以这永远不会通过。
我想到的第一个解决方案是重新设置所有内容并重命名每个提交以遵循规则,但这需要付出巨大的努力。
我不确定我是否必须在这里改进这一行
npx commitlint --from HEAD~${{ github.event.pull_request.commits }} --to HEAD --verbose
仅检查来自 PR 的提交(不幸的是,我不知道那里需要修复什么)。
您有什么想法或正在重新定位和重命名唯一的解决方案?
【问题讨论】:
-
试试
npx commitlint --from $commit --to HEAD --verbose || exit 1 -
抱歉,很遗憾,
|| exit 1没有帮助。工作流程仍然通过 -
npx commitlint是否以错误代码退出? -
抱歉,我没能找到。但是图像显示我必须修复我认为的语法?
-
IMO 如果你想逐个测试提交
--from $commit --to HEAD是错误的,它应该是一个提交,类似于--from $commit~ --to $commit。或者不是循环测试一次所有提交:--from ${{ github.base_ref }} --to ${{ github.head_ref }}without a loop。
标签: git push github-actions pull-request conventional-commits