From c3e3dc4b83b835cf87f49150fd6048faf48dc78b Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Wed, 6 Sep 2023 07:53:16 +0900 Subject: [PATCH] chore: add commit lint action (#8) This adds an action for linting commit messages. Following the conventional commit rule helps to automatically generate changelogs in the future. Signed-off-by: Daeyeon Jeong --- .github/workflows/commit_lint.yml | 32 ++++++++++++++++++++++++++ .github/workflows/commitlint.config.js | 20 ++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/commit_lint.yml create mode 100644 .github/workflows/commitlint.config.js diff --git a/.github/workflows/commit_lint.yml b/.github/workflows/commit_lint.yml new file mode 100644 index 0000000..e90ef22 --- /dev/null +++ b/.github/workflows/commit_lint.yml @@ -0,0 +1,32 @@ +name: Lint commit message + +on: [pull_request] + +env: + NODE_VERSION: lts/* + +jobs: + lint-commit-message: + runs-on: ubuntu-latest + steps: + - name: Compute number of commits + id: nb-of-commits + run: | + echo "plusOne=$((${{ github.event.pull_request.commits }} + 1))" >> $GITHUB_OUTPUT + echo "minusOne=$((${{ github.event.pull_request.commits }} - 1))" >> $GITHUB_OUTPUT + - uses: actions/checkout@v3 + with: + fetch-depth: ${{ steps.nb-of-commits.outputs.plusOne }} + persist-credentials: false + - run: git reset HEAD^2 + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + - name: Install required dependencies + run: | + npm install -g @commitlint/cli @commitlint/config-conventional + - name: Validate the first commit message + run: | + commitlint -V --config .github/workflows/commitlint.config.js \ + --to HEAD~${{ steps.nb-of-commits.outputs.minusOne }} diff --git a/.github/workflows/commitlint.config.js b/.github/workflows/commitlint.config.js new file mode 100644 index 0000000..20ea5a8 --- /dev/null +++ b/.github/workflows/commitlint.config.js @@ -0,0 +1,20 @@ +module.exports = { + extends: ["@commitlint/config-conventional"], + rules: { + "header-max-length": () => [2, "always", 72], + "type-enum": () => [ + 2, + "always", + ["feat", "fix", "refactor", "chore", "test", "doc", "release", "revert"], + ], + "scope-enum": [ + 2, + "always", + ["core", "database", "functions", "storage", "test"], + ], + "body-max-line-length": [0, "always"], + "footer-max-line-length": [0, "always"], + }, + helpUrl: + "https://github.com/flutter-tizen/flutterfire/blob/main/CONTRIBUTING.md", +};