Automated testing

This commit is contained in:
IThundxr 2024-10-21 15:47:29 -04:00
parent 3a949c717a
commit cefc61a7d6
No known key found for this signature in database
GPG Key ID: E291EC97BAF935E6
8 changed files with 185 additions and 43 deletions

View File

@ -1,47 +1,82 @@
name: build name: Build
on: [ pull_request, push ] on: [ pull_request, push ]
jobs: jobs:
build: build:
strategy: runs-on: ubuntu-latest
matrix: steps:
java: [ - name: Checkout Repository
17 # Current Java LTS & minimum supported by Minecraft uses: actions/checkout@v4
]
os: [ ubuntu-latest ] - name: Setup Java
runs-on: ${{ matrix.os }} run: echo "JAVA_HOME=$JAVA_HOME_17_X64" >> "$GITHUB_ENV"
steps:
- name: Checkout - name: Loom Cache
uses: actions/checkout@v4 uses: actions/cache@v4
- name: Validate Gradle Wrapper with:
uses: gradle/actions/wrapper-validation@v3 path: "**/.gradle/loom-cache"
- name: Gradle Cache key: "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}"
uses: actions/cache@v4 restore-keys: "${{ runner.os }}-gradle-"
with:
path: | - name: Setup Gradle
~/.gradle/caches uses: gradle/actions/setup-gradle@v3
~/.gradle/wrapper with:
.gradle/loom-cache gradle-home-cache-cleanup: true
build/ cache-read-only: ${{ !endsWith(github.ref_name, '/dev') }}
key: ${{ runner.os }}-jdk${{ matrix.java }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties', '**/gradle-wrapper.properties', '.github/workflows/build.yml') }}
- name: Setup JDK ${{ matrix.java }} - name: Validate Gradle Wrapper Integrity
uses: actions/setup-java@v4 uses: gradle/wrapper-validation-action@v2
with:
distribution: 'temurin' - name: Build
java-version: ${{ matrix.java }} # doesn't actually publish, as no secrets are passed in, just makes sure that publishing works
- name: Make Gradle Wrapper Executable run: ./gradlew :forge:remapTestmodJar :fabric:remapTestmodJar publish --no-daemon
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew - name: Capture Build Artifacts
- name: Build uses: actions/upload-artifact@v4
# doesn't actually publish, as no secrets are passed in, just makes sure that publishing works with:
run: ./gradlew publish --no-daemon name: Artifacts
- name: Capture Build Artifacts path: |
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} common/build/libs/
uses: actions/upload-artifact@v4 fabric/build/libs/
with: fabric/build/devlibs/
name: Artifacts forge/build/libs/
path: | forge/build/devlibs/
common/build/libs/
fabric/build/libs/ test:
forge/build/libs/ strategy:
matrix:
loader: [ forge, fabric ]
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: Artifacts
- name: Setup Environment Variables
run: |
echo "MOD_VERSION=$(grep '^mod_version =' gradle.properties | cut -d'=' -f2 | tr -d ' ')" >> "$GITHUB_ENV"
echo "MINECRAFT_VERSION=$(grep '^minecraft_version =' gradle.properties | cut -d'=' -f2 | tr -d ' ')" >> "$GITHUB_ENV"
echo "FABRIC_API_VERSION=$(grep '^fabric_api_version =' gradle.properties | cut -d'=' -f2 | tr -d ' ' | sed 's/+.*//')" >> "$GITHUB_ENV"
- name: Move Test Mod and Flywheel into run/mods
run: |
mkdir -p run/mods
cp ${{ matrix.loader }}/build/libs/flywheel-${{ matrix.loader }}-${{ env.MINECRAFT_VERSION }}-${{ env.MOD_VERSION }}.jar run/mods
cp ${{ matrix.loader }}/build/devlibs/flywheel-${{ matrix.loader }}-${{ env.MINECRAFT_VERSION }}-${{ env.MOD_VERSION }}-testmod.jar run/mods
# Lock to a specific commit, it would be bad if the tag is re-pushed with unwanted changes
- name: Run the MC client
uses: 3arthqu4ke/mc-runtime-test@e72f8fe1134aabf6fc749a2a8c09bb56dd7d283e
with:
mc: ${{ env.MINECRAFT_VERSION }}
modloader: ${{ matrix.loader }}
regex: .*${{ matrix.loader }}.*
mc-runtime-test: none
java: 17
fabric-api: ${{ matrix.loader == 'fabric' && env.FABRIC_API_VERSION || 'none' }}

View File

