diff --git a/.github/workflows/lint-commit-message.yml b/.github/workflows/lint-commit-message.yml new file mode 100644 index 0000000000000..9d2245a817785 --- /dev/null +++ b/.github/workflows/lint-commit-message.yml @@ -0,0 +1,125 @@ +name: Lint commit message + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + lint: + runs-on: ubuntu-latest + continue-on-error: true + strategy: + matrix: + node-version: ['16'] + include: + - node-version: '16' + node-name: 'Latest' + outputs: + failed: ${{ steps.lint_commit.outputs.failed == 'true' }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Add dev branch + run: git branch dev origin/dev + - name: Setup pnpm + uses: pnpm/action-setup@v2 + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Cache ~/.pnpm-store + uses: actions/cache@v3 + env: + cache-name: cache-pnpm-store + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-${{ matrix.node-version }}-test-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.node-version }}-test-${{ env.cache-name }}- + ${{ runner.os }}-${{ matrix.node-version }}-test- + ${{ runner.os }}- + + - name: Install dependencies + run: pnpm i --frozen-lockfile + - name: Lint commit + id: lint_commit + run: pnpm lint:commit || echo "::set-output name=failed::true" + - uses: actions/upload-artifact@v2 + with: + name: commit-lint-report + path: ./commit-lint.txt + + on-success: + runs-on: ubuntu-latest + needs: lint + if: ${{ needs.lint.outputs.failed != 'true' }} + name: Lint successfully + steps: + - uses: actions-awesome/pr-helper@1.1.0 + with: + actions: 'maintain-comment, add-labels, remove-labels' + token: ${{ secrets.GITHUB_TOKEN }} + labels-to-add: 'CommitMessage::Qualified' + labels-to-remove: 'CommitMessage::Unqualified' + body-filter: '' + + on-failed: + runs-on: ubuntu-latest + needs: lint + name: Lint failed + if: ${{ needs.lint.outputs.failed == 'true' }} + steps: + - uses: actions/download-artifact@v2 + with: + name: commit-lint-report + + - name: Read lint result + id: read + uses: juliangruber/read-file-action@v1 + with: + path: ./commit-lint.txt + + - uses: actions-awesome/pr-helper@1.1.0 + with: + actions: 'remove-labels, add-labels, maintain-comment' + labels-to-remove: 'CommitMessage::Qualified' + labels-to-add: 'CommitMessage::Unqualified' + token: ${{ secrets.GITHUB_TOKEN }} + comment-body: | + Hello, @${{ github.event.pull_request.user.login }}, seems like your commit message contains some issues. + + 你好,@${{ github.event.pull_request.user.login }},你的提交消息不符合 Element Plus 的提交消息规范。 + + ``` + ${{ steps.read.outputs.content }} + ``` + + Please refer to [Commit Example](https://github.com/element-plus/element-plus/blob/dev/commit-example.md) for fixing it. + + 请参考 [提交示例](https://github.com/element-plus/element-plus/blob/dev/commit-example.md) 来修改你的提交消息。 + + Note that all your commits will be squashed into one for being linted, so you might need to revision your commits. + If you do not know how to do so, please refer to [Keeping git commit history clean](https://about.gitlab.com/blog/2018/06/07/keeping-git-commit-history-clean/) to update your commit message. + + 你的所有 commit(s) 会被合并为一个 commit 来被验证,所以你可能需要修改你之前的 commit(s) 消息。 + 如果你不知道如何来修改之前已经提交的记录,请参考[让你的 Git 提交历史保持干净](https://about.gitlab.com/blog/2018/06/07/keeping-git-commit-history-clean/)来修改。 + + If you find it hard to do it by yourself, run command below to use an intuitive tool for that. + + 如果你觉得自己写这个提交消息很难,请使用下面的命令来启动一个交互式工具来帮助你生成消息。 + + ```shell + pnpm cz + ``` + + Note that if you do not fix the commit message issue, your PR will be automatically closed within **3 days**. + + 请注意,如果你没有按照规范修改你的提交消息,你的 PR 将会在**三天**内被自动关闭。 + + Generated with :heart: by ElementPlusBot + + body-filter: '' + - run: exit 1 diff --git a/.husky/commit-msg b/.husky/commit-msg deleted file mode 100755 index e8511eaeaf61d..0000000000000 --- a/.husky/commit-msg +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx --no-install commitlint --edit $1 diff --git a/commit-example.md b/commit-example.md index 2acbdc855ae3a..eea74bd1263aa 100644 --- a/commit-example.md +++ b/commit-example.md @@ -1,5 +1,7 @@ # Why this chapter exists +Please refer to [Conventional Commits](https://www.conventionalcommits.org/) for more information. + A good commit message enables us: 1. To understand what the contributor is trying to do @@ -58,7 +60,7 @@ A good commit message enables us: Below is a template commit message for your reference. ```md -feat(components): [el-button] I did something with button +feat(components): [button] I did something with button Blank between subject and body is expected.(period is expected) Describes your change in one line or multi-line. @@ -75,3 +77,7 @@ For the subject header, the format is: ``` You can checkout the allowed values for **type** and **scope** in [commitlint.config.js](https://github.com/element-plus/element-plus/blob/c2ee36a7fc72b17742d43ecdff4e2912c416141d/commitlint.config.js#L57), + +## Useful links + +[Keeping git commit history clean](https://about.gitlab.com/blog/2018/06/07/keeping-git-commit-history-clean/) diff --git a/commitlint.config.js b/commitlint.config.js index 0022e442939f0..16bff1a88e669 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -31,14 +31,35 @@ const scopes = [ module.exports = { rules: { + /** + * type[scope]: [function] description + * ^^^^^ + */ 'scope-enum': (ctx) => getPackages(ctx).then((packages) => [ 2, 'always', [...packages, ...scopes], ]), + /** + * type[scope]: [function] description + * + * ^^^^^^^^^^^^^^ empty line. + * - Something here + */ 'body-leading-blank': [1, 'always'], + /** + * type[scope]: [function] description + * + * - something here + * + * ^^^^^^^^^^^^^^ + */ 'footer-leading-blank': [1, 'always'], + /** + * type[scope]: [function] description [No more than 72 characters] + * ^^^^^ + */ 'header-max-length': [2, 'always', 72], 'scope-case': [2, 'always', 'lower-case'], 'subject-case': [ @@ -50,6 +71,10 @@ module.exports = { 'subject-full-stop': [2, 'never', '.'], 'type-case': [2, 'always', 'lower-case'], 'type-empty': [2, 'never'], + /** + * type[scope]: [function] description + * ^^^^ + */ 'type-enum': [ 2, 'always', diff --git a/package.json b/package.json index 6a846d3410519..408c6627501b3 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "format": "prettier --write .", "lint": "eslint . --ext .vue,.js,.ts,.jsx,.tsx,.md,.json --max-warnings 0 && pretty-quick --check --branch dev", "lint:fix": "eslint --fix . --ext .vue,.js,.ts,.jsx,.tsx,.md,.json && pretty-quick --branch dev", + "lint:commit": "commitlint --from $(git merge-base dev HEAD) --to HEAD > ./commit-lint.txt", "docs:dev": "pnpm run -C docs dev", "docs:build": "pnpm run -C docs build", "docs:serve": "pnpm run -C docs serve",