[PR] Code Warning #7
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
name: "[PR] 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 the PR branch not the base branch | |
ref: ${{ github.event.pull_request.head.sha }} | |
# checkout only the files we need | |
sparse-checkout: | | |
apps | |
packages | |
- name: All checkout files | |
run: | | |
ls -al | |
- name: Check for TODOs | |
id: check_todo | |
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) | |
else | |
echo "No TODOs found." | |
fi | |
echo "::warning:: Found $TODO_COUNT file(s) with TODO." | |
echo "todo_count=$TODO_COUNT" >> $GITHUB_ENV | |
- name: Check for console.log | |
id: check_console_log | |
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/*" \ | |
-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) | |
else | |
echo "No console.log found." | |
fi | |
echo "::warning:: Found $LOG_COUNT file(s) with console.log." | |
echo "console_log_count=$LOG_COUNT" >> $GITHUB_ENV | |
- name: Check for console.debug | |
id: check_console_debug | |
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 "./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) | |
else | |
echo "No console.debug found." | |
fi | |
echo "::warning:: Found DEBUG_COUNT file(s) with console.debug." | |
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 |