mirror of
https://github.com/GTNewHorizons/GTNH-Actions-Workflows.git
synced 2025-07-03 02:41:29 +02:00
93 lines
3.2 KiB
YAML
93 lines
3.2 KiB
YAML
# 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://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
|
|
|
name: Build and test
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
timeout:
|
|
description: 'Timeout for runServer (seconds)'
|
|
required: false
|
|
default: 90
|
|
type: number
|
|
workspace:
|
|
description: 'setupCIWorkspace/setupDecompWorkspace'
|
|
required: false
|
|
default: "setupCIWorkspace"
|
|
type: string
|
|
client-only:
|
|
description: 'Do not execute runServer'
|
|
required: false
|
|
default: false
|
|
type: boolean
|
|
|
|
jobs:
|
|
build-and-test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout mod repo
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Checkout workflows repo
|
|
uses: actions/checkout@v3
|
|
with:
|
|
repository: GTNewHorizons/GTNH-Actions-Workflows
|
|
path: .gtnh-workflows
|
|
fetch-depth: 0
|
|
|
|
- name: Set up JDK 8
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
java-version: '8'
|
|
distribution: 'temurin'
|
|
cache: gradle
|
|
|
|
- name: Grant execute permission for gradlew
|
|
run: chmod +x gradlew
|
|
|
|
- name: Setup the workspace
|
|
run: ./gradlew --info --stacktrace ${{ inputs.workspace }}
|
|
|
|
- name: Build the mod
|
|
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' && !github.event.pull_request.draft }}
|
|
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
|
|
if: ${{ !inputs.client-only }}
|
|
run: |
|
|
mkdir run
|
|
echo "eula=true" > run/eula.txt
|
|
echo "stop" > run/stop.txt
|
|
timeout ${{ inputs.timeout }} ./gradlew --info --stacktrace 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 .gtnh-workflows/scripts/test_no_error_reports
|
|
.gtnh-workflows/scripts/test_no_error_reports
|