|
| 1 | +name: Check Math Usage |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "exp/arm64" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "exp/arm64" ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + check-math: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Check for java.lang.Math usage |
| 18 | + id: check-math |
| 19 | + run: | |
| 20 | + echo "Checking for java.lang.Math usage..." |
| 21 | + |
| 22 | + find . -type f -name "*.java" -exec cat {} \; > all_java_content.txt |
| 23 | + |
| 24 | + echo "Files with Math usage:" > math_usage.txt |
| 25 | + |
| 26 | + find . -type f -name "*.java" | while read file; do |
| 27 | + if grep -l "^import[[:space:]]*java\.lang\.Math\b" "$file" > /dev/null; then |
| 28 | + echo "$file (contains import)" >> math_usage.txt |
| 29 | + continue |
| 30 | + fi |
| 31 | + |
| 32 | + if perl -0777 -ne 'print "$ARGV\n" if /java\s*\.\s*lang\s*\.\s*Math\s*\./' "$file" > /dev/null; then |
| 33 | + echo "$file (contains fully qualified)" >> math_usage.txt |
| 34 | + continue |
| 35 | + fi |
| 36 | + |
| 37 | + if perl -0777 -ne ' |
| 38 | + s!/\*.*?\*/!!gs; |
| 39 | + s!//[^\n]*!!g; |
| 40 | + print "$ARGV\n" if /(?<!Strict)(?<![\w\.])Math\s*\./' "$file" > /dev/null; then |
| 41 | + echo "$file (contains Math usage)" >> math_usage.txt |
| 42 | + fi |
| 43 | + done |
| 44 | + |
| 45 | + if [ -s math_usage.txt ]; then |
| 46 | + echo "Found Math usage in the following files:" |
| 47 | + cat math_usage.txt |
| 48 | + echo "math_found=true" >> $GITHUB_OUTPUT |
| 49 | + else |
| 50 | + echo "No Math usage found" |
| 51 | + echo "math_found=false" >> $GITHUB_OUTPUT |
| 52 | + fi |
| 53 | + |
| 54 | + rm -f all_java_content.txt |
| 55 | +
|
| 56 | + - name: Upload findings |
| 57 | + if: steps.check-math.outputs.math_found == 'true' |
| 58 | + uses: actions/upload-artifact@v3 |
| 59 | + with: |
| 60 | + name: math-usage-report |
| 61 | + path: math_usage.txt |
| 62 | + |
| 63 | + - name: Create comment |
| 64 | + if: github.event_name == 'pull_request' && steps.check-math.outputs.math_found == 'true' |
| 65 | + uses: actions/github-script@v6 |
| 66 | + with: |
| 67 | + script: | |
| 68 | + const fs = require('fs'); |
| 69 | + const findings = fs.readFileSync('math_usage.txt', 'utf8'); |
| 70 | + const body = `### Math Usage Detection Results |
| 71 | + |
| 72 | + Found usage of \`java.lang.Math\` in the following files: |
| 73 | + |
| 74 | + \`\`\` |
| 75 | + ${findings} |
| 76 | + \`\`\` |
| 77 | + |
| 78 | + Please review if this usage is intended.`; |
| 79 | + |
| 80 | + await github.rest.issues.createComment({ |
| 81 | + owner: context.repo.owner, |
| 82 | + repo: context.repo.repo, |
| 83 | + issue_number: context.issue.number, |
| 84 | + body: body |
| 85 | + }); |
0 commit comments