mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 23:27:14 +00:00
Merge branch 'check-non-re2-regex-workflow' into ENG-2773
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
name: Detect Non-RE2 Regex
|
name: Detect Non-RE2 Regex
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, synchronize]
|
types: [opened, synchronize]
|
||||||
@@ -19,6 +18,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Scan backend diff for non-RE2 regex
|
- name: Scan backend diff for non-RE2 regex
|
||||||
run: |
|
run: |
|
||||||
|
# Extract only added lines (excluding file headers)
|
||||||
grep '^+' diff.txt | grep -v '^+++' | sed 's/^\+//' > added_lines.txt
|
grep '^+' diff.txt | grep -v '^+++' | sed 's/^\+//' > added_lines.txt
|
||||||
|
|
||||||
if [ ! -s added_lines.txt ]; then
|
if [ ! -s added_lines.txt ]; then
|
||||||
@@ -26,26 +26,28 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
regex_usage_pattern='(^|[^A-Za-z0-9_])(\/[^\/]+\/[gimsuy]*|new RegExp\()'
|
regex_usage_pattern='(^|[^A-Za-z0-9_"'"'"'`])(\/[^\/\n]+\/[gimsuyv]*|new RegExp\()'
|
||||||
|
|
||||||
# Find all added lines that contain the regex_usage_pattern.
|
# Find all added lines that contain regex patterns
|
||||||
grep -E "$regex_usage_pattern" added_lines.txt > potential_violations.txt
|
if grep -E "$regex_usage_pattern" added_lines.txt > potential_violations.txt 2>/dev/null; then
|
||||||
|
# Filter out lines that contain 'new RE2' (allowing for whitespace variations)
|
||||||
if [ -s potential_violations.txt ]; then # If any lines match the regex usage pattern
|
if grep -v -E 'new\s+RE2\s*\(' potential_violations.txt > actual_violations.txt 2>/dev/null && [ -s actual_violations.txt ]; then
|
||||||
# Filter out lines that also contain the string 'new RE2'
|
echo "🚨 ERROR: Found forbidden regex pattern in added/modified backend code."
|
||||||
grep -v 'new RE2' potential_violations.txt > actual_violations.txt
|
echo ""
|
||||||
|
echo "The following lines use raw regex literals (/.../) or new RegExp(...):"
|
||||||
if [ -s actual_violations.txt ]; then # If there are lines left after filtering out 'new RE2'
|
echo "Please replace with 'new RE2(...)' for RE2 compatibility."
|
||||||
echo "🚨 ERROR: Found forbidden regex pattern (raw literal '/.../' or 'new RegExp(...)') in added/modified backend code."
|
echo ""
|
||||||
echo "Please use 'new RE2(...)' for all regular expressions in the backend."
|
|
||||||
echo "Offending lines:"
|
echo "Offending lines:"
|
||||||
cat actual_violations.txt
|
cat actual_violations.txt
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# All lines that matched regex_usage_pattern also contained 'new RE2'.
|
|
||||||
echo "✅ All identified regex usages are correctly using 'new RE2(...)'."
|
echo "✅ All identified regex usages are correctly using 'new RE2(...)'."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# No lines matched the regex_usage_pattern at all.
|
echo "✅ No regex patterns found in added/modified backend lines."
|
||||||
echo "✅ No raw regex literals ('/.../') or 'new RegExp(...)' usage found in added/modified backend lines."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
- name: Cleanup temporary files
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
rm -f diff.txt added_lines.txt potential_violations.txt actual_violations.txt
|
||||||
|
|||||||
Reference in New Issue
Block a user