diff --git a/.github/actions/build_setup/action.yml b/.github/actions/build_setup/action.yml new file mode 100644 index 0000000..41712b8 --- /dev/null +++ b/.github/actions/build_setup/action.yml @@ -0,0 +1,32 @@ +name: Build Setup +description: Setup for standard Java builds + +inputs: + update-cache: + description: If cache should be updated + required: false + default: 'false' + +runs: + using: 'composite' + + steps: + - name: Set up JDK 8 and 17 + uses: actions/setup-java@v4 + with: + cache: gradle + distribution: 'zulu' + java-version: | + 8 + 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + with: + cache-write-only: ${{ inputs.update-cache }} + gradle-home-cache-includes: | + caches + caches/retro_futura_gradle + notifications + jdks + wrapper diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 0000000..9a5e0eb --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,94 @@ +# 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 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: GTBeesMatrix + 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 "${github.ref_name}" + ./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 "${github.ref_name}" \ + --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 "${github.ref_name}" -F pr-message.log || true + shell: bash # ensures set -eo pipefail + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + 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.sh + ./scripts/test_no_error_reports.sh diff --git a/.github/workflows/format_java.yml b/.github/workflows/format_java.yml new file mode 100644 index 0000000..645904d --- /dev/null +++ b/.github/workflows/format_java.yml @@ -0,0 +1,62 @@ +# Runs formatting requirements +name: Java Formatting + +on: + push: + branches: + - master + paths: ['src/main/java/**', 'src/test/**'] + pull_request: + paths: ['src/main/java/**', 'src/test/**'] + +concurrency: + group: format-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + formatting: + name: Formatting + runs-on: ubuntu-latest + + permissions: + pull-requests: write + contents: write + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Setup Build + uses: ./.github/actions/build_setup + + - name: Run Spotless Formatting Check with Gradle + id: build + run: ./gradlew --info spotlessCheck + + - name: Attempt to make a PR fixing spotless errors + if: failure() && steps.build.conclusion == 'failure' + 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 ${PR_BRANCH} for #${PR_NUMBER}" \ + --body "Automatic spotless apply to fix formatting errors, applies to PR #${PR_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.event.pull_request.head.ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + FIXED_BRANCH: ${{ github.head_ref }}-spotless-fixes diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..a0d8b1e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,129 @@ +# Publishes the project to GitHub Releases, CurseForge, and Modrinth +name: Publish Project + +on: + workflow_dispatch: + inputs: + version: + description: 'Mod version' + required: true + release_type: + description: 'Release type' + type: choice + default: 'beta' + options: + - 'release' + - 'beta' + - 'alpha' + +env: + # link to the changelog with a format code for the version + CHANGELOG_LOCATION: "Changelog is available [here](https://github.com/${{ github.repository }}/releases/tag/GTBeesMatrix-v${{ github.event.inputs.version }}-${{ github.event.inputs.release_type }})" + # Version of the mod + FULL_VERSION: "${{ github.event.inputs.version }}-${{ github.event.inputs.release_type }}" + # type of release + NAME: "GTBeesMatrix" + + # Curseforge and Modrinth project IDs + CURSEFORGE_PROJECT_ID: "" + MODRINTH_PROJECT_ID: "" + +concurrency: + group: publish-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Check if tag already exists + run: | + if git rev-parse --verify --quiet "v${{ github.event.inputs.version }}"; then + echo "Version ${{ github.event.inputs.version }} already exists, aborting workflow." + exit 1 + fi + + - name: Set version + run: sed -i "s/modVersion.*=.*/modVersion = ${{ env.FULL_VERSION }}/g" gradle.properties + + - name: Commit and push gradle.properties + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Bump version to v${{ env.FULL_VERSION }}" + commit_options: '--no-verify' + file_pattern: gradle.properties + tagging_message: "v${{ env.FULL_VERSION }}" + + - name: Setup Build + uses: ./.github/actions/build_setup + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build Project + run: ./gradlew --info build + + - name: Publish to Curseforge and Modrinth + uses: Kir-Antipov/mc-publish@v3.3 + with: + github-tag: "v${{ env.FULL_VERSION }}" + github-generate-changelog: true + github-draft: false + github-prerelease: false + github-token: ${{ secrets.GITHUB_TOKEN }} + # modrinth-id: ${{ env.MODRINTH_PROJECT_ID }} + # modrinth-token: "${{ secrets.MODRINTH_API_KEY }}" + # modrinth-dependencies: | + # G1ckZuWK(required) + # tULldUx4(required) + # tZiutdLG(required) + # curseforge-id: ${{ env.CURSEFORGE_PROJECT_ID }} + # curseforge-token: "${{ secrets.CURSEFORGE_API_KEY }}" + # curseforge-dependencies: | + # mixin-booter(required) + # gregtech-ce-unofficial(required) + # gregicality-multiblocks(required) + # implosionnobomb(recommended) + # ae2-extended-life(recommended) + # ae-additions-extra-cells-2-fork(recommended) + # nae2(recommended) + # ender-io-base(recommended) + # ender-io-machines(recommended) + # ender-io-endergy(recommended) + # ender-io-conduits(recommended) + # ender-io-ae2-conduits(recommended) + # gregtech-food-option(recommended) + # chisel(recommended) + # extracpus(recommended) + # draconic-evolution(recommended) + # draconicadditions(recommended) + # project-red-illumination(recommended) + # avaritia-1-1x-unofficial(recommended) + # thaumcraft(recommended) + # forestry(recommended) + # gendustry(recommended) + # binnies-mods-patched(recommended) + # ulv-covers(incompatible) + files: | + build/libs/!(*-@(dev|sources|javadoc)).jar + build/libs/*-@(sources).jar + build/libs/*-@(dev).jar + name: "${{ env.NAME }}-${{ env.FULL_VERSION }}.jar" + changelog: "Changelog is available [here](https://github.com/${{github.repository}}/blob/main/CHANGELOG.md)" + version: "${{ github.event.inputs.version }}" + version-type: "${{ github.event.inputs.release_type }}" + loaders: | + forge + game-versions: | + 1.12.2 + java: | + 8 + retry-attempts: 2 diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 0000000..6ccbe44 --- /dev/null +++ b/.github/workflows/rebase.yml @@ -0,0 +1,29 @@ +# Auto rebase pull requests when a comment contains `/rebase` or `/autosquash` +name: Automatic Rebase + +on: + issue_comment: + types: [created] + +jobs: + rebase: + name: Rebase + runs-on: ubuntu-latest + if: >- + github.event.issue.pull_request != '' && + ( + contains(github.event.comment.body, '/rebase') || + contains(github.event.comment.body, '/autosquash') + ) + steps: + - name: Checkout the latest code + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 # otherwise, you will fail to push refs to dest repo + - name: Automatic Rebase + uses: cirrus-actions/rebase@1.8 + with: + autosquash: ${{ contains(github.event.comment.body, '/autosquash') || contains(github.event.comment.body, '/rebase-autosquash') }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test_java.yml b/.github/workflows/test_java.yml new file mode 100644 index 0000000..2b275bc --- /dev/null +++ b/.github/workflows/test_java.yml @@ -0,0 +1,32 @@ +# Runs tests +name: Java Tests + +on: + push: + branches: + - master + pull_request: + branches: + - '*' + +concurrency: + group: test-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + test: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Apply patch to build.gradle + run: sed -i 's/debug_all = false/debug_all = true/g' gradle.properties + + - name: Setup Build + uses: ./.github/actions/build_setup + + - name: Run Tests with Gradle + run: ./gradlew --info --scan test diff --git a/.github/workflows/update_buildscript.yml b/.github/workflows/update_buildscript.yml new file mode 100644 index 0000000..8ca13b7 --- /dev/null +++ b/.github/workflows/update_buildscript.yml @@ -0,0 +1,55 @@ +# Checks daily to see if the buildscript is in need of an update +name: Update Buildscript + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * *' # "min hr day month year", so run once per day + +jobs: + buildscript-update: + runs-on: ubuntu-latest + + # Avoid running this workflow on forks + if: github.repository == 'GTModpackTeam/GTBeesMatrix' + + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Build + uses: ./.github/actions/build_setup + + - name: Run Buildscript Updater + run: ./gradlew --info updateBuildScript + + - name: Get New Buildscript Version + id: version-check + run: | + new_version=$(head -1 build.gradle | sed -r 's|//version: (.*)|\1|g') + echo "NEW_VERSION=$new_version" >> "$GITHUB_OUTPUT" + + - name: Create Pull Request + id: create-pull-request + uses: peter-evans/create-pull-request@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + token: ${{ secrets.GITHUB_TOKEN }} + committer: GitHub + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + commit-message: 'update build script version to ${{ steps.version-check.outputs.NEW_VERSION }}' + branch: gha-update-buildscript + title: Update build script version to ${{ steps.version-check.outputs.NEW_VERSION }} + body: This pull request is created by the buildscript-update workflow + labels: ignore changelog + +# - name: Enable Pull-Request Auto-Merge +# if: steps.create-pull-request.outputs.pull-request-operation == 'created' +# run: gh pr merge --squash --auto "${{ steps.create-pull-request.outputs.pull-request-number }}" +# env: +# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/update_gradle_cache.yml b/.github/workflows/update_gradle_cache.yml new file mode 100644 index 0000000..4c928d7 --- /dev/null +++ b/.github/workflows/update_gradle_cache.yml @@ -0,0 +1,30 @@ +# Updates the Gradle Cache when necessary +name: Update Gradle Cache + +on: + push: + branches: + - master + paths: ['gradle/**', '**.gradle', 'gradle.properties', 'gradlew**', 'src/main/resources/*_at.cfg'] + workflow_dispatch: + +concurrency: + group: gradle-cache-${{ github.ref }} + cancel-in-progress: true + +jobs: + update-cache: + name: Update Grade Cache + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Build + uses: ./.github/actions/build_setup + with: + update-cache: true + + - name: Build Project with Gradle + run: ./gradlew --info assemble diff --git a/.github/workflows/validate_gradle_wrapper.yml b/.github/workflows/validate_gradle_wrapper.yml new file mode 100644 index 0000000..d32e687 --- /dev/null +++ b/.github/workflows/validate_gradle_wrapper.yml @@ -0,0 +1,29 @@ +# Validates the integrity of the Gradle Wrapper +name: Validate Gradle Wrapper + +on: + push: + branches: + - master + paths: + - 'gradle/**' + pull_request: + branches: + - '*' + paths: + - 'gradle/**' + +concurrency: + group: gradle-wrapper-validation-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + Validation: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v4