diff --git a/.gitignore b/.gitignore index 8a4aa75..bf90e39 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,6 @@ __tests__/runner/* # Custom encrypted +eval_linux +ioncube_encoder_evaluation +ioncube_encoder_evaluation.tar.gz diff --git a/__tests__/main.test.js b/__tests__/main.test.js index a0feb2c..9864aa8 100644 --- a/__tests__/main.test.js +++ b/__tests__/main.test.js @@ -36,5 +36,5 @@ describe('action', () => { expect(debugMock).toHaveBeenNthCalledWith(9, '') expect(setOutputMock).toHaveBeenCalledWith('status', 'Project encoded with success') - }) + }, 20000) }) diff --git a/action.yml b/action.yml index 2bf90dd..6eca5e7 100644 --- a/action.yml +++ b/action.yml @@ -60,7 +60,6 @@ inputs: outputs: status: description: 'The message of encode proccess' - type: string runs: using: node20 diff --git a/badges/coverage.svg b/badges/coverage.svg index e274008..6e95813 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -Coverage: 88.49%Coverage88.49% \ No newline at end of file +Coverage: 91.86%Coverage91.86% \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d9608cd..0d9f965 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,18 @@ { - "name": "javascript-action", - "version": "0.0.0", + "name": "ioncube-encoder-action", + "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "javascript-action", - "version": "0.0.0", + "name": "ioncube-encoder-action", + "version": "0.1.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", - "@actions/exec": "^1.1.1" + "@actions/exec": "^1.1.1", + "node-tar": "^1.0.0", + "tar": "^6.2.0" }, "devDependencies": { "@babel/core": "^7.23.5", @@ -4000,6 +4002,14 @@ "node": ">=10" } }, + "node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", + "engines": { + "node": ">=10" + } + }, "node_modules/ci-info": { "version": "3.8.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", @@ -5221,6 +5231,33 @@ "is-callable": "^1.1.3" } }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/fs-minipass/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/fs-minipass/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -6989,6 +7026,53 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/minipass": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", + "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minizlib/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/mri": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/mri/-/mri-1.1.4.tgz", @@ -7022,6 +7106,12 @@ "integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==", "dev": true }, + "node_modules/node-tar": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-tar/-/node-tar-1.0.0.tgz", + "integrity": "sha512-cowng5lugLQ3Bb5wWYfWM3067/S9xHDwCw3RWbqn0swqmgApDwklyg31XRci97cT7gNbVHmxoXQSkr2zDi5n+g==", + "deprecated": "please use 'tar'" + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -8069,6 +8159,27 @@ "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", "dev": true }, + "node_modules/tar": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz", + "integrity": "sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^5.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/tar/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", diff --git a/package.json b/package.json index 354083e..72c81a5 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,9 @@ }, "dependencies": { "@actions/core": "^1.10.1", - "@actions/exec": "^1.1.1" + "@actions/exec": "^1.1.1", + "node-tar": "^1.0.0", + "tar": "^6.2.0" }, "devDependencies": { "@babel/core": "^7.23.5", diff --git a/src/evaluation.js b/src/evaluation.js index 4fb1305..18b58c4 100644 --- a/src/evaluation.js +++ b/src/evaluation.js @@ -1,22 +1,29 @@ const core = require('@actions/core') const EVALUATION_PATH = './ioncube_encoder_evaluation/ioncube_encoder.sh' +const tar = require('tar') +const fs = require('fs') +const cp = require('child_process') +const process = require('process') /** * Download ioncube evaluation. - * @returns {string} Returns the path of encoder. + * @returns {Promise} Returns the path of encoder. */ -async function evaluation() { - core.debug('Using trial ioncube to encode files!') - core.debug('Downloading trial version of ioncube encoder...') +module.exports = async function evaluation() { + const cwd = process.cwd() - // TODO: download ioncube evaluation - // wget https://www.ioncube.com/eval_linux -O ioncube_encoder_evaluation.tar.gz - // tar -xzvf ioncube_encoder_evaluation.tar.gz + if (!fs.existsSync('ioncube_encoder_evaluation')) { + await download('https://www.ioncube.com/eval_linux', `${cwd}/ioncube_encoder_evaluation.tar.gz`) + await tar.extract({ file: `${cwd}/ioncube_encoder_evaluation.tar.gz` }) + + if (fs.existsSync(`${cwd}/ioncube_encoder_evaluation.tar.gz`)) { + fs.unlinkSync(`${cwd}/ioncube_encoder_evaluation.tar.gz`) + } + } return EVALUATION_PATH } -module.exports = { - EVALUATION_PATH, - evaluation +const download = async (uri, filename) => { + cp.execSync(`wget ${uri} -O ${filename}`) } diff --git a/src/inputs/trial.js b/src/inputs/trial.js index ba1e57a..a48273b 100644 --- a/src/inputs/trial.js +++ b/src/inputs/trial.js @@ -3,13 +3,13 @@ const evaluation = require('../evaluation') /** * Validate trial input values. - * @returns {string} Returns a validated trial input. + * @returns {Promise} Returns a validated trial input. */ -module.exports = function validateTrial() { - const trial = core.getInput('trial', { required: true }) ?? false +module.exports = async function validateTrial() { + const trial = core.getInput('trial', { required: true }) ?? true if (trial) { - return evaluation.evaluation() + return await evaluation() } // TODO: add a default path parameter diff --git a/src/main.js b/src/main.js index 0784edc..c1379c6 100644 --- a/src/main.js +++ b/src/main.js @@ -8,7 +8,7 @@ const validate = require('./validate') */ async function run() { try { - const inputs = validate() + const inputs = await validate() if (!inputs.trial) { // TODO: activate ioncube diff --git a/src/validate.js b/src/validate.js index 1ed3e36..db2ddc9 100644 --- a/src/validate.js +++ b/src/validate.js @@ -12,12 +12,12 @@ const validateOutput = require('./inputs/output') /** * Set default arguments depending on inputed template. - * @returns {object} Inputs based on templates. + * @returns {Promise} Inputs based on templates. */ -module.exports = function validate() { +module.exports = async function validate() { const template = validateTemplate() - const ioncube = validateTrial() + const ioncube = await validateTrial() const trial = ioncube === EVALUATION_PATH ? true : false const defaults = choose(template)