@@ -11,111 +11,18 @@ jobs:
1111 with :
1212 fetch-depth : 0
1313
14- - name : Get list of changed files
15- id : changed-files
14+ - name : Find files missing end line break
1615 run : |
17- changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | jq -R -s -c 'split("\n")[:-1]')
18- echo "changed_files: $changed_files"
19- echo "files=$changed_files" >> $GITHUB_OUTPUT
20-
21- - name : Check for missing newlines
22- id : newline-check
23- run : |
24- files_without_newline=()
25- while IFS= read -r file; do
26- if [ -f "$file" ]; then
27- last_char=$(tail -c 1 "$file")
28- if [ -n "$last_char" ]; then
29- files_without_newline+=("$file")
30- fi
16+ files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
17+ success=true
18+ for file in $files; do
19+ if [ "$(tail -c 1 $file | wc -l)" -eq 0 ]; then
20+ echo "- $file" >> $GITHUB_STEP_SUMMARY
21+ success=false
3122 fi
32- done < <(echo '${{ steps.changed-files.outputs.files }}' | jq -r '.[]')
23+ done
3324
34- if [ ${#files_without_newline[@]} -gt 0 ]; then
35- json_files=$(printf '%s\n' "${files_without_newline[@]}" | jq -R -s -c 'split("\n")[:-1]')
36- echo "files_without_newline: $json_files"
37- echo "files=$json_files" >> $GITHUB_OUTPUT
25+ if [ "$success" = false ]; then
26+ echo -e "\n:warning: ์ ํ์ผ๋ค์ ๋์ ๋๋ฝ๋ ์ค ๋ฐ๊ฟ์ ์ถ๊ฐํด ์ฃผ์ธ์." >> $GITHUB_STEP_SUMMARY
3827 exit 1
39- fi
40-
41- - name : Set Job Summary
42- if : failure()
43- run : |
44- if [ -n '${{ steps.newline-check.outputs.files }}' ]; then
45- echo "๐ ๏ธ ์๋ ํ์ผ๋ค์ ๊ณต๋ฐฑ ์ค์ ์ถ๊ฐํด์ฃผ์ธ์:" >> $GITHUB_STEP_SUMMARY
46- echo '${{ steps.newline-check.outputs.files }}' |
47- jq -r '.[]' |
48- sed 's/^/- /' >> $GITHUB_STEP_SUMMARY
49- fi
50-
51- label-lang :
52- runs-on : ubuntu-latest
53- continue-on-error : true
54-
55- permissions :
56- contents : read
57- pull-requests : write
58-
59- steps :
60- - uses : actions/checkout@v4
61- - uses : actions/setup-node@v4
62- with :
63- node-version : ' 20'
64- - run : echo '{}' > package.json
65- - run : npm install @octokit/rest node-fetch
66-
67- - name : Detect languages and add labels
68- env :
69- GITHUB_TOKEN : ${{ github.token }}
70- PR_NUM : ${{ github.event.number }}
71- run : |
72- node --input-type=module -e "
73- import { Octokit } from '@octokit/rest';
74- import path from 'path';
75- import fetch from 'node-fetch';
76-
77- const octokit = new Octokit({
78- auth: process.env.GITHUB_TOKEN,
79- request: { fetch }
80- });
81-
82- const extensionsToLanguages = {
83- js: 'js',
84- ts: 'ts',
85- py: 'py',
86- java: 'java',
87- kt: 'kotlin',
88- cpp: 'c++',
89- go: 'go',
90- exs: 'elixir',
91- swift: 'swift'
92- // ํ์ํ ๋ค๋ฅธ ํ์ฅ์์ ์ธ์ด ๋งคํ ์ถ๊ฐ
93- };
94-
95- async function run() {
96- const { data: files } = await octokit.pulls.listFiles({
97- owner: process.env.GITHUB_REPOSITORY.split('/')[0],
98- repo: process.env.GITHUB_REPOSITORY.split('/')[1],
99- pull_number: process.env.PR_NUM,
100- });
101-
102- const languages = new Set();
103- files.forEach(file => {
104- const ext = path.extname(file.filename).slice(1);
105- if (extensionsToLanguages[ext]) {
106- languages.add(extensionsToLanguages[ext]);
107- }
108- });
109-
110- if (languages.size > 0) {
111- await octokit.issues.addLabels({
112- owner: process.env.GITHUB_REPOSITORY.split('/')[0],
113- repo: process.env.GITHUB_REPOSITORY.split('/')[1],
114- issue_number: process.env.PR_NUM,
115- labels: Array.from(languages),
116- });
117- }
118- }
119-
120- run();
121- "
28+ fi
0 commit comments