Skip to content

Commit d5b6c3c

Browse files
committed
👷 ci(.husky/pre-commit): adding pre-commit hook using validate-branch-name
added new branch validation hook and documentation
1 parent 9a87c8d commit d5b6c3c

File tree

3 files changed

+181
-26
lines changed

3 files changed

+181
-26
lines changed

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# validate branch name before commit
2+
npx validate-branch-name

package.json

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@
124124
"upgrade:clean": "rm -rf node_modules && rm bun.lockb package-lock.json && bun pm cache rm && sudo bun i -g n && sudo n prune || true && sudo npm uninstall -g n && sudo rm -rf /usr/local/n && sudo rm -f /usr/local/bin/node",
125125
"upgrade:full": "bun run upgrade:clean && bun run upgrade"
126126
},
127+
"validate-branch-name": {
128+
"pattern": "^(main|develop){1}$|^(feature|fix|hotfix|release|experimental|chore|docs|dependabot|renovate)/.+$",
129+
"errorMsg": "Your branch name does not meet the Brand Naming conventions.\nPlease review ./repo_management_files/branchNamingConventions.md and ./package.json#L128 for rules"
130+
},
127131
"config": {
128132
"commitizen": {
129133
"path": "./node_modules/cz-gitmoji-adapter",
@@ -139,43 +143,38 @@
139143
".prettierrc.json",
140144
"license",
141145
"readme-api.md",
142-
"readme.md",
143146
"commit-template.hbs",
147+
"readme.md",
144148
"commitlint.config.ts",
145149
"default-template.hbs",
146-
"emojitypescommitmessages.txt",
147150
"jest.config.json",
148151
"package-lock.json",
149152
"package.json",
150153
"release.config.ts",
151154
"renovate.json",
152-
"tsconfig.json",
155+
"emojitypescommitmessages.txt",
153156
"typedoc.json",
157+
"tsconfig.json",
154158
".vscode/settings.json",
155-
"public/.gitkeep",
156159
"repo_management_files/cz-emoji-type-extract.js",
157160
"repo_management_files/cz-type-extract.js",
158161
"repo_management_files/directorystructuredocument.md",
159162
"repo_management_files/extractfilescopes.js",
163+
"repo_management_files/branchnamingconventions.md",
160164
"repo_management_files/genericcommitmessages.md",
161165
"repo_management_files/gitmojisemver-extract.js",
162166
"repo_management_files/issues.sh",
163167
"repo_management_files/labels.sh",
164168
"repo_management_files/packagejsondocument.md",
165-
".github/dependabot.yml",
166-
".github/workflows/build.yml",
167-
".github/workflows/docs.yml",
168-
".github/workflows/lint.yml",
169-
".github/workflows/pr.yml",
170-
".github/workflows/release.yml",
171-
".github/workflows/test.yml",
169+
"public/.gitkeep",
172170
".husky/commit-msg",
171+
".husky/pre-commit",
173172
".husky/prepare-commit-msg",
174173
".husky/_/.gitignore",
175-
".husky/_/applypatch-msg",
176174
".husky/_/commit-msg",
177-
".husky/_/h",
175+
".husky/_/applypatch-msg",
178176
".husky/_/post-applypatch",
177+
".husky/_/h",
179178
".husky/_/post-checkout",
180179
".husky/_/post-commit",
181180
".husky/_/post-merge",
@@ -186,27 +185,34 @@
186185
".husky/_/pre-push",
187186
".husky/_/pre-rebase",
188187
".husky/_/prepare-commit-msg",
189-
"src/app.ts",
190-
"src/bin/.gitkeep",
191-
"src/controllers/.gitkeep",
192-
"src/plugins/.gitkeep",
193-
"src/middleware/.gitkeep",
194-
"src/configs/.gitkeep",
195-
"src/models/.gitkeep",
196-
"src/views/.gitkeep",
197-
"src/utils/.gitkeep",
198-
"src/routes/.gitkeep",
188+
".github/dependabot.yml",
189+
".github/workflows/build.yml",
190+
".github/workflows/lint.yml",
191+
".github/workflows/pr.yml",
192+
".github/workflows/release.yml",
193+
".github/workflows/docs.yml",
194+
".github/workflows/test.yml",
199195
"test/.gitkeep",
200196
"test/app.test.ts",
201197
"test/bin/.gitkeep",
198+
"test/configs/.gitkeep",
202199
"test/controllers/.gitkeep",
203200
"test/middleware/.gitkeep",
204201
"test/models/.gitkeep",
205-
"test/plugins/.gitkeep",
202+
"test/utils/.gitkeep",
206203
"test/routes/.gitkeep",
207-
"test/configs/.gitkeep",
208204
"test/views/.gitkeep",
209-
"test/utils/.gitkeep"
205+
"test/plugins/.gitkeep",
206+
"src/app.ts",
207+
"src/controllers/.gitkeep",
208+
"src/bin/.gitkeep",
209+
"src/middleware/.gitkeep",
210+
"src/plugins/.gitkeep",
211+
"src/models/.gitkeep",
212+
"src/configs/.gitkeep",
213+
"src/routes/.gitkeep",
214+
"src/utils/.gitkeep",
215+
"src/views/.gitkeep"
210216
],
211217
"questions": {
212218
"scope": "Specify a scope: "
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Branch Naming Convention
2+
3+
NOTICE:
4+
5+
* Please review [`release.config.ts` (click)](../release.config.ts) to configure the release branches appropriately for your project.
6+
* This repository uses [validate-branch-name](https://www.npmjs.com/package/validate-branch-name) which gets ran as a pre-commit using [husky](https://github.com/typicode/husky) Git Hooks to keep branch naming consistent with the following conventions. Please review and customize the rules in the [package.json](../package.json#L128) file under `"validate-branch-name"` to fit your specific project needs.
7+
* Dependabot and Renovate are also used for automated package updating and are included in the rules for validate-branch-name.
8+
9+
This document outlines the branch naming conventions for our project to ensure consistency and clarity in our Git workflow, especially for GitHub Actions CI/CD pipelines. The conventions align with the use of Gitmoji, Commitizen, Conventional Changelog, and Semantic Release.
10+
11+
## General Rules
12+
13+
* **Use Lowercase Letters**: Branch names should be in lowercase letters.
14+
* **Use Hyphens (-) as Separators**: Use hyphens to separate words within branch names.
15+
* **Avoid Special Characters**: Do not use special characters other than hyphens. Avoid spaces, slashes, underscores, etc.
16+
* **Be Descriptive but Concise**: Branch names should be clear and descriptive but not excessively long.
17+
18+
## Branch Categories
19+
20+
### Feature Branches
21+
22+
**Prefix**: `feature/`
23+
24+
**Purpose**: For new features and enhancements.
25+
26+
**Format**:
27+
28+
`feature/<short-description>`
29+
30+
**Example**:
31+
`feature/add-user-login`
32+
33+
### Fix Branches
34+
35+
**Prefix**: `Fix/`
36+
37+
**Purpose**: For bug fixes.
38+
39+
**Format**:
40+
`fix/<short-description>`
41+
42+
**Example**:
43+
`fix/fix-login-error`
44+
45+
### Hotfix Branches
46+
47+
**Prefix**: `hotfix/`
48+
49+
**Purpose**: For critical hotfixes that need to be released immediately.
50+
51+
**Format**:
52+
53+
`hotfix/<short-description>`
54+
55+
**Example**:
56+
57+
`hotfix/patch-security-vulnerability`
58+
59+
### Release Branches
60+
61+
**Prefix**: `release/`
62+
63+
**Purpose**: For preparing a new production release.
64+
65+
**Format**:
66+
67+
`release/<version>`
68+
69+
**Example**:
70+
71+
`release/1.0.0`
72+
73+
### Experimental Branches
74+
75+
**Prefix**: `experimental/`
76+
77+
**Purpose**: For experimental features or ideas that may not be included in the main project.
78+
79+
**Format**:
80+
81+
`experimental/<short-description>`
82+
83+
**Example**:
84+
85+
`experimental/prototype-new-ui`
86+
87+
### Chore Branches
88+
89+
**Prefix**: `chore/`
90+
91+
**Purpose**: For non-feature updates like refactoring, updating dependencies, etc.
92+
93+
**Format**:
94+
95+
`chore/<short-description>`
96+
97+
**Example**:
98+
99+
`chore/update-dependencies`
100+
101+
### Documentation Branches
102+
103+
**Prefix**: `docs/`
104+
105+
**Purpose**: For updates and additions to documentation.
106+
107+
**Format**:
108+
109+
`docs/<short-description>`
110+
111+
**Example**:
112+
113+
`docs/update-readme`
114+
115+
### Dependabot Branches
116+
117+
**Prefix**: `dependabot/`
118+
119+
**Purpose**: For automated dependabot package updates.
120+
121+
**Format**:
122+
123+
`dependabot/<short-description>`
124+
125+
**Example**:
126+
127+
`dependabot/npm_and_yarn/semantic-release/github-10.0.6`
128+
129+
### Renovate Branches
130+
131+
**Prefix**: `renovate/`
132+
133+
**Purpose**: For automated renovate package updates.
134+
135+
**Format**:
136+
137+
`renovate/<short-description>`
138+
139+
**Example**:
140+
141+
`renovate/prettier-plugin-organize-imports-4.x`
142+
143+
## Integration with Semantic Release
144+
145+
Ensure branch names align with Semantic Release configuration to automate versioning and changelog generation. Typically, releases will be made from the `main` branch or specific `release/*` branches.
146+
147+
By following these conventions, we ensure a smooth and efficient workflow for our CI/CD pipeline, improve collaboration, and maintain a clean and organized repository.

0 commit comments

Comments
 (0)