Quay lại tài liệu

Tích hợp với GitHub

Hướng dẫn cách tích hợp Coding Standards vào quy trình CI/CD của bạn thông qua GitHub Actions hoặc GitHub App.

Sử dụng GitHub Action

Thêm Coding Standards vào quy trình CI/CD của bạn bằng cách thêm một bước trong file workflow.

Cấu hình cơ bản

name: Code Quality Check

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

jobs:
  coding-standards:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Run Coding Standards Check
        uses: your-username/coding-standards-action@v1
        with:
          rules: 'common,frontend'  # Các nhóm quy tắc cần kiểm tra
          fail-level: 'error'       # Mức độ lỗi để fail CI (error/warning)
          report-format: 'github'   # Format báo cáo (github/text/json)
Tùy chọn cấu hình
Các tham số có thể tùy chỉnh

rules

Danh sách các nhóm quy tắc cần kiểm tra, phân cách bằng dấu phẩy.

Ví dụ: common,frontend,backend

fail-level

Mức độ lỗi để fail CI.

Giá trị: error, warning, none

report-format

Định dạng báo cáo kết quả.

Giá trị: github, text, json, html

Tùy chỉnh quy tắc
Cách tùy chỉnh quy tắc áp dụng

Tạo file .coding-standards.yml trong thư mục gốc của dự án:

# .coding-standards.yml
rules:
  # Bật/tắt quy tắc cụ thể
  C001:
    enabled: true
    level: error
  
  # Tùy chỉnh ngưỡng
  C002:
    enabled: true
    level: warning
    config:
      threshold: 120
      
# Bỏ qua các file/thư mục
exclude:
  - 'dist/**'
  - 'node_modules/**'
  - '**/*.test.js'

Ví dụ kết quả

Ví dụ kết quả GitHub Action