mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 19:17:48 +00:00 
			
		
		
		
	feat: add gh action to check logging percentage (#7688)
This commit is contained in:
		
							
								
								
									
										55
									
								
								.github/workflows/logging_percentage_check.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								.github/workflows/logging_percentage_check.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| name: Log Lines Percentage Check | ||||
|  | ||||
| on: | ||||
|   pull_request: | ||||
|     branches: | ||||
|       - develop | ||||
|  | ||||
| jobs: | ||||
|   log_lines_check: | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     steps: | ||||
|       - name: Checkout repository | ||||
|         uses: actions/checkout@v2 | ||||
|  | ||||
|       - name: Check for log lines and calculate percentage | ||||
|         run: | | ||||
|           # Define the log line pattern | ||||
|           LOG_LINE_PATTERN="Rails\.logger" | ||||
|  | ||||
|           # Get the list of changed files in the pull request | ||||
|           CHANGED_FILES=$(git diff --name-only) | ||||
|  | ||||
|           # Initialize a flag to track if any files have insufficient log lines | ||||
|           INSUFFICIENT_LOGS=0 | ||||
|  | ||||
|           for file in $CHANGED_FILES; do | ||||
|             if [[ $file =~ \.rb$ && ! $file =~ _spec\.rb$ ]]; then | ||||
|               # Count the total number of lines in the file | ||||
|               total_lines=$(wc -l < "$file") | ||||
|  | ||||
|               # Count the number of log lines in the file | ||||
|               log_lines=$(grep -c "$LOG_LINE_PATTERN" "$file") | ||||
|  | ||||
|               # Calculate the percentage of log lines | ||||
|               if [ "$total_lines" -gt 0 ]; then | ||||
|                 percentage=$(awk "BEGIN { pc=100*${log_lines}/${total_lines}; i=int(pc); print (pc-i<0.5)?i:i+1 }") | ||||
|               else | ||||
|                 percentage=0 | ||||
|               fi | ||||
|  | ||||
|               # Check if the percentage is less than 5% | ||||
|               if [ "$percentage" -lt 5 ]; then | ||||
|                 echo "Error: Log lines percentage is less than 5% ($percentage%) in $file. Please add more log lines using Rails.logger statements." | ||||
|                 INSUFFICIENT_LOGS=1 | ||||
|               else | ||||
|                 echo "Log lines percentage is $percentage% in $file. Code looks good!" | ||||
|               fi | ||||
|             fi | ||||
|           done | ||||
|  | ||||
|           # If any files have insufficient log lines, fail the action | ||||
|           if [ "$INSUFFICIENT_LOGS" -eq 1 ]; then | ||||
|             exit 1 | ||||
|           fi | ||||
		Reference in New Issue
	
	Block a user
	 Vishnu Narayanan
					Vishnu Narayanan