From 3700d3b91d5aaa47d4f3c0e5032ff234ca13ec38 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Fri, 19 Aug 2022 11:12:58 +0100 Subject: [PATCH] Spotless auto-pr (#8) * Show detailed gradle logs and stacktraces on errors * Generate a new PR on spotless failures against the failing PR branch --- .github/workflows/build-and-test.yml | 30 +++++++++++++++++++++++++--- .github/workflows/release-tags.yml | 6 +++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 059fdee..09e6569 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -43,16 +43,40 @@ jobs: run: chmod +x gradlew - name: Setup the workspace - run: ./gradlew ${{ inputs.workspace }} + run: ./gradlew --info --stacktrace ${{ inputs.workspace }} - name: Build the mod - run: ./gradlew build + id: build_mod + run: ./gradlew --info --stacktrace build + + - name: Attempt to make a PR fixing spotless errors + if: ${{ failure() && steps.build_mod.conclusion == 'failure' && github.event_name == 'pull_request' }} + run: | + ./gradlew --info --stacktrace spotlessApply || exit 1 + git diff --exit-code && exit 1 + git config user.name "GitHub GTNH Actions" + git config user.email "<>" + git switch -c "${FIXED_BRANCH}" + git commit -am "spotlessApply" + git push --force-with-lease origin "${FIXED_BRANCH}" + gh pr create \ + --head "${FIXED_BRANCH}" \ + --base "${PR_BRANCH}" \ + --title "Spotless apply for branch ${PR_BRANCH} for #${{ github.event.pull_request.number }}" \ + --body "Automatic spotless apply to fix formatting errors, applies to PR #${{ github.event.pull_request.number }}" \ + 2>&1 | tee pr-message.log || true + gh pr comment "${PR_BRANCH}" -F pr-message.log || true + shell: bash # ensures set -eo pipefail + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_BRANCH: ${{ github.head_ref }} + FIXED_BRANCH: ${{ github.head_ref }}-spotless-fixes - name: Run server for ${{ inputs.timeout }} seconds run: | mkdir run echo "eula=true" > run/eula.txt - timeout ${{ inputs.timeout }} ./gradlew runServer 2>&1 | tee -a server.log || true + timeout ${{ inputs.timeout }} ./gradlew --info --stacktrace runServer 2>&1 | tee -a server.log || true - name: Test no errors reported during server run run: | diff --git a/.github/workflows/release-tags.yml b/.github/workflows/release-tags.yml index 508b588..bf2ed56 100644 --- a/.github/workflows/release-tags.yml +++ b/.github/workflows/release-tags.yml @@ -40,10 +40,10 @@ jobs: run: chmod +x gradlew - name: Setup the workspace - run: ./gradlew ${{ inputs.workspace }} + run: ./gradlew --info --stacktrace ${{ inputs.workspace }} - name: Build the mod - run: ./gradlew build + run: ./gradlew --info --stacktrace build # Continue on error in the following steps to make sure releases still get made even if one of the methods fails @@ -60,7 +60,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Publish to Maven - run: ./gradlew publish + run: ./gradlew --info --stacktrace publish continue-on-error: true env: MAVEN_USER: ${{ secrets.MAVEN_USER }}