Feature/vision subsystem #14
Workflow file for this run
This file contains hidden or 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: Pull Request Build Check | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| - development | |
| jobs: | |
| build: | |
| name: Build and Check Code Format | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'gradle' | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build with Gradle | |
| run: ./gradlew build --console=plain | |
| - name: Check code formatting | |
| id: spotless | |
| run: | | |
| # Run spotlessCheck and capture output | |
| set -o pipefail | |
| if ./gradlew spotlessCheck --console=plain 2>&1 | tee spotless-output.txt; then | |
| echo "formatted=true" >> $GITHUB_OUTPUT | |
| echo "✓ Code formatting check passed" | |
| else | |
| echo "formatted=false" >> $GITHUB_OUTPUT | |
| echo "⚠️ Code formatting violations detected" | |
| fi | |
| continue-on-error: true | |
| - name: Comment on PR with formatting violations | |
| if: steps.spotless.outputs.formatted == 'false' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const output = fs.readFileSync('spotless-output.txt', 'utf8'); | |
| // Extract the relevant violation information | |
| const violationMatch = output.match(/The following files had format violations:([\s\S]*?)(?:Run '\.\/gradlew|$)/); | |
| const violations = violationMatch ? violationMatch[0] : output; | |
| const comment = `## ⚠️ Code Formatting Issues Detected | |
| The following formatting violations were found: | |
| \`\`\` | |
| ${violations} | |
| \`\`\` | |
| **To fix these issues locally:** | |
| \`\`\`bash | |
| ./gradlew spotlessApply | |
| \`\`\` | |
| Then commit and push the changes.`; | |
| // Check if we already commented | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('Code Formatting Issues Detected') | |
| ); | |
| if (botComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: comment | |
| }); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: comment | |
| }); | |
| } | |
| - name: Comment on PR - All checks passed | |
| if: steps.spotless.outputs.formatted == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| // Check if there's an existing formatting comment to delete | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('Code Formatting Issues Detected') | |
| ); | |
| if (botComment) { | |
| // Delete the old formatting warning since it's now fixed | |
| await github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id | |
| }); | |
| } | |
| // Post success comment | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: '✓ Build successful and code formatting check passed!' | |
| }); |