Skip to content

Commit

Permalink
adding parameters to encode command
Browse files Browse the repository at this point in the history
  • Loading branch information
MuriloChianfa committed Dec 8, 2023
1 parent 44a9a79 commit b603a31
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 107 deletions.
84 changes: 83 additions & 1 deletion __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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'
)
})
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 2 additions & 90 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/inputs/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/inputs/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 50 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/templates/choose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -19,7 +19,7 @@ module.exports = function choose(template = 'laravel') {
encrypt: '',
binary: false,
optimize: 'more',
comments: false,
comments: true,
loader: false,
preamble: '',
passphrase: '',
Expand Down
6 changes: 3 additions & 3 deletions src/templates/laravel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b603a31

Please sign in to comment.