Merge pull request #5 from josephbmanley/feature/runLocally

Allow running tests directly on runner
This commit is contained in:
Layla 2021-02-11 19:06:55 -05:00 committed by GitHub
commit 77ba28181d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 251 additions and 105 deletions

View File

@ -3,13 +3,26 @@ name: Test Action
on: [push, pull_request]
jobs:
TestAction:
test_1:
name: "Test Action with Container"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Action
id: run_tests
uses: ./
with:
directory: test_proj
directory: test_proj
test_2:
name: "Test Action Locally"
runs-on: ubuntu-latest
container:
image: barichello/godot-ci:latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Action
uses: ./
with:
directory: test_proj
useContainer: false

View File

@ -26,6 +26,15 @@ steps:
The name directory to run tests within. Defaults to the current directory.
#### useContainer
Boolean value of whether or not to run container. Defaults to `true`
#### godotExecutable
Path of Godot binary to call when running GUT tests. Defaults to `godot`
## Configure GUT
This action requires you to configure GUT using the `.gutconfig.json` file which would be located in the root directory of your project.

View File

@ -5,6 +5,12 @@ inputs:
containerImage:
description: "The container to run tests inside of."
default: "barichello/godot-ci:latest"
useContainer:
description: "Boolean value of whether or not to run container."
default: true
godotExecutable:
description: "Path of Godot binary to call when running GUT tests."
default: godot
directory:
description: "The name directory to run tests in."
runs:

194
dist/index.js vendored
View File

