From 5af87a011e3e65d4e447f2a7a55295fcb24d575b Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Thu, 11 Feb 2021 18:14:40 -0500 Subject: [PATCH] Allow action to run locally Update test workflows Test Action: wget quiretly Test Action: Install for user Check condition on string Cleanup and update test action Run on runner: debug Run on runner: debug Run on runner: debug Run on runner: debug Run on runner: debug Run on runner: debug Run on runner: debug Run on runner: debug Run on runner: debug Run on runner: debug --- .github/workflows/test_action.yml | 19 ++- ReadMe.md | 4 + action.yml | 3 + dist/index.js | 193 ++++++++++++++++++++++-------- main.js | 77 +++++++----- package.json | 50 ++++---- 6 files changed, 241 insertions(+), 105 deletions(-) diff --git a/.github/workflows/test_action.yml b/.github/workflows/test_action.yml index 0d9f443..d80a32d 100644 --- a/.github/workflows/test_action.yml +++ b/.github/workflows/test_action.yml @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index 3cbe732..5a17f1d 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -26,6 +26,10 @@ 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` + ## 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. diff --git a/action.yml b/action.yml index 5c4fc40..d0e08bc 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,9 @@ 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 directory: description: "The name directory to run tests in." runs: diff --git a/dist/index.js b/dist/index.js index fec6313..3c84cd0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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,67 @@ try { // Get inputs var docker_image = core.getInput('containerImage'); var work_dir = core.getInput('directory'); + var use_container = core.getInput('useContainer'); 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', '-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 -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 +14426,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 +14480,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 +14830,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 +14858,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 +14884,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 +25668,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 +25682,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 +25726,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 +26390,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"}; /***/ }), diff --git a/main.js b/main.js index 721dd71..5ff3102 100644 --- a/main.js +++ b/main.js @@ -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,67 @@ try { // Get inputs var docker_image = core.getInput('containerImage'); var work_dir = core.getInput('directory'); + var use_container = core.getInput('useContainer'); 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', '-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 -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); diff --git a/package.json b/package.json index 58456b5..720975d 100644 --- a/package.json +++ b/package.json @@ -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" - } - } \ No newline at end of file + "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" + } +}