Skip to content

Commit

Permalink
👷 ci(.husky/pre-commit): adding pre-commit hook using validate-branch…
Browse files Browse the repository at this point in the history
…-name

added new branch validation hook and documentation
  • Loading branch information
jebarpg committed Jul 22, 2024
1 parent 9a87c8d commit d5b6c3c
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# validate branch name before commit
npx validate-branch-name
58 changes: 32 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
"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",
"upgrade:full": "bun run upgrade:clean && bun run upgrade"
},
"validate-branch-name": {
"pattern": "^(main|develop){1}$|^(feature|fix|hotfix|release|experimental|chore|docs|dependabot|renovate)/.+$",
"errorMsg": "Your branch name does not meet the Brand Naming conventions.\nPlease review ./repo_management_files/branchNamingConventions.md and ./package.json#L128 for rules"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-gitmoji-adapter",
Expand All @@ -139,43 +143,38 @@
".prettierrc.json",
"license",
"readme-api.md",
"readme.md",
"commit-template.hbs",
"readme.md",
"commitlint.config.ts",
"default-template.hbs",
"emojitypescommitmessages.txt",
"jest.config.json",
"package-lock.json",
"package.json",
"release.config.ts",
"renovate.json",
"tsconfig.json",
"emojitypescommitmessages.txt",
"typedoc.json",
"tsconfig.json",
".vscode/settings.json",
"public/.gitkeep",
"repo_management_files/cz-emoji-type-extract.js",
"repo_management_files/cz-type-extract.js",
"repo_management_files/directorystructuredocument.md",
"repo_management_files/extractfilescopes.js",
"repo_management_files/branchnamingconventions.md",
"repo_management_files/genericcommitmessages.md",
"repo_management_files/gitmojisemver-extract.js",
"repo_management_files/issues.sh",
"repo_management_files/labels.sh",
"repo_management_files/packagejsondocument.md",
".github/dependabot.yml",
".github/workflows/build.yml",
".github/workflows/docs.yml",
".github/workflows/lint.yml",
".github/workflows/pr.yml",
".github/workflows/release.yml",
".github/workflows/test.yml",
"public/.gitkeep",
".husky/commit-msg",
".husky/pre-commit",
".husky/prepare-commit-msg",
".husky/_/.gitignore",
".husky/_/applypatch-msg",
".husky/_/commit-msg",
".husky/_/h",
".husky/_/applypatch-msg",
".husky/_/post-applypatch",
".husky/_/h",
".husky/_/post-checkout",
".husky/_/post-commit",
".husky/_/post-merge",
Expand All @@ -186,27 +185,34 @@
".husky/_/pre-push",
".husky/_/pre-rebase",
".husky/_/prepare-commit-msg",
"src/app.ts",
"src/bin/.gitkeep",
"src/controllers/.gitkeep",
"src/plugins/.gitkeep",
"src/middleware/.gitkeep",
"src/configs/.gitkeep",
"src/models/.gitkeep",
"src/views/.gitkeep",
"src/utils/.gitkeep",
"src/routes/.gitkeep",
".github/dependabot.yml",
".github/workflows/build.yml",
".github/workflows/lint.yml",
".github/workflows/pr.yml",
".github/workflows/release.yml",
".github/workflows/docs.yml",
".github/workflows/test.yml",
"test/.gitkeep",
"test/app.test.ts",
"test/bin/.gitkeep",
"test/configs/.gitkeep",
"test/controllers/.gitkeep",
"test/middleware/.gitkeep",
"test/models/.gitkeep",
"test/plugins/.gitkeep",
"test/utils/.gitkeep",
"test/routes/.gitkeep",
"test/configs/.gitkeep",
"test/views/.gitkeep",
"test/utils/.gitkeep"
"test/plugins/.gitkeep",
"src/app.ts",
"src/controllers/.gitkeep",
"src/bin/.gitkeep",
"src/middleware/.gitkeep",
"src/plugins/.gitkeep",
"src/models/.gitkeep",
"src/configs/.gitkeep",
"src/routes/.gitkeep",
"src/utils/.gitkeep",
"src/views/.gitkeep"
],
"questions": {
"scope": "Specify a scope: "
Expand Down
147 changes: 147 additions & 0 deletions repo_management_files/branchNamingConventions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Branch Naming Convention

NOTICE:

* Please review [`release.config.ts` (click)](../release.config.ts) to configure the release branches appropriately for your project.
* 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.
* Dependabot and Renovate are also used for automated package updating and are included in the rules for validate-branch-name.

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.

## General Rules

* **Use Lowercase Letters**: Branch names should be in lowercase letters.
* **Use Hyphens (-) as Separators**: Use hyphens to separate words within branch names.
* **Avoid Special Characters**: Do not use special characters other than hyphens. Avoid spaces, slashes, underscores, etc.
* **Be Descriptive but Concise**: Branch names should be clear and descriptive but not excessively long.

## Branch Categories

### Feature Branches

**Prefix**: `feature/`

**Purpose**: For new features and enhancements.

**Format**:

`feature/<short-description>`

**Example**:
`feature/add-user-login`

### Fix Branches

**Prefix**: `Fix/`

**Purpose**: For bug fixes.

**Format**:
`fix/<short-description>`

**Example**:
`fix/fix-login-error`

### Hotfix Branches

**Prefix**: `hotfix/`

**Purpose**: For critical hotfixes that need to be released immediately.

**Format**:

`hotfix/<short-description>`

**Example**:

`hotfix/patch-security-vulnerability`

### Release Branches

**Prefix**: `release/`

**Purpose**: For preparing a new production release.

**Format**:

`release/<version>`

**Example**:

`release/1.0.0`

### Experimental Branches

**Prefix**: `experimental/`

**Purpose**: For experimental features or ideas that may not be included in the main project.

**Format**:

`experimental/<short-description>`

**Example**:

`experimental/prototype-new-ui`

### Chore Branches

**Prefix**: `chore/`

**Purpose**: For non-feature updates like refactoring, updating dependencies, etc.

**Format**:

`chore/<short-description>`

**Example**:

`chore/update-dependencies`

### Documentation Branches

**Prefix**: `docs/`

**Purpose**: For updates and additions to documentation.

**Format**:

`docs/<short-description>`

**Example**:

`docs/update-readme`

### Dependabot Branches

**Prefix**: `dependabot/`

**Purpose**: For automated dependabot package updates.

**Format**:

`dependabot/<short-description>`

**Example**:

`dependabot/npm_and_yarn/semantic-release/github-10.0.6`

### Renovate Branches

**Prefix**: `renovate/`

**Purpose**: For automated renovate package updates.

**Format**:

`renovate/<short-description>`

**Example**:

`renovate/prettier-plugin-organize-imports-4.x`

## Integration with Semantic Release

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.

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 comments on commit d5b6c3c

Please # to comment.