forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI(github): add math check and cross-platform build
- Loading branch information
1 parent
2b41e57
commit 729ab6d
Showing
3 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | ||
|
||
name: arm64-Platform Matrix | ||
|
||
on: | ||
push: | ||
branches: [ "exp/arm64" ] | ||
pull_request: | ||
branches: [ "exp/arm64" ] | ||
|
||
jobs: | ||
build: | ||
|
||
name: ${{ matrix.os }} - ${{ matrix.os-version }} | ||
runs-on: ${{ matrix.runner }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
# Apple Silicon runners (using latest available) | ||
- os: macOS | ||
arch: arm64 | ||
runner: macos-14 | ||
os-version: "14" | ||
- os: macOS | ||
arch: arm64 | ||
runner: macos-15 | ||
os-version: "15" | ||
|
||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. | ||
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | ||
|
||
- name: Build with Gradle Wrapper | ||
run: ./gradlew clean build --no-daemon |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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 | ||
filename=$(basename "$file") | ||
if [[ "$filename" == "StrictMathWrapper.java" || "$filename" == "MathWrapper.java" ]]; then | ||
continue | ||
fi | ||
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 "❌ Error: Forbidden Math usage found in the following files:" | ||
cat math_usage.txt | ||
echo "math_found=true" >> $GITHUB_OUTPUT | ||
echo "Please use org.tron.common.math.StrictMathWrapper instead of direct Math usage." | ||
else | ||
echo "✅ No forbidden 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 forbidden usage of \`java.lang.Math\` in the following files: | ||
\`\`\` | ||
${findings} | ||
\`\`\` | ||
**Please review if this usage is intended.** | ||
> [!CAUTION] | ||
> Note: You should use \`org.tron.common.math.StrictMathWrapper\`. | ||
> If you need to use \`java.lang.Math\`, please provide a justification. | ||
`; | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
body: body | ||
}); | ||
- name: Fail if Math usage found | ||
if: steps.check-math.outputs.math_found == 'true' | ||
run: exit 1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | ||
|
||
name: X86_64-Platform Matrix | ||
|
||
on: | ||
push: | ||
branches: [ "exp/arm64" ] | ||
pull_request: | ||
branches: [ "exp/arm64" ] | ||
|
||
jobs: | ||
build: | ||
|
||
name: ${{ matrix.os }} - ${{ matrix.os-version }} | ||
runs-on: ${{ matrix.runner }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
# Macos Intel runners | ||
- os: macOS | ||
arch: x86_64 | ||
runner: macos-12 | ||
os-version: "12" | ||
- os: macOS | ||
arch: x86_64 | ||
runner: macos-13 | ||
os-version: "13" | ||
# Linux x86_64 runners | ||
- os: Linux | ||
arch: x86_64 | ||
runner: ubuntu-20.04 | ||
os-version: "20.04" | ||
- os: Linux | ||
arch: x86_64 | ||
runner: ubuntu-22.04 | ||
os-version: "22.04" | ||
|
||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 8 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '8' | ||
distribution: 'zulu' | ||
|
||
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. | ||
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | ||
|
||
- name: Build with Gradle Wrapper | ||
run: ./gradlew clean build --no-daemon |