|
| 1 | +name: PR Line Lint |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, ready_for_review, synchronize] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + line-ending-check: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Get list of changed files |
| 21 | + id: changed-files |
| 22 | + run: | |
| 23 | + changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) |
| 24 | + echo "Changed files:" |
| 25 | + echo "$changed_files" |
| 26 | + echo "files<<EOF" >> $GITHUB_OUTPUT |
| 27 | + echo "$changed_files" >> $GITHUB_OUTPUT |
| 28 | + echo "EOF" >> $GITHUB_OUTPUT |
| 29 | +
|
| 30 | + - name: Check for missing newlines |
| 31 | + id: newline-check |
| 32 | + run: | |
| 33 | + readarray -t changed_files <<< "${{ steps.changed-files.outputs.files }}" |
| 34 | + files_without_newline="" |
| 35 | + for file in "${changed_files[@]}"; do |
| 36 | + if [ -f "$file" ] && [ "$(tail -c 1 "$file" | wc -l)" -eq 0 ]; then |
| 37 | + files_without_newline+="- ${file}\n" # ํฌ๋งท์ ๋ง์ถ๊ธฐ ์ํด ํ์ผ ์ด๋ฆ์ ๋ฐฑํฑ์ผ๋ก ๊ฐ์๋๋ค. |
| 38 | + fi |
| 39 | + done |
| 40 | + if [ -n "$files_without_newline" ]; then |
| 41 | + echo "Files without newline at end:" |
| 42 | + echo -e "$files_without_newline" |
| 43 | + echo "files<<EOF" >> $GITHUB_OUTPUT |
| 44 | + echo -e "$files_without_newline" >> $GITHUB_OUTPUT |
| 45 | + echo "EOF" >> $GITHUB_OUTPUT |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Set Job Summary |
| 50 | + if: always() |
| 51 | + run: | |
| 52 | + if [ -n "${{ steps.newline-check.outputs.files }}" ]; then |
| 53 | + echo "์๋ ํ์ผ๋ค์ ๊ณต๋ฐฑ ์ค์ ์ถ๊ฐํด์ฃผ์ธ์." >> $GITHUB_STEP_SUMMARY |
| 54 | + echo -e "${{ steps.newline-check.outputs.files }}" >> $GITHUB_STEP_SUMMARY |
| 55 | + else |
| 56 | + echo "๋ชจ๋ ํ์ผ์ด ์ฌ๋ฐ๋ฅด๊ฒ ๊ฐํ ์ฒ๋ฆฌ๋์ด ์์ต๋๋ค." >> $GITHUB_STEP_SUMMARY |
| 57 | + fi |
0 commit comments