Skip to content

CI(github): add math check and cross-platform build #1

CI(github): add math check and cross-platform build

CI(github): add math check and cross-platform build #1

Workflow file for this run

name: Check Math Usage
on:
push:
branches: [ "exp/arm64" ]
pull_request:
branches: [ "exp/arm64" ]
workflow_dispatch:
jobs:
check-math:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for java.lang.Math usage
id: check-math
run: |
echo "Checking for java.lang.Math usage..."
find . -type f -name "*.java" -exec cat {} \; > all_java_content.txt
echo "Files with Math usage:" > math_usage.txt
find . -type f -name "*.java" | while read file; do
if grep -l "^import[[:space:]]*java\.lang\.Math\b" "$file" > /dev/null; then
echo "$file (contains import)" >> math_usage.txt
continue
fi
if perl -0777 -ne 'print "$ARGV\n" if /java\s*\.\s*lang\s*\.\s*Math\s*\./' "$file" > /dev/null; then
echo "$file (contains fully qualified)" >> math_usage.txt
continue
fi
if perl -0777 -ne '
s!/\*.*?\*/!!gs;
s!//[^\n]*!!g;
print "$ARGV\n" if /(?<!Strict)(?<![\w\.])Math\s*\./' "$file" > /dev/null; then
echo "$file (contains Math usage)" >> math_usage.txt
fi
done
if [ -s math_usage.txt ]; then
echo "Found Math usage in the following files:"
cat math_usage.txt
echo "math_found=true" >> $GITHUB_OUTPUT
else
echo "No Math usage found"
echo "math_found=false" >> $GITHUB_OUTPUT
fi
rm -f all_java_content.txt
- name: Upload findings
if: steps.check-math.outputs.math_found == 'true'
uses: actions/upload-artifact@v3
with:
name: math-usage-report
path: math_usage.txt
- name: Create comment
if: github.event_name == 'pull_request' && steps.check-math.outputs.math_found == 'true'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const findings = fs.readFileSync('math_usage.txt', 'utf8');
const body = `### Math Usage Detection Results
Found usage of \`java.lang.Math\` in the following files:
\`\`\`
${findings}
\`\`\`
Please review if this usage is intended.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});