diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index f5cf4c3b..5c69807a 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -1,10 +1,13 @@ -name: Conventional Commitlint +name: Commit Linter on: push: branches: ["main"] pull_request: +permissions: + contents: read + pull-requests: read jobs: commitlint: runs-on: ubuntu-latest @@ -13,5 +16,22 @@ jobs: contents: read pull-requests: read steps: - - name: Conventional Commitlint - uses: opensource-nepal/commitlint@v1 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: lts/* + - name: Install commitlint + run: npm install -D @commitlint/cli @commitlint/config-conventional + - name: Print versions + run: | + git --version + node --version + npm --version + npx commitlint --version + + - name: Validate PR commits with commitlint + if: github.event_name == 'pull_request' + run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose diff --git a/.gitignore b/.gitignore index e62a0fa3..e6eff21e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,7 @@ rebar3.crashdump doc !_index.md guides +# don't commit the stuff required for commitlint to work +node_modules +package-lock.json +package.json \ No newline at end of file diff --git a/commitlint.config.ts b/commitlint.config.ts new file mode 100644 index 00000000..f3c86500 --- /dev/null +++ b/commitlint.config.ts @@ -0,0 +1,39 @@ +import { + RuleConfigCondition, + RuleConfigSeverity, + TargetCaseType, +} from "@commitlint/types"; + +export default { + parserPreset: "conventional-changelog-conventionalcommits", + rules: { + "body-leading-blank": [RuleConfigSeverity.Warning, "always"] as const, + "body-max-line-length": [RuleConfigSeverity.Error, "always", 100] as const, + "footer-leading-blank": [RuleConfigSeverity.Warning, "always"] as const, + "footer-max-line-length": [ + RuleConfigSeverity.Error, + "always", + 100, + ] as const, + "header-max-length": [RuleConfigSeverity.Error, "always", 100] as const, + "header-trim": [RuleConfigSeverity.Error, "always"] as const, + "subject-case": [ + RuleConfigSeverity.Error, + "never", + ["sentence-case", "start-case", "pascal-case", "upper-case"], + ] as [RuleConfigSeverity, RuleConfigCondition, TargetCaseType[]], + "subject-empty": [RuleConfigSeverity.Error, "never"] as const, + "subject-full-stop": [RuleConfigSeverity.Error, "never", "."] as const, + "type-case": [RuleConfigSeverity.Error, "always", "lower-case"] as const, + "type-empty": [RuleConfigSeverity.Error, "never"] as const, + "type-enum": [ + RuleConfigSeverity.Error, + "always", + [ + "chore", + "feat", + "fix", + ], + ] as [RuleConfigSeverity, RuleConfigCondition, string[]], + }, +}; diff --git a/justfile b/justfile index 7bc735e8..cf9b55b9 100644 --- a/justfile +++ b/justfile @@ -8,3 +8,8 @@ changelogs: git cliff 29b747722addf39ce40014ee1a905a973c9044be.. --include-path "${dir}/**" --workdir ${dir} -o ${dir}/CHANGELOG.md fi done + +# lint the commits between HEAD and the point from `origin/main` this branch was created from +commit-lint: + npm install -D @commitlint/cli @commitlint/config-conventional + npx commitlint --verbose --from `git merge-base --fork-point origin/main` --to HEAD