2020-07-25 23:09:22 +02:00
|
|
|
const core = require('@actions/core');
|
2021-02-12 00:14:40 +01:00
|
|
|
const { spawnSync } = require("child_process");
|
2020-07-25 23:09:22 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
// Setup Docker
|
|
|
|
const Docker = require('dockerode');
|
|
|
|
var docker = new Docker({socketPath: '/var/run/docker.sock'});
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// Get inputs
|
|
|
|
var docker_image = core.getInput('containerImage');
|
|
|
|
var work_dir = core.getInput('directory');
|
2021-02-12 00:14:40 +01:00
|
|
|
var use_container = core.getInput('useContainer');
|
2021-02-12 01:03:58 +01:00
|
|
|
var godot_executable = core.getInput('godotExecutable');
|
2020-07-25 23:09:22 +02:00
|
|
|
|
2020-07-25 23:57:44 +02:00
|
|
|
if(work_dir)
|
|
|
|
{
|
|
|
|
process.chdir(work_dir);
|
|
|
|
}
|
2020-07-25 23:09:22 +02:00
|
|
|
|
2021-02-12 00:14:40 +01:00
|
|
|
if(use_container == "true")
|
|
|
|
{
|
2020-07-25 23:09:22 +02:00
|
|
|
|
2021-02-12 00:14:40 +01:00
|
|
|
// Pull docker image for building
|
|
|
|
console.log("Pulling build image...");
|
|
|
|
docker.pull(docker_image, function(err, stream)
|
2020-07-25 23:09:22 +02:00
|
|
|
{
|
2021-02-12 00:14:40 +01:00
|
|
|
|
|
|
|
docker.modem.followProgress(stream, onFinished, onProgress);
|
|
|
|
|
|
|
|
// Wait to run build until after pull complete
|
|
|
|
function onFinished(err, output)
|
|
|
|
{
|
|
|
|
console.log("Starting image...")
|
2021-02-12 01:03:58 +01:00
|
|
|
docker.run(docker_image, [godot_executable, '-d', '-s', '--path', '/project', 'addons/gut/gut_cmdln.gd'], process.stdout,
|
2021-02-12 00:14:40 +01:00
|
|
|
|
|
|
|
// Mount working directory to `/project`
|
|
|
|
{ HostConfig: { Binds: [ process.cwd() + ":/project" ] }},
|
|
|
|
|
|
|
|
function (err, data, container) {
|
|
|
|
|
|
|
|
if(err)
|
|
|
|
{
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Tests exited with status: " + data.StatusCode);
|
|
|
|
|
|
|
|
if( data.StatusCode != "0" )
|
|
|
|
{
|
|
|
|
core.setFailed("GUT tests failed!");
|
|
|
|
}
|
2020-07-25 23:09:22 +02:00
|
|
|
|
2021-02-12 00:14:40 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
function onProgress(event) {}
|
2020-07-25 23:09:22 +02:00
|
|
|
|
2021-02-12 00:14:40 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log("Running GUT tests locally");
|
2020-07-25 23:17:07 +02:00
|
|
|
|
2021-02-12 01:03:58 +01:00
|
|
|
var result = spawnSync(`${godot_executable} -d -s --path . addons/gut/gut_cmdln.gd`, {
|
2021-02-12 00:14:40 +01:00
|
|
|
stdio: 'inherit',
|
|
|
|
shell: true
|
|
|
|
});
|
2020-07-25 23:17:07 +02:00
|
|
|
|
2021-02-12 00:14:40 +01:00
|
|
|
if(result.status != null && result.status != 0)
|
|
|
|
{
|
|
|
|
core.setFailed("GUT tests failed!");
|
2020-07-25 23:09:22 +02:00
|
|
|
}
|
2021-02-12 00:14:40 +01:00
|
|
|
|
|
|
|
}
|
2020-07-25 23:09:22 +02:00
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|