From c6f40e4f8bab9ca44376953954f604f23266781d Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Wed, 20 Dec 2023 13:33:01 +0100 Subject: [PATCH] Add a bot comment that explains how to fix Spotless errors --- .github/workflows/gradle.yml | 45 ++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 3a10dd4..ff11262 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,5 +1,3 @@ -# 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: Java CI with Gradle on: @@ -17,24 +15,63 @@ on: jobs: build: runs-on: ubuntu-latest + steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Validate Gradle wrapper uses: gradle/wrapper-validation-action@v1 + - name: Set up Java 17 uses: actions/setup-java@v3 with: java-version: '17' distribution: 'microsoft' + - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Setup Gradle uses: gradle/gradle-build-action@v2 + + - name: Check code style with Spotless + id: spotless_check + run: ./gradlew spotlessCheck + continue-on-error: true + + - name: Comment on PR on Spotless failure + if: ${{ steps.spotless_check.outcome == 'failure' && github.event_name == 'pull_request' }} + uses: actions/github-script@v7 + with: + script: | + const prAuthor = context.payload.pull_request.user.login; + const codestyleUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/tree/master/codestyle`; + const commentBody = ` + Hi @${prAuthor}, thanks for the pull request! It seems there are some format violations that need to be fixed. + + If you're using Eclipse, please make sure to use the cleanup and format settings located in the [codestyle folder](${codestyleUrl}). This will help ensure consistency with the existing codebase. + + Alternatively, if you're not using Eclipse, you can also fix these violations by running the following command from the command line: + + \`\`\` + ./gradlew spotlessApply + \`\`\` + + Once you've done this, please commit the changes and push them to your branch. This should cause the check to pass and allow your pull request to be merged. + `; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); + - name: Execute Gradle build - run: ./gradlew build spotlessCheck + run: ./gradlew build + - name: VirusTotal scan - if: github.event_name == 'push' + if: ${{ github.event_name == 'push' }} uses: crazy-max/ghaction-virustotal@v4 with: vt_api_key: ${{ secrets.VIRUSTOTAL_API_KEY }}