Merge pull request #3 from Meatwo310/refactor/common-logic #38
This file contains hidden or 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
| name: Build | |
| on: | |
| push: | |
| paths-ignore: | |
| - 'docs/**' | |
| - '*.md' | |
| pull_request: | |
| paths-ignore: | |
| - 'docs/**' | |
| - '*.md' | |
| jobs: | |
| detect: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.detect.outputs.matrix }} | |
| runtime_matrix: ${{ steps.detect.outputs.runtime_matrix }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Detect subprojects from settings.gradle.kts | |
| id: detect | |
| run: | | |
| SUBPROJECTS=$(grep '^include(' settings.gradle.kts | sed 's/include("//;s/")//') | |
| JSON=$(printf '%s\n' "$SUBPROJECTS" | jq -R . | jq -sc .) | |
| RUNTIME_JSON=$(printf '%s\n' "$SUBPROJECTS" | grep -Ev '(^common$|-common$)' | jq -R . | jq -sc .) | |
| echo "matrix=$JSON" >> "$GITHUB_OUTPUT" | |
| echo "runtime_matrix=$RUNTIME_JSON" >> "$GITHUB_OUTPUT" | |
| echo "::group::Subprojects" | |
| jq . <<< "$JSON" | |
| echo "::endgroup::" | |
| echo "::group::Runtime test subprojects" | |
| jq . <<< "$RUNTIME_JSON" | |
| echo "::endgroup::" | |
| build: | |
| needs: detect | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| subproject: ${{ fromJson(needs.detect.outputs.matrix) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Setup JDK 25 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: '25' | |
| distribution: 'temurin' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v6 | |
| - name: Build with Gradle | |
| run: chmod u+x ./gradlew && ./gradlew ":${{ matrix.subproject }}:build" | |
| - name: Run Game Tests | |
| if: "endsWith(matrix.subproject, 'neo') || endsWith(matrix.subproject, 'forge')" | |
| run: ./gradlew ":${{ matrix.subproject }}:runGameTestServer" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v7 | |
| if: "!endsWith(matrix.subproject, 'common')" | |
| with: | |
| path: ${{ matrix.subproject }}/build/libs/ | |
| name: artifact-${{ matrix.subproject }} | |
| runtime-test: | |
| needs: | |
| - detect | |
| - build | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| subproject: ${{ fromJson(needs.detect.outputs.runtime_matrix) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Detect runtime test settings | |
| id: runtime | |
| run: | | |
| subproject="${{ matrix.subproject }}" | |
| prop() { sed -n "s/^$1=//p" "$subproject/gradle.properties"; } | |
| loader="${subproject##*-}" | |
| minecraftVersion="$(prop minecraftVersion)" | |
| javaVersion="$(prop javaVersion)" | |
| fabricApiVersion="$(prop fabricApiVersion)" | |
| javaVersion="${javaVersion:-17}" | |
| fabricApiVersion="${fabricApiVersion%%+*}" | |
| echo "mc=$minecraftVersion" >> "$GITHUB_OUTPUT" | |
| echo "java=$javaVersion" >> "$GITHUB_OUTPUT" | |
| echo "fabric_api=${fabricApiVersion:-none}" >> "$GITHUB_OUTPUT" | |
| if [[ "$loader" == "neo" ]]; then | |
| echo "modloader=neoforge" >> "$GITHUB_OUTPUT" | |
| echo "mc_runtime_test=neoforge" >> "$GITHUB_OUTPUT" | |
| echo "regex=.*neoforge.*" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "modloader=$loader" >> "$GITHUB_OUTPUT" | |
| echo "mc_runtime_test=${loader/forge/lexforge}" >> "$GITHUB_OUTPUT" | |
| echo "regex=.*$loader.*" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Download artifact | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: artifact-${{ matrix.subproject }} | |
| path: ${{ matrix.subproject }}/build/libs/ | |
| - name: Setup runtime JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: ${{ steps.runtime.outputs.java }} | |
| distribution: 'temurin' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Stage mod for runtime test client | |
| run: | | |
| mkdir -p run/mods | |
| find "${{ matrix.subproject }}/build/libs" -maxdepth 1 -type f -name '*.jar' \ | |
| ! -name '*-sources.jar' \ | |
| ! -name '*-javadoc.jar' \ | |
| ! -name '*-dev.jar' \ | |
| -exec cp {} run/mods/ \; | |
| test -n "$(find run/mods -maxdepth 1 -type f -name '*.jar' -print -quit)" | |
| ls -la run/mods | |
| - name: Run MC runtime test client | |
| uses: headlesshq/mc-runtime-test@4.4.0 | |
| with: | |
| mc: ${{ steps.runtime.outputs.mc }} | |
| modloader: ${{ steps.runtime.outputs.modloader }} | |
| regex: ${{ steps.runtime.outputs.regex }} | |
| mc-runtime-test: ${{ steps.runtime.outputs.mc_runtime_test }} | |
| java: ${{ steps.runtime.outputs.java }} | |
| fabric-api: ${{ steps.runtime.outputs.fabric_api }} |