From e712d8f149b5e4d9902e65929e47db151759fa28 Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Sun, 16 Jun 2024 02:23:29 +0200 Subject: [PATCH] initial commit --- .github/scripts/test_no_error_reports | 51 +++++++++++++ .github/workflows/build-and-test.yml | 100 ++++++++++++++++++++++++++ .github/workflows/release-tags.yml | 84 ++++++++++++++++++++++ .gitignore | 92 ++++++++++++++++++++++++ CREDITS | 23 ++++++ LICENSE | 21 ++++++ 6 files changed, 371 insertions(+) create mode 100755 .github/scripts/test_no_error_reports create mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/release-tags.yml create mode 100644 .gitignore create mode 100644 CREDITS create mode 100644 LICENSE diff --git a/.github/scripts/test_no_error_reports b/.github/scripts/test_no_error_reports new file mode 100755 index 0000000..1fcc739 --- /dev/null +++ b/.github/scripts/test_no_error_reports @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# bashsupport disable=BP5006 # Global environment variables +RUNDIR="run" \ + CRASH="crash-reports" \ + SERVERLOG="server.log" + +# enable nullglob to get 0 results when no match rather than the pattern +shopt -s nullglob + +# store matches in array +crash_reports=("$RUNDIR/$CRASH/crash"*.txt) + +# if array not empty there are crash_reports +if [ "${#crash_reports[@]}" -gt 0 ]; then + # get the latest crash_report from array + latest_crash_report="${crash_reports[-1]}" + { + printf 'Latest crash report detected %s:\n' "${latest_crash_report##*/}" + cat "$latest_crash_report" + } >&2 + exit 1 +fi + +if grep --quiet --fixed-strings 'Fatal errors were detected' "$SERVERLOG"; then + { + printf 'Fatal errors detected:\n' + cat server.log + } >&2 + exit 1 +fi + +if grep --quiet --fixed-strings 'The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED' \ + "$SERVERLOG"; then + { + printf 'Server force stopped:' + cat server.log + } >&2 + exit 1 +fi + +if ! grep --quiet --perl-regexp --only-matching '.+Done \(.+\)\! For help, type "help" or "\?"' "$SERVERLOG"; then + { + printf 'Server did not finish startup:' + cat server.log + } >&2 + exit 1 +fi + +printf 'No crash reports detected' +exit 0 diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..18ebf7a --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,100 @@ +# 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: Install Ubuntu dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y mesa-utils xvfb x11-xserver-utils + - name: Checkout mod repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Checkout workflows repo + uses: actions/checkout@v4 + with: + repository: FalsePattern/fpgradle-workflows + path: .fpgradle-workflows + fetch-depth: 0 + + - name: Validate gradle wrapper checksum + uses: gradle/wrapper-validation-action@v2 + + - name: Set up JDK versions + uses: actions/setup-java@v4 + with: + java-version: | + 8 + 17 + 21 + distribution: 'adopt' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Setup the workspace + run: ./gradlew --build-cache --info --stacktrace ${{ inputs.workspace }} + + - name: Compile the mod + run: ./gradlew --build-cache --info --stacktrace assemble + + - name: Attach compilation artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ github.repository_id }}-build-libs + path: build/libs/ + retention-days: 31 + + - name: Run post-build checks + id: build_mod + run: xvfb-run --server-args="-screen 0 1366x768x24" ./gradlew --build-cache --info --stacktrace build + + - name: Attach gradle reports + if: failure() && steps.build_mod.conclusion == 'failure' + uses: actions/upload-artifact@v4 + continue-on-error: true + with: + name: ${{ github.repository_id }}-reports + path: build/reports/ + retention-days: 31 + + - 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 "level-seed=-6202107849386030209\nonline-mode=true\n" > run/server.properties + echo "stop" > run/stop.txt + timeout ${{ inputs.timeout }} ./gradlew --build-cache --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 .fpgradle-workflows/scripts/test_no_error_reports + .fpgradle-workflows/scripts/test_no_error_reports \ No newline at end of file diff --git a/.github/workflows/release-tags.yml b/.github/workflows/release-tags.yml new file mode 100644 index 0000000..c7644c4 --- /dev/null +++ b/.github/workflows/release-tags.yml @@ -0,0 +1,84 @@ + +name: Release tagged build + +on: + workflow_call: + secrets: + MAVEN_USER: + required: false + MAVEN_PASSWORD: + required: false + CURSEFORGE_TOKEN: + required: false + MODRINTH_TOKEN: + required: false + inputs: + workspace: + description: 'setupCIWorkspace/setupDecompWorkspace' + required: false + default: "setupCIWorkspace" + type: string + +jobs: + build: + runs-on: ubuntu-latest + env: + VERSION: ${{ github.ref_name }} + RELEASE_VERSION: ${{ github.ref_name }} + steps: + - name: Checkout mod repo + uses: actions/checkout@v4 + with: + fetch-depth: 32 + + - name: Validate gradle wrapper checksum + uses: gradle/wrapper-validation-action@v2 + + - name: Set up JDK versions + uses: actions/setup-java@v4 + with: + java-version: | + 8 + 17 + 21 + distribution: 'adopt' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Setup the workspace + run: ./gradlew --build-cache --info --stacktrace ${{ inputs.workspace }} + + - name: Build the mod + run: ./gradlew --build-cache --info --stacktrace assemble + + # Continue on error in the following steps to make sure releases still get made even if one of the methods fails + + - name: Delete old release if it already exists + run: gh release delete --yes "${RELEASE_VERSION}" + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Release under current tag + run: gh release create "${RELEASE_VERSION}" ./build/libs/*.jar + shell: bash + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to Maven + run: ./gradlew --build-cache --info --stacktrace assemble publish -x test + continue-on-error: true + env: + MAVEN_DEPLOY_USER: ${{ secrets.MAVEN_DEPLOY_USER }} + MAVEN_DEPLOY_PASSWORD: ${{ secrets.MAVEN_DEPLOY_PASSWORD }} + if: ${{ env.MAVEN_DEPLOY_USER != '' }} + + - name: Publish to Modrinth and CurseForge + run: ./gradlew --build-cache --info --stacktrace assemble publish -x test + continue-on-error: true + env: + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba6bc86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,92 @@ +# Created by https://www.toptal.com/developers/gitignore/api/intellij+all +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +.idea/artifacts +.idea/compiler.xml +.idea/jarRepositories.xml +.idea/modules.xml +.idea/*.iml +.idea/modules +*.iml +*.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +# End of https://www.toptal.com/developers/gitignore/api/intellij+all diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..cb4e99f --- /dev/null +++ b/CREDITS @@ -0,0 +1,23 @@ +Based on the GTNH-Actions-Workflows repository + +MIT License + +Copyright (c) 2022 GTNH Developers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9d76775 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 FalsePattern + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.