-
Notifications
You must be signed in to change notification settings - Fork 38
143 lines (133 loc) · 5 KB
/
pull_request_code_warning.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: "[Pull Request] Code Warning"
on:
pull_request:
types: [opened, synchronize, reopened]
paths-ignore:
- '.github/**'
- '**/deploy/**'
- '**/Dockerfile'
- '**/*.dockerfile'
- '**/*.dockerignore'
- '**/LICENSE'
- '**/AUTHORS'
- '**/.husky/**'
- '**/commitlint.config.js'
- '**/.lintstagedrc.js'
- '**/*.md'
- '**/*.env'
branches:
- master
- feature-*
workflow_dispatch:
jobs:
review:
runs-on: ubuntu-latest
env:
NODE_ENV: 'development'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# checkout only the files we need
sparse-checkout: |
apps
packages
# fetch all history so we can check diff between PR and base branch
fetch-depth: 0
- name: Copy changed files to specific directory
run: |
mkdir -p changed_files
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }} | while read file; do
if [ -f "$file" ]; then
rsync -R "$file" changed_files/
else
echo "Skipping missing file: $file"
fi
done
- name: Display changed files
run: |
echo "Changed files copied to 'changed_files' directory:"
find changed_files -type f
- name: Check for TODOs
id: check_todo
working-directory: changed_files
run: |
echo "Checking for TODOs..."
TODO_FILES=$(grep -rl "// TODO" . --exclude-dir=.git --exclude=apps/web/public/lottie.js || true)
TODO_COUNT=0
if [ -n "$TODO_FILES" ]; then
echo "The following files contain TODO:"
echo "$TODO_FILES"
TODO_COUNT=$(echo "$TODO_FILES" | wc -l)
echo "::warning:: Found $TODO_COUNT file(s) with TODO."
else
echo "No TODOs found."
fi
echo "todo_count=$TODO_COUNT" >> $GITHUB_ENV
- name: Check for console.log
id: check_console_log
working-directory: changed_files
run: |
echo "Checking for console.log..."
LOG_FILES=$(find . -type f \
! -path "./.git/*" \
! -path "./**/tests/**/*.spec.ts" \
! -path "./**/__tests__/**/*.test.ts" \
! -path "./apps/web/build/*" \
! -path "./apps/web/public/*" \
! -path "./apps/web/vite.config.js" \
! -path "./apps/web/src/lib/site-analytics/*" \
! -path "./packages/mirinae/scripts/*" \
! -path "./packages/mirinae/cli/*" \
! -path "./**/*.stories.ts" \
-exec grep -l "console\.log" {} + || true)
LOG_COUNT=0
if [ -n "$LOG_FILES" ]; then
echo "The following files contain console.log:"
echo "$LOG_FILES"
LOG_COUNT=$(echo "$LOG_FILES" | wc -l)
echo "::warning:: Found $LOG_COUNT file(s) with console.log."
else
echo "No console.log found."
fi
echo "console_log_count=$LOG_COUNT" >> $GITHUB_ENV
- name: Check for console.debug
id: check_console_debug
working-directory: changed_files
run: |
echo "Checking for console.debug..."
DEBUG_FILES=$(find . -type f \
! -path "./.git/*" \
! -path "./**/tests/**/*.spec.ts" \
! -path "./**/__tests__/**/*.test.ts" \
! -path "./apps/web/build/*" \
! -path "./apps/web/public/*" \
! -path "./apps/web/src/store/display/display-store.ts" \
! -path "./apps/web/src/lib/config/index.ts" \
! -path "./packages/mirinae/scripts/*" \
! -path "./packages/mirinae/cli/*" \
! -path "./packages/core-lib/src/space-connector/token-api.ts" \
! -path "./**/*.stories.ts" \
-exec grep -l "console\.debug" {} + || true)
DEBUG_COUNT=0
if [ -n "$DEBUG_FILES" ]; then
echo "The following files contain console.debug:"
echo "$DEBUG_FILES"
DEBUG_COUNT=$(echo "$DEBUG_FILES" | wc -l)
echo "::warning:: Found $DEBUG_COUNT file(s) with console.debug."
else
echo "No console.debug found."
fi
echo "console_debug_count=$DEBUG_COUNT" >> $GITHUB_ENV
- name: Fail if issues found
run: |
echo "TODO Count: $todo_count"
echo "console.log Count: $console_log_count"
echo "console.debug Count: $console_debug_count"
if [ "$todo_count" -gt 0 ] || [ "$console_log_count" -gt 0 ] || [ "$console_debug_count" -gt 0 ]; then
echo "::error:: Workflow failed. TODO count: $todo_count, console.log count: $console_log_count, console.debug count: $console_debug_count"
exit 1
else
echo "No issues found. Workflow passed."
fi