-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add rules for line linting and file names (#10)
- Loading branch information
1 parent
b628693
commit 9f04bbb
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |