feat: java support for sdk17 #2825
Workflow file for this run
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: Format code | |
on: | |
pull_request: | |
branches: [ master ] | |
paths-ignore: | |
- '**.md' | |
- '.github/workflows/**' | |
env: | |
java_version: '17' | |
java_distribution: 'zulu' | |
jobs: | |
formatting: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK ${{ env.java_version }}-${{ env.java_distribution }} | |
uses: actions/setup-java@v3 | |
with: | |
java-version: ${{ env.java_version }} | |
distribution: ${{ env.java_distribution }} | |
- name: Cache Gradle packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: ${{ runner.os }}-gradle | |
- name: Run Spotless Check | |
run: | | |
./gradlew spotlessCheck --quiet --continue 2>&1 | tee spotless-output.txt | |
if grep -q "\.java" spotless-output.txt; then | |
exit 1 | |
fi | |
- name: Upload Spotless Output | |
if: ${{ failure() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: spotless-output | |
path: spotless-output.txt | |
- name: Extract Affected Files | |
if: ${{ failure() }} | |
run: | | |
grep "\.java" spotless-output.txt > affected-files.txt || true | |
- name: Comment PR if code does not comply to Google Java style guide | |
if: ${{ failure() }} | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const files = fs.existsSync('affected-files.txt') ? fs.readFileSync('affected-files.txt', 'utf8').trim().split('\n') : []; | |
if (files.length === 0) return; | |
const actionsDashboardUrl = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}`; | |
const commentBody = `### 🚨 Code Formatting Issue 🚨\n\n` | |
+ `This contribution does not follow the conventions set by the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html).\n\n` | |
+ `Please run the following command at the root of the project to fix formatting errors:\n\n` | |
+ "```sh\n./gradlew spotlessApply\n```\n\n" | |
+ `<details><summary><strong>🗂️ Affected files</strong></summary>\n${files.map(file => `- \`${file.trim()}\``).join('\n')}</details>\n\n` | |
+ `[Go to the Actions Dashboard to download the full Spotless output](${actionsDashboardUrl})\n\n`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: commentBody | |
}); |