From b603a3122f3235f69f250508d0d9ef52675a2bbb Mon Sep 17 00:00:00 2001 From: MuriloChianfa Date: Fri, 8 Dec 2023 15:29:13 -0300 Subject: [PATCH] adding parameters to encode command --- __tests__/main.test.js | 84 +++++++++++++++++++++++++++++++++++- badges/coverage.svg | 2 +- dist/index.js | 5 +-- dist/licenses.txt | 92 +--------------------------------------- src/inputs/license.js | 4 +- src/inputs/template.js | 2 +- src/main.js | 55 +++++++++++++++++++++--- src/templates/choose.js | 4 +- src/templates/laravel.js | 6 +-- 9 files changed, 147 insertions(+), 107 deletions(-) diff --git a/__tests__/main.test.js b/__tests__/main.test.js index ec57db7..b10ea89 100644 --- a/__tests__/main.test.js +++ b/__tests__/main.test.js @@ -25,7 +25,7 @@ describe('action', () => { // Verify that all of the core library functions were called correctly with default values expect(debugMock).toHaveBeenNthCalledWith( 1, - 'Encoding files using template: laravel' + 'Encoding files using template: php' ) expect(debugMock).toHaveBeenNthCalledWith( 2, @@ -41,6 +41,26 @@ describe('action', () => { ) expect(debugMock).toHaveBeenNthCalledWith(5, 'Using input files: .') expect(debugMock).toHaveBeenNthCalledWith(6, 'Using output path: encrypted') + expect(debugMock).toHaveBeenNthCalledWith(7, 'Using reflection for: NONE') + expect(debugMock).toHaveBeenNthCalledWith(8, 'Encrypting files: NONE') + expect(debugMock).toHaveBeenNthCalledWith(9, 'Encoding into ASCII format') + expect(debugMock).toHaveBeenNthCalledWith(10, 'Using optimization: more') + expect(debugMock).toHaveBeenNthCalledWith(11, 'Now allow doc comments') + expect(debugMock).toHaveBeenNthCalledWith( + 12, + 'Checking for loader in environment' + ) + expect(debugMock).toHaveBeenNthCalledWith(13, 'Adding preamble file: NONE') + expect(debugMock).toHaveBeenNthCalledWith(14, 'Using passphrase: NONE') + expect(debugMock).toHaveBeenNthCalledWith(15, 'Using license check: auto') + expect(debugMock).toHaveBeenNthCalledWith( + 16, + 'Using license file in runtime path: NONE' + ) + expect(debugMock).toHaveBeenNthCalledWith( + 17, + 'Using callback file in runtime path: NONE' + ) // No errors expect(debugMock).toHaveBeenNthCalledWith(18, 0) @@ -52,4 +72,66 @@ describe('action', () => { 'Project encoded with success' ) }, 20000) + + it('run succefully with laravel template', async () => { + getInputMock.mockImplementation(name => { + if (name === 'template') return 'laravel' + }) + + await main.run() + expect(runMock).toHaveReturned() + + // Verify that all of the core library functions were called correctly with default values + expect(debugMock).toHaveBeenNthCalledWith( + 1, + 'Encoding files using template: laravel' + ) + expect(debugMock).toHaveBeenNthCalledWith( + 2, + 'Using encoder version: current' + ) + expect(debugMock).toHaveBeenNthCalledWith( + 3, + 'Using PHP target version: 8.2' + ) + expect(debugMock).toHaveBeenNthCalledWith( + 4, + 'Using target architecture: x86-64' + ) + expect(debugMock).toHaveBeenNthCalledWith(5, 'Using input files: .') + expect(debugMock).toHaveBeenNthCalledWith(6, 'Using output path: encrypted') + expect(debugMock).toHaveBeenNthCalledWith(7, 'Allowing reflection for all') + expect(debugMock).toHaveBeenNthCalledWith( + 8, + 'Encrypting files: *.blade.php' + ) + expect(debugMock).toHaveBeenNthCalledWith(9, 'Encoding into binary format') + expect(debugMock).toHaveBeenNthCalledWith(10, 'Using optimization: max') + expect(debugMock).toHaveBeenNthCalledWith(11, 'Now allow doc comments') + expect(debugMock).toHaveBeenNthCalledWith( + 12, + 'Not checking for loader in environment' + ) + expect(debugMock).toHaveBeenNthCalledWith(13, 'Adding preamble file: NONE') + expect(debugMock).toHaveBeenNthCalledWith(14, 'Using passphrase: CHANGEME') + expect(debugMock).toHaveBeenNthCalledWith(15, 'Using license check: script') + expect(debugMock).toHaveBeenNthCalledWith( + 16, + 'Using license file in runtime path: /opt/license' + ) + expect(debugMock).toHaveBeenNthCalledWith( + 17, + 'Using callback file in runtime path: public/ioncube.php' + ) + + // No errors + expect(debugMock).toHaveBeenNthCalledWith(18, 0) + expect(debugMock).toHaveBeenNthCalledWith(19, '') + expect(debugMock).toHaveBeenNthCalledWith(20, '') + + expect(setOutputMock).toHaveBeenCalledWith( + 'status', + 'Project encoded with success' + ) + }) }) diff --git a/badges/coverage.svg b/badges/coverage.svg index 331a352..1168477 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -Coverage: 89.69%Coverage89.69% \ No newline at end of file +Coverage: 91.85%Coverage91.85% \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 5b6457a..4b8f9dd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7,7 +7,6 @@ var __webpack_exports__ = {}; /** * The entrypoint for the action. */ -const { run } = require('./main') - -run() +import main from './main' +main.run() diff --git a/dist/licenses.txt b/dist/licenses.txt index d771846..a5ac3e7 100644 --- a/dist/licenses.txt +++ b/dist/licenses.txt @@ -1,94 +1,6 @@ -@actions/core +@vercel/ncc MIT -The MIT License (MIT) - -Copyright 2019 GitHub - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -@actions/exec -MIT -The MIT License (MIT) - -Copyright 2019 GitHub - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -@actions/http-client -MIT -Actions Http Client for Node.js - -Copyright (c) GitHub, Inc. - -All rights reserved. - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT -LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -@actions/io -MIT -The MIT License (MIT) - -Copyright 2019 GitHub - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -tunnel -MIT -The MIT License (MIT) - -Copyright (c) 2012 Koichi Kobayashi - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - -uuid -MIT -The MIT License (MIT) - -Copyright (c) 2010-2020 Robert Kieffer and other contributors +Copyright 2018 ZEIT, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/src/inputs/license.js b/src/inputs/license.js index 3178b76..fa172dd 100644 --- a/src/inputs/license.js +++ b/src/inputs/license.js @@ -6,6 +6,8 @@ const core = require('@actions/core') */ module.exports = function validateLicense(standard = '') { const license = core.getInput('with-license', { required: true }) ?? standard - core.debug(`Using license file in runtime path: ${license}`) + core.debug( + `Using license file in runtime path: ${license === '' ? 'NONE' : license}` + ) return license } diff --git a/src/inputs/template.js b/src/inputs/template.js index 7d32c01..a7da000 100644 --- a/src/inputs/template.js +++ b/src/inputs/template.js @@ -5,7 +5,7 @@ const core = require('@actions/core') * @returns {string} Returns a validated template input. */ module.exports = function validateTemplate() { - const template = core.getInput('template', { required: true }) ?? 'laravel' + const template = core.getInput('template', { required: true }) ?? 'php' core.debug(`Encoding files using template: ${template}`) // TODO: validate template values diff --git a/src/main.js b/src/main.js index c1379c6..07f313d 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,7 @@ const core = require('@actions/core') const exec = require('@actions/exec') const validate = require('./validate') +const binary = require('./inputs/binary') /** * The main function for the action. @@ -30,12 +31,56 @@ async function run() { options.failOnStdErr = false options.ignoreReturnCode = false + let customOptions = '' + + if (inputs.binary === true) { + customOptions += ' --binary' + } + + if (inputs.comments === false) { + customOptions += ' --no-doc-comments' + } + + if (inputs.encrypt !== '') { + customOptions += ` --encrypt "${inputs.encrypt}"` + } + + if (inputs.optimize === 'more' || inputs.optimize === 'max') { + customOptions += ` --optimize ${inputs.optimize}` + } + + if (inputs.reflection === true) { + customOptions += ` --allow-reflection-all` + } else if (inputs.reflection !== '') { + customOptions += ` --allow-reflection ${inputs.reflection}` + } + + if (inputs.preamble !== '') { + customOptions += ` --preamble-file ${inputs.preamble}` + } + + if (inputs.passphrase !== '') { + customOptions += ` --passphrase "${inputs.passphrase}"` + } + + if (inputs.license !== '') { + customOptions += ` --with-license ${inputs.license}` + } + + if (inputs.callback !== '') { + customOptions += ` --callback-file "${inputs.callback}"` + } + + if (inputs.check === 'auto' || inputs.check === 'script') { + customOptions += ` --license-check ${inputs.check}` + } + + customOptions.trim() + + const command = `${inputs.ioncube} -${inputs.encoderVersion} -${inputs.phpTargetVersion} -${inputs.arch} ${inputs.input} -o ${inputs.output} ${customOptions} --create-target --replace-target` + // core.debug(command) try { - const exitCode = await exec.exec( - `${inputs.ioncube} -${inputs.encoderVersion} -${inputs.phpTargetVersion} -${inputs.arch} ${inputs.input} -o ${inputs.output} --create-target --replace-target`, - [], - options - ) + const exitCode = await exec.exec(command, [], options) core.debug(exitCode) } catch (error) { core.error(error) diff --git a/src/templates/choose.js b/src/templates/choose.js index 97e50bb..3e994d1 100644 --- a/src/templates/choose.js +++ b/src/templates/choose.js @@ -8,7 +8,7 @@ const templates = { * Choose correct template based on template input value. * @returns {object} Returns defaults values based on templates. */ -module.exports = function choose(template = 'laravel') { +module.exports = function choose(template = 'php') { const standard = { encoderVersion: 'current', phpTargetVersion: '8.2', @@ -19,7 +19,7 @@ module.exports = function choose(template = 'laravel') { encrypt: '', binary: false, optimize: 'more', - comments: false, + comments: true, loader: false, preamble: '', passphrase: '', diff --git a/src/templates/laravel.js b/src/templates/laravel.js index 176428f..f944c25 100644 --- a/src/templates/laravel.js +++ b/src/templates/laravel.js @@ -13,10 +13,10 @@ module.exports = function laravel() { encrypt: '*.blade.php', binary: true, optimize: 'max', - comments: false, - loader: false, + comments: true, // without + loader: true, // without preamble: '', - passphrase: '', + passphrase: 'CHANGEME', check: 'script', license: '/opt/license', callback: 'public/ioncube.php'