|
| 1 | +# Build and test the mod |
| 2 | +name: Build and test |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + timeout: |
| 8 | + description: 'Timeout for runServer (seconds)' |
| 9 | + required: false |
| 10 | + default: 90 |
| 11 | + type: number |
| 12 | + client-only: |
| 13 | + description: 'Do not execute runServer' |
| 14 | + required: false |
| 15 | + default: false |
| 16 | + type: boolean |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: build-and-test-${{ github.head_ref || github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-and-test: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + permissions: |
| 27 | + contents: write |
| 28 | + pull-requests: write |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout Repository |
| 32 | + uses: actions/checkout@v6 |
| 33 | + - name: Apply patch to buildscript.properties |
| 34 | + run: sed -i 's/debug_all = false/debug_all = true/g' buildscript.properties |
| 35 | + |
| 36 | + - name: Setup Build |
| 37 | + uses: ./.github/actions/build_setup |
| 38 | + |
| 39 | + - name: Compile the mod |
| 40 | + run: ./gradlew --info --scan --stacktrace assemble |
| 41 | + |
| 42 | + - name: Upload Jars |
| 43 | + uses: actions/upload-artifact@v5 |
| 44 | + with: |
| 45 | + name: GTExpert-Core |
| 46 | + path: build/libs/*.jar |
| 47 | + retention-days: 31 |
| 48 | + |
| 49 | + - name: Run post-build checks |
| 50 | + id: build_mod |
| 51 | + run: ./gradlew --info build |
| 52 | + |
| 53 | + - name: Attempt to make a PR fixing spotless errors |
| 54 | + if: ${{ failure() && steps.build_mod.conclusion == 'failure' && github.event_name == 'pull_request' && !github.event.pull_request.draft }} |
| 55 | + run: | |
| 56 | + git reset --hard |
| 57 | + git checkout "${github.ref_name}" |
| 58 | + ./gradlew --info spotlessApply || exit 1 |
| 59 | + git diff --exit-code && exit 1 |
| 60 | + git config user.name "GitHub Actions" |
| 61 | + git config user.email "<>" |
| 62 | + git switch -c "${FIXED_BRANCH}" |
| 63 | + git commit -am "spotlessApply" |
| 64 | + git push --force-with-lease origin "${FIXED_BRANCH}" |
| 65 | + gh pr create \ |
| 66 | + --head "${FIXED_BRANCH}" \ |
| 67 | + --base "${github.ref_name}" \ |
| 68 | + --title "Spotless apply for branch ${{ github.event.pull_request.head.ref }} for #${{ github.event.pull_request.number }}" \ |
| 69 | + --body "Automatic spotless apply to fix formatting errors, applies to PR #${{ github.event.pull_request.number }}" \ |
| 70 | + 2>&1 | tee pr-message.log || true |
| 71 | + gh pr comment "${github.ref_name}" -F pr-message.log || true |
| 72 | + shell: bash # ensures set -eo pipefail |
| 73 | + env: |
| 74 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + FIXED_BRANCH: ${{ github.head_ref }}-spotless-fixes |
| 76 | + |
| 77 | + - name: Run server for ${{ inputs.timeout }} seconds |
| 78 | + if: ${{ !inputs.client-only }} |
| 79 | + run: | |
| 80 | + mkdir -p run |
| 81 | + echo "eula=true" > run/eula.txt |
| 82 | + # Set a constant seed with a village at spawn |
| 83 | + echo "stop" > run/stop.txt |
| 84 | + timeout ${{ inputs.timeout }} ./gradlew runServer 2>&1 < run/stop.txt | tee -a server.log || true |
| 85 | +
|
| 86 | + - name: Test no errors reported during server run |
| 87 | + if: ${{ !inputs.client-only }} |
| 88 | + run: | |
| 89 | + chmod +x ./scripts/test_no_error_reports.sh |
| 90 | + ./scripts/test_no_error_reports.sh |
0 commit comments