|
| 1 | + |
| 2 | +# Pull Request Title Validation CI/CD Setup on GitHub |
| 3 | + |
| 4 | +## Table of Contents |
| 5 | + |
| 6 | +- [1. Introduction](#1-introduction) |
| 7 | +- [2. Getting Started](#2-getting-started) |
| 8 | +- [3. Workflow Configuration](#3-workflow-configuration) |
| 9 | + - [3.1 Trigger](#31-trigger) |
| 10 | + - [3.2 Job](#32-job) |
| 11 | + - [3.3 Steps](#33-steps) |
| 12 | +- [4. Setting up config.json file](#4-setting-up-configjson-file) |
| 13 | +- [5. Example YAML Configuration](#5-example-yaml-configuration) |
| 14 | +- [6. Example config.json file Configuration](#6-example-configjson-file-configuration) |
| 15 | +- [7. Validation Checks](#7-validation-checks) |
| 16 | +- [8. Troubleshooting](#8-troubleshooting) |
| 17 | +- [9. Sample Repository](#9-sample-repository) |
| 18 | +- [10. Conclusion](#10-conclusion) |
| 19 | + - [Benefits of CI Setup](#benefits-of-ci-setup) |
| 20 | + - [Future Enhancements](#future-enhancements) |
| 21 | + |
| 22 | +## 1. Introduction |
| 23 | + |
| 24 | +This document provides guidelines for setting up Continuous Integration and Continuous Deployment (CI/CD) to validate PR Title for projects on GitHub using GitHub Actions. It aims to ensure consistent pull request titles across all projects. |
| 25 | + |
| 26 | +[Back to top](#table-of-contents) |
| 27 | + |
| 28 | +## 2. Getting Started |
| 29 | + |
| 30 | +Before you begin, ensure you have a GitHub account, and a basic understanding of GitHub workflows. |
| 31 | + |
| 32 | +[Back to top](#table-of-contents) |
| 33 | + |
| 34 | +## 3. Workflow Configuration |
| 35 | + |
| 36 | +Create a `.github/workflows` directory in your project. Inside this directory, create a YAML file (e.g., `pr_title_validation.yml`) to define your workflow. |
| 37 | + |
| 38 | +### 3.1 Trigger |
| 39 | + |
| 40 | +Specify when your workflow should run. Trigger to use is `pull_request_target` and its types are `opened`, `edited`, `synchronize`, `labeled`, `unlabeled`, `reopened`. |
| 41 | + |
| 42 | +### 3.2 Job |
| 43 | + |
| 44 | +Define job such as `check`. The job runs in a fresh virtual environment. |
| 45 | + |
| 46 | +### 3.3 Steps |
| 47 | + |
| 48 | +Within the job, define steps such as Get PR Title, Check PR Title. |
| 49 | + |
| 50 | +[Back to top](#table-of-contents) |
| 51 | + |
| 52 | +## 4. Setting up config.json file |
| 53 | + |
| 54 | +Create the config.json file `root/pr-title-checker-config.json`. Write the PR validation checks and messages in this file. |
| 55 | + |
| 56 | +[Back to top](#table-of-contents) |
| 57 | + |
| 58 | +## 5. Example YAML Configuration |
| 59 | + |
| 60 | +Here is an example of a basic GitHub Actions workflow file for PR Title Validation: |
| 61 | + |
| 62 | +```yaml |
| 63 | +name: "PR Title Checker" |
| 64 | +on: |
| 65 | + pull_request_target: |
| 66 | + types: |
| 67 | + - opened |
| 68 | + - edited |
| 69 | + - synchronize |
| 70 | + - labeled |
| 71 | + - unlabeled |
| 72 | + - reopened |
| 73 | + |
| 74 | +jobs: |
| 75 | + check: |
| 76 | + runs-on: ubuntu-latest |
| 77 | + steps: |
| 78 | + - name: Get PR Title |
| 79 | + id: get_pr_title |
| 80 | + run: | |
| 81 | + echo "Checking PR_TITLE = ${{ github.event.pull_request.title }}" |
| 82 | + |
| 83 | + - name: Check PR Title |
| 84 | + |
| 85 | + with: |
| 86 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + pass_on_octokit_error: false |
| 88 | + configuration_path: .github/pr-title-checker-config.json |
| 89 | +``` |
| 90 | +
|
| 91 | +[Back to top](#table-of-contents) |
| 92 | +
|
| 93 | +## 6. Example config.json file Configuration |
| 94 | +
|
| 95 | +Here is an example of config.json file for PR Title Validation: |
| 96 | +
|
| 97 | +```json |
| 98 | +{ |
| 99 | + "CHECKS": { |
| 100 | + "regexp": "^(build|chore|ci|docs|feat|fix|perf|refactor|style|test|sample): [a-z0-9 ]{0,50}$" |
| 101 | + }, |
| 102 | + "MESSAGES": { |
| 103 | + "success": "PR title is as per standards", |
| 104 | + "failure": "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.", |
| 105 | + "notice": "" |
| 106 | + } |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +[Back to top](#table-of-contents) |
| 111 | + |
| 112 | +## 7. Validation Checks |
| 113 | + |
| 114 | +1. PR title must start with the following prefixes: build, chore, ci, docs, feat, fix, perf, refactor, style, test, sample. |
| 115 | +2. PR title content must not exceed 50 characters. |
| 116 | +3. PR title shouldn't have any upper case letter character. |
| 117 | + |
| 118 | +[Back to top](#table-of-contents) |
| 119 | + |
| 120 | +## 8. Troubleshooting |
| 121 | + |
| 122 | +If your CI build fails, check the logs in GitHub Actions. Ensure your PR Title follows the above checks to pass the validation. |
| 123 | + |
| 124 | +[Back to top](#table-of-contents) |
| 125 | + |
| 126 | +## 9. Sample Repository |
| 127 | + |
| 128 | +[Repository Link](https://github.com/OsmosysSoftware/pr-lint-workflow-guide/tree/main) |
| 129 | + |
| 130 | +Explore this for practical demonstration of PR Title Validation CI setups. |
| 131 | + |
| 132 | +[Back to top](#table-of-contents) |
| 133 | + |
| 134 | +## 10. Conclusion |
| 135 | + |
| 136 | +### Benefits of CI Setup |
| 137 | + |
| 138 | +Setting up a CI pipeline for PR Title Validation provides several benefits: |
| 139 | + |
| 140 | +- Consistency: Ensures uniform pull request titles for easier understanding and management. |
| 141 | +- Communication: Enhances clarity and collaboration among team members. |
| 142 | +- Efficiency: Streamlines the review process by providing immediate context to reviewers. |
| 143 | +- Compliance: Automatically enforces naming conventions and standards, reducing manual checks. |
| 144 | + |
| 145 | +### Future Enhancements |
| 146 | + |
| 147 | +Additional checks for PR title validation can be incorporated as per project requirements. |
| 148 | + |
| 149 | +[Back to top](#table-of-contents) |
0 commit comments