@ -1193,6 +1193,32 @@ formatters.O = function (v) {
};
/***/ }),
/***/ 82:
/***/ (function(__unusedmodule, exports) {
"use strict";
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
*/
function toCommandValue(input) {
if (input === null || input === undefined) {
return '';
}
else if (typeof input === 'string' || input instanceof String) {
return input;
}
return JSON.stringify(input);
}
exports.toCommandValue = toCommandValue;
//# sourceMappingURL=utils.js.map
/***/ }),
/***/ 87:
@ -1715,6 +1741,42 @@ ServerStderr.prototype._write = function(data, encoding, cb) {
module.exports = Channel;
/***/ }),
/***/ 102:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
// For internal use, subject to change.
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__webpack_require__(747));
const os = __importStar(__webpack_require__(87));
const utils_1 = __webpack_require__(82);
function issueCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`];
if (!filePath) {
throw new Error(`Unable to find environment variable for file command ${command}`);
}
if (!fs.existsSync(filePath)) {
throw new Error(`Missing file at path: ${filePath}`);
}
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
encoding: 'utf8'
});
}
exports.issueCommand = issueCommand;
//# sourceMappingURL=file-command.js.map
/***/ }),
/***/ 107:
@ -12178,6 +12240,7 @@ function plural(ms, msAbs, n, name) {
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
const core = __webpack_require__(470);
const { spawnSync } = __webpack_require__(129);
const fs = __webpack_require__(747);
const path = __webpack_require__(622)
@ -12190,47 +12253,68 @@ try {
// Get inputs
var docker_image = core.getInput('containerImage');
var work_dir = core.getInput('directory');
var use_container = core.getInput('useContainer');
var godot_executable = core.getInput('godotExecutable');
if(work_dir)
{
process.chdir(work_dir);
}
// Pull docker image for building
console.log("Pulling build image...");
docker.pull(docker_image, function(err, stream)
{
if(use_container == "true")
{
docker.modem.followProgress(stream, onFinished, onProgress);
// Wait to run build until after pull complete
function onFinished(err, output)
// Pull docker image for building
console.log("Pulling build image...");
docker.pull(docker_image, function(err, stream)
{
console.log("Starting image...")
docker.run(docker_image, ['godot', '-d', '-s', '--path', '/project', 'addons/gut/gut_cmdln.gd'], process.stdout,
docker.modem.followProgress(stream, onFinished, onProgress);
// Wait to run build until after pull complete
function onFinished(err, output)
{
console.log("Starting image...")
docker.run(docker_image, [godot_executable, '-d', '-s', '--path', '/project', 'addons/gut/gut_cmdln.gd'], process.stdout,
// 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!");
}
// Mount working directory to `/project`
{ HostConfig: { Binds: [ process.cwd() + ":/project" ] }},
function (err, data, container) {
})
}
function onProgress(event) {}
if(err)
{
core.setFailed(error.message);
}
});
}
else
{
console.log("Running GUT tests locally");
console.log("Tests exited with status: " + data.StatusCode);
var result = spawnSync(`${godot_executable} -d -s --path . addons/gut/gut_cmdln.gd`, {
stdio: 'inherit',
shell: true
});
if( data.StatusCode != "0" )
{
core.setFailed("GUT tests failed!");
}
})
if(result.status != null && result.status != 0)
{
core.setFailed("GUT tests failed!");
}
function onProgress(event) {}
});
}
} catch (error) {
core.setFailed(error.message);
@ -14343,6 +14427,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const os = __importStar(__webpack_require__(87));
const utils_1 = __webpack_require__(82);
/**
* Commands
*
@ -14396,28 +14481,14 @@ class Command {
return cmdStr;
}
}
/**
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
*/
function toCommandValue(input) {
if (input === null || input === undefined) {
return '';
}
else if (typeof input === 'string' || input instanceof String) {
return input;
}
return JSON.stringify(input);
}
exports.toCommandValue = toCommandValue;
function escapeData(s) {
return toCommandValue(s)
return utils_1.toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A');
}
function escapeProperty(s) {
return toCommandValue(s)
return utils_1.toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
@ -14760,6 +14831,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = __webpack_require__(431);
const file_command_1 = __webpack_require__(102);
const utils_1 = __webpack_require__(82);
const os = __importStar(__webpack_require__(87));
const path = __importStar(__webpack_require__(622));
/**
@ -14786,9 +14859,17 @@ var ExitCode;
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function exportVariable(name, val) {
const convertedVal = command_1.toCommandValue(val);
const convertedVal = utils_1.toCommandValue(val);
process.env[name] = convertedVal;
command_1.issueCommand('set-env', { name }, convertedVal);
const filePath = process.env['GITHUB_ENV'] || '';
if (filePath) {
const delimiter = '_GitHubActionsFileCommandDelimeter_';
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
file_command_1.issueCommand('ENV', commandValue);
}
else {
command_1.issueCommand('set-env', { name }, convertedVal);
}
}
exports.exportVariable = exportVariable;
/**
@ -14804,7 +14885,13 @@ exports.setSecret = setSecret;
* @param inputPath
*/
function addPath(inputPath) {
command_1.issueCommand('add-path', {}, inputPath);
const filePath = process.env['GITHUB_PATH'] || '';
if (filePath) {
file_command_1.issueCommand('PATH', inputPath);
}
else {
command_1.issueCommand('add-path', {}, inputPath);
}
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
}
exports.addPath = addPath;
@ -25582,12 +25669,13 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
if (bytes > l) {
this._bufs[i].copy(dst, bufoff, start)
bufoff += l
} else {
this._bufs[i].copy(dst, bufoff, start, start + bytes)
bufoff += l
break
}
bufoff += l
bytes -= l
if (start) {
@ -25595,6 +25683,9 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
}
}
// safeguard so that we don't return uninitialized memory
if (dst.length > bufoff) return dst.slice(0, bufoff)
return dst
}
@ -25636,6 +25727,11 @@ BufferList.prototype.toString = function toString (encoding, start, end) {
}
BufferList.prototype.consume = function consume (bytes) {
// first, normalize the argument, in accordance with how Buffer does it
bytes = Math.trunc(bytes)
// do nothing if not a positive number
if (Number.isNaN(bytes) || bytes <= 0) return this
while (this._bufs.length) {
if (bytes >= this._bufs[0].length) {
bytes -= this._bufs[0].length
@ -26295,7 +26391,7 @@ try {
/***/ 724:
/***/ (function(module) {
module.exports = {"_from":"ssh2-streams@~0.4.10","_id":"ssh2-streams@0.4.10","_inBundle":false,"_integrity":"sha512-8pnlMjvnIZJvmTzUIIA5nT4jr2ZWNNVHwyXfMGdRJbug9TpI3kd99ffglgfSWqujVv/0gxwMsDn9j9RVst8yhQ==","_location":"/ssh2-streams","_phantomChildren":{},"_requested":{"type":"range","registry":true,"raw":"ssh2-streams@~0.4.10","name":"ssh2-streams","escapedName":"ssh2-streams","rawSpec":"~0.4.10","saveSpec":null,"fetchSpec":"~0.4.10"},"_requiredBy":["/ssh2"],"_resolved":"https://registry.npmjs.org/ssh2-streams/-/ssh2-streams-0.4.10.tgz","_shasum":"48ef7e8a0e39d8f2921c30521d56dacb31d23a34","_spec":"ssh2-streams@~0.4.10","_where":"/var/home/vetra/Projects/run-gut-tests-action/node_modules/ssh2","author":{"name":"Brian White","email":"mscdex@mscdex.net"},"bugs":{"url":"https://github.com/mscdex/ssh2-streams/issues"},"bundleDependencies":false,"dependencies":{"asn1":"~0.2.0","bcrypt-pbkdf":"^1.0.2","streamsearch":"~0.1.2"},"deprecated":false,"description":"SSH2 and SFTP(v3) client/server protocol streams for node.js","engines":{"node":">=5.2.0"},"homepage":"https://github.com/mscdex/ssh2-streams#readme","keywords":["ssh","ssh2","sftp","secure","protocol","streams","client","server"],"licenses":[{"type":"MIT","url":"http://github.com/mscdex/ssh2-streams/raw/master/LICENSE"}],"main":"./index","name":"ssh2-streams","repository":{"type":"git","url":"git+ssh://git@github.com/mscdex/ssh2-streams.git"},"scripts":{"test":"node test/test.js"},"version":"0.4.10"};
module.exports = {"_args":[["ssh2-streams@0.4.10","/home/manley/Projects/run-gut-tests-action"]],"_from":"ssh2-streams@0.4.10","_id":"ssh2-streams@0.4.10","_inBundle":false,"_integrity":"sha512-8pnlMjvnIZJvmTzUIIA5nT4jr2ZWNNVHwyXfMGdRJbug9TpI3kd99ffglgfSWqujVv/0gxwMsDn9j9RVst8yhQ==","_location":"/ssh2-streams","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"ssh2-streams@0.4.10","name":"ssh2-streams","escapedName":"ssh2-streams","rawSpec":"0.4.10","saveSpec":null,"fetchSpec":"0.4.10"},"_requiredBy":["/ssh2"],"_resolved":"https://registry.npmjs.org/ssh2-streams/-/ssh2-streams-0.4.10.tgz","_spec":"0.4.10","_where":"/home/manley/Projects/run-gut-tests-action","author":{"name":"Brian White","email":"mscdex@mscdex.net"},"bugs":{"url":"https://github.com/mscdex/ssh2-streams/issues"},"dependencies":{"asn1":"~0.2.0","bcrypt-pbkdf":"^1.0.2","streamsearch":"~0.1.2"},"description":"SSH2 and SFTP(v3) client/server protocol streams for node.js","engines":{"node":">=5.2.0"},"homepage":"https://github.com/mscdex/ssh2-streams#readme","keywords":["ssh","ssh2","sftp","secure","protocol","streams","client","server"],"licenses":[{"type":"MIT","url":"http://github.com/mscdex/ssh2-streams/raw/master/LICENSE"}],"main":"./index","name":"ssh2-streams","repository":{"type":"git","url":"git+ssh://git@github.com/mscdex/ssh2-streams.git"},"scripts":{"test":"node test/test.js"},"version":"0.4.10"};
/***/ }),

78
main.js
View File

@ -1,4 +1,5 @@
const core = require('@actions/core');
const { spawnSync } = require("child_process");
const fs = require('fs');
const path = require('path')
@ -11,47 +12,68 @@ try {
// Get inputs
var docker_image = core.getInput('containerImage');
var work_dir = core.getInput('directory');
var use_container = core.getInput('useContainer');
var godot_executable = core.getInput('godotExecutable');
if(work_dir)
{
process.chdir(work_dir);
}
// Pull docker image for building
console.log("Pulling build image...");
docker.pull(docker_image, function(err, stream)
{
if(use_container == "true")
{
docker.modem.followProgress(stream, onFinished, onProgress);
// Wait to run build until after pull complete
function onFinished(err, output)
// Pull docker image for building
console.log("Pulling build image...");
docker.pull(docker_image, function(err, stream)
{
console.log("Starting image...")
docker.run(docker_image, ['godot', '-d', '-s', '--path', '/project', 'addons/gut/gut_cmdln.gd'], process.stdout,
docker.modem.followProgress(stream, onFinished, onProgress);
// Wait to run build until after pull complete
function onFinished(err, output)
{
console.log("Starting image...")
docker.run(docker_image, [godot_executable, '-d', '-s', '--path', '/project', 'addons/gut/gut_cmdln.gd'], process.stdout,
// 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!");
}
// Mount working directory to `/project`
{ HostConfig: { Binds: [ process.cwd() + ":/project" ] }},
function (err, data, container) {
})
}
function onProgress(event) {}
if(err)
{
core.setFailed(error.message);
}
});
}
else
{
console.log("Running GUT tests locally");
console.log("Tests exited with status: " + data.StatusCode);
var result = spawnSync(`${godot_executable} -d -s --path . addons/gut/gut_cmdln.gd`, {
stdio: 'inherit',
shell: true
});
if( data.StatusCode != "0" )
{
core.setFailed("GUT tests failed!");
}
})
if(result.status != null && result.status != 0)
{
core.setFailed("GUT tests failed!");
}
function onProgress(event) {}
});
}
} catch (error) {
core.setFailed(error.message);

View File

@ -1,26 +1,26 @@
{
"name": "run-gut-tests-action",
"version": "1.0.0",
"description": "",
"main": "dist/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"package": "ncc build main.js -o dist"
},
"repository": {
"type": "git",
"url": "git+https://github.com/josephbmanley/run-gut-tests-action.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/josephbmanley/run-gut-tests-action/issues"
},
"homepage": "https://github.com/josephbmanley/run-gut-tests-action#readme",
"dependencies": {
"@actions/core": "^1.2.6",
"@zeit/ncc": "^0.22.3",
"dockerode": "^3.2.1"
}
}
"name": "run-gut-tests-action",
"version": "1.0.0",
"description": "",
"main": "dist/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"package": "ncc build main.js -o dist"
},
"repository": {
"type": "git",
"url": "git+https://github.com/josephbmanley/run-gut-tests-action.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/josephbmanley/run-gut-tests-action/issues"
},
"homepage": "https://github.com/josephbmanley/run-gut-tests-action#readme",
"dependencies": {
"@actions/core": "^1.2.6",
"@zeit/ncc": "^0.22.3",
"dockerode": "^3.2.1"
}
}