docs: add gitlab example to check all commits in merge request
Description
Add an example for Gitlab CI/CD that shows how to check all commits in merge request.
Also solves this question on Stackoverflow.
Motivation and Context
Current CI/CD guide shows examples how to validate single commit only in Gitlab CI/CD.
Usage examples
// commitlint.config.js
module.exports = {};
echo "your commit message here" |Β commitlint # fails/passes
How Has This Been Tested?
I've tested this with -V on branch with multiple commits (including one non-valid commit).
Positive (multiple valid commits):
// Gitlab CI/CD runner
// ...
$ npx commitlint -V --from $CI_MERGE_REQUEST_DIFF_BASE_SHA --to $CI_COMMIT_SHA
β§ input: chore: good
β found 0 problems, 0 warnings
β§ input: chore: bad
β found 0 problems, 0 warnings
β§ input: feat(cicd): run commitlint in pipeline
β found 0 problems, 0 warnings
// ...
Negative (multiple commits including one invalid):
// Gitlab CI/CD runner
// ...
$ npx commitlint -V --from $CI_MERGE_REQUEST_DIFF_BASE_SHA --to $CI_COMMIT_SHA
β§ input: chore: good
β found 0 problems, 0 warnings
β§ input: bad
β subject may not be empty [subject-empty]
β type may not be empty [type-empty]
β found 2 problems, 0 warnings
β Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
β§ input: feat(cicd): run commitlint in pipeline
β found 0 problems, 0 warnings
// ...
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [x] Chore (documentation update)
Checklist:
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
@knocte wdyt?
I haven't used GitLab in ages. Hey @bliuchak, shouldn't this test first that the variable CI_MERGE_REQUEST_DIFF_BASE_SHA contains a value? (Because, if it doesn't, then the CI job is being spawned by a push, not a mergeRequest, and then in that case we wouldn't want to fail?)
Please re-open when this continues