CI(github): add math check and cross-platform build #8
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: 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 | |
shell: bash | |
run: | | |
echo "Checking for java.lang.Math usage..." | |
touch math_usage.txt | |
while IFS= read -r file; do | |
perl -0777 -ne ' | |
s/"([^"\\]|\\.)*"//g; | |
s/'\''([^'\''\\]|\\.)*'\''//g; | |
s!/\*([^*]|\*[^/])*\*/!!g; | |
s!//[^\n]*!!g; | |
$hasMath = 0; | |
$hasMath = 1 if /^[\s]*import[\s]+java\.lang\.Math\b/m; | |
$hasMath = 1 if /\bjava\s*\.\s*lang\s*\.\s*Math\s*\./; | |
$hasMath = 1 if /(?<![\w\.])(?<!Strict)Math\s*\./; | |
print "$ARGV\n" if $hasMath; | |
' "$file" >> math_usage.txt | |
done < <(find . -type f -name "*.java") | |
sort -u math_usage.txt -o math_usage.txt | |
if [ -s math_usage.txt ]; then | |
echo "Found Math usage in:" | |
cat math_usage.txt | |
echo "math_found=true" >> $GITHUB_OUTPUT | |
else | |
echo "No Math usage found" | |
echo "math_found=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Upload findings | |
if: steps.check-math.outputs.math_found == 'true' | |
uses: actions/upload-artifact@v4 | |
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 | |
}); |