Build and test #9
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
# Build and test the mod | |
name: Build and test | |
on: | |
workflow_dispatch: | |
inputs: | |
timeout: | |
description: 'Timeout for runServer (seconds)' | |
required: false | |
default: 90 | |
type: number | |
client-only: | |
description: 'Do not execute runServer' | |
required: false | |
default: false | |
type: boolean | |
concurrency: | |
group: build-and-test-${{ github.head_ref || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Apply patch to settings.gradle | |
run: | | |
if [ -f settings.gradle.patch ]; then | |
patch -p0 < settings.gradle.patch | |
fi | |
- name: Apply patch to gradle.properties | |
run: sed -i 's/debug_all = false/debug_all = true/g' gradle.properties | |
- name: Setup Build | |
uses: ./.github/actions/build_setup | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Compile the mod | |
run: ./gradlew --info --scan assemble | |
- name: Upload Jars | |
uses: actions/upload-artifact@v4 | |
with: | |
name: GTExpert-Core | |
path: build/libs/*.jar | |
retention-days: 31 | |
- name: Run post-build checks | |
id: build_mod | |
run: ./gradlew --info build | |
- name: Attempt to make a PR fixing spotless errors | |
if: ${{ failure() && steps.build_mod.conclusion == 'failure' && github.event_name == 'pull_request' && !github.event.pull_request.draft }} | |
run: | | |
git reset --hard | |
git checkout "${PR_BRANCH}" | |
./gradlew --info spotlessApply || exit 1 | |
git diff --exit-code && exit 1 | |
git config user.name "GitHub 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 ${{ github.event.pull_request.head.ref }} 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 | |
if: ${{ !inputs.client-only }} | |
run: | | |
mkdir -p run | |
echo "eula=true" > run/eula.txt | |
# Set a constant seed with a village at spawn | |
echo "stop" > run/stop.txt | |
timeout ${{ inputs.timeout }} ./gradlew runServer 2>&1 < run/stop.txt | tee -a server.log || true | |
- name: Test no errors reported during server run | |
if: ${{ !inputs.client-only }} | |
run: | | |
chmod +x ./scripts/test_no_error_reports | |
./scripts/test_no_error_reports |