@ -4,6 +4,7 @@ import dev.engine_room.gradle.jarset.JarSetExtension
import dev.engine_room.gradle.nullability.PackageInfosExtension import dev.engine_room.gradle.nullability.PackageInfosExtension
import dev.engine_room.gradle.transitive.TransitiveSourceSetsExtension import dev.engine_room.gradle.transitive.TransitiveSourceSetsExtension
import net.fabricmc.loom.api.LoomGradleExtensionAPI import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
import org.gradle.api.JavaVersion import org.gradle.api.JavaVersion
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
@ -11,6 +12,7 @@ import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.tasks.GenerateModuleMetadata import org.gradle.api.publish.tasks.GenerateModuleMetadata
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.bundling.AbstractArchiveTask import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.api.tasks.javadoc.Javadoc
@ -18,6 +20,7 @@ import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.gradle.language.jvm.tasks.ProcessResources import org.gradle.language.jvm.tasks.ProcessResources
import java.io.File
class SubprojectPlugin: Plugin<Project> { class SubprojectPlugin: Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
@ -32,6 +35,9 @@ class SubprojectPlugin: Plugin<Project> {
setupDependencies(project) setupDependencies(project)
configureTasks(project) configureTasks(project)
setupPublishing(project) setupPublishing(project)
if (project.path != ":common")
setupTestMod(project)
} }
private fun setBaseProperties(project: Project) { private fun setBaseProperties(project: Project) {
@ -164,6 +170,26 @@ class SubprojectPlugin: Plugin<Project> {
} }
} }
} }
private fun setupTestMod(project: Project) {
val sourceSets = project.extensions.getByName("sourceSets") as SourceSetContainer
val testmodJar = project.tasks.register<Jar>("testmodJar") {
from (sourceSets["testmod"].output)
val file = File(project.layout.buildDirectory.asFile.get(), "devlibs");
destinationDirectory.set(file)
archiveClassifier = "testmod"
}
val remapTestmodJar = project.tasks.register<RemapJarTask>("remapTestmodJar") {
dependsOn(testmodJar)
inputFile.set(testmodJar.get().archiveFile)
archiveClassifier = "testmod"
addNestedDependencies = false
classpath.from(sourceSets["testmod"].compileClasspath)
}
project.tasks["build"].dependsOn(remapTestmodJar)
}
} }
val processResourcesExpandFiles = listOf("pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml") val processResourcesExpandFiles = listOf("pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml")

View File

@ -12,6 +12,10 @@ val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend") val backend = sourceSets.create("backend")
val stubs = sourceSets.create("stubs") val stubs = sourceSets.create("stubs")
val main = sourceSets.getByName("main") val main = sourceSets.getByName("main")
val testmod = sourceSets.create("testmod") {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
transitiveSourceSets { transitiveSourceSets {
compileClasspath = main.compileClasspath compileClasspath = main.compileClasspath

View File

@ -0,0 +1,22 @@
package dev.engine_room.flywheel;
import org.spongepowered.asm.mixin.MixinEnvironment;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
public class FlywheelTestModClient implements ClientModInitializer {
private int ticks = 0;
@Override
public void onInitializeClient() {
if (Boolean.getBoolean("flywheel.autoTest")) {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (++ticks == 50) {
MixinEnvironment.getCurrentEnvironment().audit();
client.stop();
}
});
}
}
}

View File

@ -0,0 +1,13 @@
{
"schemaVersion": 1,
"id": "${mod_id}-testmod",
"name": "${mod_name} Test Mod",
"version": "1.0.0",
"environment": "*",
"license": "${mod_license}",
"entrypoints": {
"client": [
"dev.engine_room.flywheel.FlywheelTestModClient"
]
}
}

View File

@ -12,6 +12,10 @@ val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend") val backend = sourceSets.create("backend")
val stubs = sourceSets.create("stubs") val stubs = sourceSets.create("stubs")
val main = sourceSets.getByName("main") val main = sourceSets.getByName("main")
val testmod = sourceSets.create("testmod") {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
transitiveSourceSets { transitiveSourceSets {
compileClasspath = main.compileClasspath compileClasspath = main.compileClasspath

View File

@ -0,0 +1,30 @@
package dev.engine_room.flywheel;
import org.spongepowered.asm.mixin.MixinEnvironment;
import net.minecraft.client.Minecraft;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@Mod("flywheel-testmod")
public class FlywheelTestModClient {
private int ticks = 0;
public FlywheelTestModClient() {
if (Boolean.getBoolean("flywheel.autoTest")) {
IEventBus modEventBus = FMLJavaModLoadingContext.get()
.getModEventBus();
modEventBus.addListener((TickEvent.ClientTickEvent e) -> {
if (e.phase == TickEvent.Phase.END) {
if (++ticks == 50) {
MixinEnvironment.getCurrentEnvironment().audit();
Minecraft.getInstance().stop();
}
}
});
}
}
}

View File

@ -0,0 +1,8 @@
modLoader = "javafml"
loaderVersion = "[0,)"
license = "${mod_license}"
[[mods]]
modId = "${mod_id}-testmod"
version = "1.0.0"
displayName = "${mod_name} Test Mod"