Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add gitlab example to check all commits in merge request #4154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bliuchak
Copy link

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)
  • 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.

Copy link

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.

@escapedcat
Copy link
Member

@knocte wdyt?

@knocte
Copy link
Contributor

knocte commented Sep 18, 2024

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?)


```yml
lint:commit:
image: node:18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use image: commitlint/commitlint:latest?
Then you don't need to have the before_script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants