Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:HaUI-HIT-AnodisO/Control-Vaccina…
Browse files Browse the repository at this point in the history
…tion-Services into ai
  • Loading branch information
Anodis108 committed Nov 24, 2024
2 parents 3862826 + 3243460 commit 72eee3b
Show file tree
Hide file tree
Showing 9 changed files with 2,220 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Commitlint

on:
pull_request:
branches:
- '**' # Kiểm tra commit trên tất cả các nhánh trước khi merge
push:
branches:
- '**' # Kiểm tra commit khi đẩy lên bất kỳ nhánh nào

jobs:
commitlint:
runs-on: ubuntu-22.04
steps:
# Bước 1: Checkout mã nguồn
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Lấy toàn bộ lịch sử commit

# Bước 2: Cài đặt các phụ thuộc cần thiết
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y git curl
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo DEBIAN_FRONTEND=noninteractive apt install -y nodejs
npm install
# Bước 3: In ra phiên bản của các công cụ
- name: Print versions
run: |
git --version
node --version
npm --version
npx commitlint --version
# Bước 4: Cài đặt commitlint nếu chưa cài đặt
- name: Install commitlint
run: |
npm install @commitlint/cli @commitlint/config-conventional
# Bước 5: Kiểm tra commit trên Pull Request (PR)
- name: Validate PR commits with commitlint
if: github.event_name == 'pull_request'
run: |
npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
# Bước 6: Kiểm tra commit của push
- name: Validate push commit with commitlint
if: github.event_name == 'push'
run: |
npx commitlint --from HEAD~1 --to HEAD --verbose
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/node_modules
__pycache__/
*.pyc
*.pdf
*.jpg
*.log
env/
target/
2 changes: 2 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
npx --no-install commitlint --edit "$1"
39 changes: 39 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Format and lint code
echo "🪄 In the process of formatting and linting code."
npx lint-staged || exit 1 # Dừng lại nếu linting gặp lỗi

echo "✨ All code is beautiful ✨"

# Get the current branch name
branch_name=$(git rev-parse --abbrev-ref HEAD)

# Define branch naming convention regex
branch_regex="^(feature|bugfix|hotfix|release|docs|ci)(\/[a-z0-9._-]+)?$"

# Allowed email for protected branches
allowed_email="[email protected]"

# Check if pushing to a protected branch
if [ "$branch_name" = "develop" ] || [ "$branch_name" = "uat" ] || [ "$branch_name" = "prod" ]; then
email=$(git config user.email)

if [ "$email" != "$allowed_email" ]; then
echo "⛔️ Error: User '$email' is not allowed to push to the '$branch_name' branch."
exit 1
fi
echo "✅ Skipping branch name check for '$branch_name' with user email '$email'."

else
# Check if the branch name matches the convention
if ! echo "$branch_name" | grep -Eq "$branch_regex"; then
echo "⛔️ Error: Branch name '$branch_name' does not follow the naming convention."
echo "Allowed patterns: feature/*, bugfix/*, hotfix/*, release/*, docs/*"
exit 1
fi
fi

# Allow the commit if all checks pass
exit 0
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"arrowParens": "always",
"tabWidth": 2,
"semi": false,
"printWidth": 100,
"bracketSameLine": true,
"jsxSingleQuote": true,
"bracketSpacing": true,
"useTabs": false,
"singleQuote": true,
"embeddedLanguageFormatting": "auto",
"proseWrap": "preserve",
"trailingComma": "all",
"quoteProps": "as-needed"
}
9 changes: 9 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'chore', 'docs', 'style', 'refactor', 'test']],
'subject-case': [2, 'never', ['sentence-case']],
'scope-case': [2, 'always', 'lower-case'],
'header-max-length': [2, 'always', 72],
},
}
Loading

0 comments on commit 72eee3b

Please sign in to comment.