- 1. Introduction
- 2. Getting Started
- 3. Workflow Configuration
- 4. Example YAML Configuration
- 5. Validation Checks
- 6. Troubleshooting
- 7. Sample Repository
- 8. Conclusion
This document provides guidelines for setting up Continuous Integration and Continuous Deployment (CI/CD) to validate MR Title for projects on GitLab. It aims to ensure consistent merge request titles across all projects.
Before you begin, ensure you have a Gitlab account, and a basic understanding of Gitlab workflows.
Create a .gitlab-ci.yml
file in your project to define your workflow.
Specify in which stage your workflow should run. Stage used is validate
.
Define the gitlab runner tag in which your workflow will run. For example - python-3.11.9
.
Specify the logic of the checks which needs to be checked for merge request validation.
Here is an example of a basic Gitlab Actions workflow file for MR Title Validation:
stages:
- validate
validate_merge_request_title:
stage: validate
tags:
- python-3.11.9
script:
- 'echo "Validating merge request title: $CI_MERGE_REQUEST_TITLE"'
- |
if echo "$CI_MERGE_REQUEST_TITLE" | grep -Eq "^(build|chore|ci|docs|feat|fix|perf|refactor|style|test|sample): [a-z0-9 ]{0,50}$"; then
echo "PR title is as per standards"
else
echo "PR title is not as per standards. PR title must start with one of the following prefixes: build, chore, ci, docs, feat, fix, perf, refactor, style, test, sample. PR title content must not exceed 50 characters and shouldn't have any upper case letter character."
exit 1
fi
only:
- merge_requests
- triggers
- MR title must start with the following prefixes: build, chore, ci, docs, feat, fix, perf, refactor, style, test, sample.
- MR title content must not exceed 50 characters.
- MR title shouldn't have any upper case letter character.
If your CI build fails, check the logs in Gitlab Actions. Ensure your MR Title follows the above checks to pass the validation.
Explore this for practical demonstration of MR Title Validation CI setups.
Setting up a CI pipeline for MR Title Validation provides several benefits:
- Consistency: Ensures uniform pull request titles for easier understanding and management.
- Communication: Enhances clarity and collaboration among team members.
- Efficiency: Streamlines the review process by providing immediate context to reviewers.
- Compliance: Automatically enforces naming conventions and standards, reducing manual checks.
Additional checks for MR title validation can be incorporated as per project requirements.