From 9f04bbb280ef53024f45219669f7452a606e87b7 Mon Sep 17 00:00:00 2001 From: ThisPath Date: Mon, 30 Dec 2024 00:19:20 +0900 Subject: [PATCH] feature: add rules for line linting and file names (#10) --- .github/pull_request_template.md | 1 + .github/workflows/check-lint-names.yaml | 82 +++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/check-lint-names.yaml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 89e492a..56433a6 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,6 +10,7 @@ Fixes # (issue) ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] 커밋 컨벤션을 확인하셨나요? +- [ ] black formatter를 통한 line inting을 확인 하셨나요? - **Tag**: Select the appropriate tag for this PR: - [ ] `feature` - [ ] `fix` diff --git a/.github/workflows/check-lint-names.yaml b/.github/workflows/check-lint-names.yaml new file mode 100644 index 0000000..f32d9e6 --- /dev/null +++ b/.github/workflows/check-lint-names.yaml @@ -0,0 +1,82 @@ +name: Check Line Linting and File Names + +on: + pull_request: + +jobs: + linelint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # PR 라벨 확인 + - name: Get PR labels + id: pr-labels + run: | + pr_number="${{ github.event.pull_request.number }}" + labels_json=$(gh pr view $pr_number --json labels -q '.labels[].name') + if [ -n "$labels_json" ]; then + echo "has_maintenance=$(echo $labels_json | grep -q 'maintenance' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT + else + echo "has_maintenance=false" >> $GITHUB_OUTPUT + fi + env: + GH_TOKEN: ${{ github.token }} + + # 줄바꿈 체크 + - name: Check for missing end line breaks + run: | + # 따옴표를 제거하고 파일 목록 가져오기 + files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr -d '"') + success=true + + echo "변경된 파일 목록:" + echo "$files" + + echo "## 줄바꿈 누락 파일" >> $GITHUB_STEP_SUMMARY + for file in $files; do + if [ -s "$file" ] && [ "$(tail -c 1 $file | wc -l)" -eq 0 ]; then + echo "발견된 줄바꿈 누락: $file" + echo "- $file" >> $GITHUB_STEP_SUMMARY + success=false + fi + done + + if [ "$success" = false ]; then + echo -e "\n:warning: 파일 끝의 누락된 줄바꿈을 추가해 주세요." >> $GITHUB_STEP_SUMMARY + exit 1 + fi + + # 제어문자 체크 + - name: Check for control characters in filenames + run: | + files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr -d '"') + success=true + + echo "## 제어문자가 포함된 파일명" >> $GITHUB_STEP_SUMMARY + for file in $files; do + # basename으로 파일명만 추출하고 따옴표 제거 + filename=$(basename "$file" | tr -d '"') + + # 백슬래시로 시작하는 제어문자들 체크 (\b, \n, \r, \t 등) + if printf '%q' "$filename" | grep -q '\\[bnrtfv]' || \ + + # 일반적인 제어문자들 체크 (0x00-0x1F, 0x7F) + echo -n "$filename" | LC_ALL=C grep -q '[[:cntrl:]]' || \ + + # 특수 제어문자들 체크 + echo -n "$filename" | grep -q $'[\x00-\x1F\x7F]' || \ + + # 이스케이프 시퀀스 체크 + [[ "$filename" =~ (\\[0-7]{1,3}|\\x[0-9a-fA-F]{1,2}) ]]; then + echo "- $file (제어문자 포함)" >> $GITHUB_STEP_SUMMARY + success=false + fi + done + + if [ "$success" = false ]; then + echo -e "\n:warning: 파일명에서 제어문자를 제거해 주세요." >> $GITHUB_STEP_SUMMARY + exit 1 + fi