Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,36 @@ jobs:
with:
fetch-depth: 0

- name: Check for 1. missing end line breaks and 2. control characters in filenames
# 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 1. missing end line breaks and 2. control characters in filenames and 3. filename rules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 스탭이 너무 길어진 것 같은데 혹시 3개로 나누어주실 수 있으실까요? 그럼, 답안 제출자가 어떤 단계에서 실패했는지 좀 더 쉽게 파악할 수 있을 것 같아요.

run: |
# 필요한 값들 미리 설정
pr_author="${{ github.event.pull_request.user.login }}"
pr_number="${{ github.event.pull_request.number }}"
labels_json=$(gh pr view $pr_number --json labels -q '.labels[].name')
has_maintenance=false
if echo "$labels_json" | grep -q "maintenance"; then
has_maintenance=true
fi

# 따옴표를 제거하고 파일 목록 가져오기
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr -d '"')
echo "변경된 파일 목록:"
echo "$files"

success=true

# 줄바꿈 체크
Expand All @@ -35,13 +58,13 @@ jobs:
for file in $files; do
# basename으로 파일명만 추출하고 따옴표 제거
filename=$(basename "$file" | tr -d '"')

# 백슬래시로 시작하는 제어문자들 체크 (\b, \n, \r, \t 등)
if printf '%q' "$filename" | grep -q '\\[bnrtfv]'; then
echo "- $file (제어문자 포함)" >> $GITHUB_STEP_SUMMARY
success=false
fi

# 일반적인 제어문자들 체크 (0x00-0x1F, 0x7F)
if echo -n "$filename" | LC_ALL=C grep -q '[[:cntrl:]]'; then
echo "- $file (제어문자 포함)" >> $GITHUB_STEP_SUMMARY
Expand All @@ -53,17 +76,41 @@ jobs:
echo "- $file (제어문자 포함)" >> $GITHUB_STEP_SUMMARY
success=false
fi

# 이스케이프 시퀀스 체크
if [[ "$filename" =~ (\\[0-7]{1,3}|\\x[0-9a-fA-F]{1,2}) ]]; then
echo "- $file (제어문자 포함)" >> $GITHUB_STEP_SUMMARY
success=false
fi
done

# maintenance 라벨이 없는 경우에만 파일명 규칙 체크
if [ "$has_maintenance" != "true" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

라벨을 활용하는 아이디어 좋네요! 💡

echo -e "\n## 파일명 규칙 위반" >> $GITHUB_STEP_SUMMARY
for file in $files; do
if [ -f "$file" ]; then

# 파일명만 추출 (경로 제외)
filename=$(basename "$file")

# 파일명이 GitHub계정명인지 확인
shopt -s nocasematch
if [[ ! "$filename" = "$pr_author"* ]]; then
echo "- $file (파일명은 '$pr_author'형식으로 해주셔야 합니다)" >> $GITHUB_STEP_SUMMARY
success=false
fi
fi
done
fi

if [ "$success" = false ]; then
echo -e "\n:warning: 위 문제들을 해결해 주세요:" >> $GITHUB_STEP_SUMMARY
echo "1. 파일 끝의 누락된 줄바꿈을 추가해 주세요." >> $GITHUB_STEP_SUMMARY
echo "2. 파일명에서 제어문자를 제거해 주세요." >> $GITHUB_STEP_SUMMARY
if [[ ! "$pr_labels" =~ "maintenance" ]]; then
echo "3. 파일명은 반드시 'GitHub계정명'형식으로 해주셔야 합니다. (예: ${pr_author}.ts)" >> $GITHUB_STEP_SUMMARY
fi
exit 1
fi
env:
GH_TOKEN: ${{ github.token }}