Use XVFB on Linux CI, allows running the client prod tasks on a headless OS (#1243)

This commit is contained in:
modmuss
2025-01-02 20:35:00 +00:00
committed by GitHub
parent 8b6658c559
commit 52a19b3bf7
3 changed files with 53 additions and 3 deletions

View File

@@ -43,6 +43,16 @@ import net.fabricmc.loom.util.Platform;
*/
@ApiStatus.Experimental
public abstract non-sealed class ClientProductionRunTask extends AbstractProductionRunTask {
/**
* Whether to use XVFB to run the game, using a virtual framebuffer. This is useful for CI environments that don't have a display server.
*
* <p>Defaults to true only on Linux and when the "CI" environment variable is set.
*
* <p>XVFB must be installed, on Debian-based systems you can install it with: <code>apt install -y xvfb</code>
*/
@Input
public abstract Property<Boolean> getUseXVFB();
// Internal options
@Input
protected abstract Property<String> getAssetsIndex();
@@ -52,6 +62,11 @@ public abstract non-sealed class ClientProductionRunTask extends AbstractProduct
@Inject
public ClientProductionRunTask() {
getUseXVFB().convention(getProject().getProviders().environmentVariable("CI")
.map(value -> Platform.CURRENT.getOperatingSystem().isLinux())
.orElse(false)
);
getAssetsIndex().set(getExtension().getMinecraftVersion()
.map(minecraftVersion -> getExtension()
.getMinecraftProvider()
@@ -71,6 +86,22 @@ public abstract non-sealed class ClientProductionRunTask extends AbstractProduct
dependsOn("downloadAssets");
}
@Override
protected void configureCommand(ExecSpec exec) {
if (getUseXVFB().get()) {
if (!Platform.CURRENT.getOperatingSystem().isLinux()) {
throw new UnsupportedOperationException("XVFB is only supported on Linux");
}
exec.commandLine("/usr/bin/xvfb-run");
exec.args("-a", getJavaLauncher().get().getExecutablePath());
return;
}
super.configureCommand(exec);
}
@Override
protected void configureJvmArgs(ExecSpec exec) {
super.configureJvmArgs(exec);