Skip to content

Commit

Permalink
Spin up a dedicated server on github actions + add run tasks for test…
Browse files Browse the repository at this point in the history
… mods. (#1163)

* Add test mod run tasks, add a very basic auto test server task

* License header

* Minor cleanup

* Fix bad depends
  • Loading branch information
modmuss50 committed Nov 15, 2020
1 parent fca1ef1 commit 1cd3aea
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
- uses: actions/checkout@v1
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew check build publishToMavenLocal --stacktrace --parallel
- run: mkdir run && echo "eula=true" >> run/eula.txt
- run: ./gradlew runAutoTestServer --stacktrace
- uses: actions/upload-artifact@v2
with:
name: Artifacts
Expand Down
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ version = Globals.baseVersion + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") +
logger.lifecycle("Building Fabric: " + version)

import org.apache.commons.codec.digest.DigestUtils
import net.fabricmc.loom.task.RunClientTask
import net.fabricmc.loom.task.RunServerTask

def getSubprojectVersion(project, version) {
if (grgit == null) {
Expand Down Expand Up @@ -83,6 +85,14 @@ allprojects {
}
}

task runTestmodClient(type: RunClientTask) {
classpath sourceSets.testmod.runtimeClasspath
}

task runTestmodServer(type: RunServerTask) {
classpath sourceSets.testmod.runtimeClasspath
}

dependencies {
minecraft "com.mojang:minecraft:$Globals.mcVersion"
mappings "net.fabricmc:yarn:${Globals.mcVersion}${Globals.yarnVersion}:v2"
Expand Down Expand Up @@ -181,6 +191,15 @@ task javadocJar(type: Jar) {

build.dependsOn javadocJar

// Runs a dedicated headless server with all test mods that closes once complete.
task runAutoTestServer(type: RunServerTask) {
project.subprojects {
classpath it.sourceSets.testmod.runtimeClasspath
}
jvmArgs "-Dfabric.autoTest"
args "--nogui"
}

subprojects {
dependencies {
testmodCompile sourceSets.main.output
Expand Down
4 changes: 4 additions & 0 deletions fabric-api-base/build.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
archivesBaseName = "fabric-api-base"
version = getSubprojectVersion(project, "0.2.0")

dependencies {
testmodCompile project(path: ':fabric-lifecycle-events-v1', configuration: 'dev')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.test.base;

import org.spongepowered.asm.mixin.MixinEnvironment;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;

public class FabricApiBaseTestInit implements ModInitializer {
private int ticks = 0;

@Override
public void onInitialize() {
if (System.getProperty("fabric.autoTest") != null) {
ServerTickEvents.END_SERVER_TICK.register(server -> {
ticks++;

if (ticks == 50) {
MixinEnvironment.getCurrentEnvironment().audit();
server.stop(false);
}
});
}
}
}
13 changes: 13 additions & 0 deletions fabric-api-base/src/testmod/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"schemaVersion": 1,
"id": "fabric-api-base-testmod",
"name": "Fabric API Base Test Mod",
"version": "1.0.0",
"environment": "*",
"license": "Apache-2.0",
"entrypoints": {
"main": [
"net.fabricmc.fabric.test.base.FabricApiBaseTestInit"
]
}
}

0 comments on commit 1cd3aea

Please sign in to comment.