Skip to content

Commit

Permalink
adding more parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
MuriloChianfa committed Dec 8, 2023
1 parent 7a4364d commit 44a9a79
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 39 deletions.
6 changes: 3 additions & 3 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ describe('action', () => {
expect(debugMock).toHaveBeenNthCalledWith(6, 'Using output path: encrypted')

// No errors
expect(debugMock).toHaveBeenNthCalledWith(7, 0)
expect(debugMock).toHaveBeenNthCalledWith(8, '')
expect(debugMock).toHaveBeenNthCalledWith(9, '')
expect(debugMock).toHaveBeenNthCalledWith(18, 0)
expect(debugMock).toHaveBeenNthCalledWith(19, '')
expect(debugMock).toHaveBeenNthCalledWith(20, '')

expect(setOutputMock).toHaveBeenCalledWith(
'status',
Expand Down
111 changes: 93 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ description: 'Github action for integrate your project encode with ioncube into
author: 'MuriloChianfa'

inputs:
# Basic inputs
trial:
description: 'Encode file with trial version of ioncube'
required: true
default: false
type: boolean
template:
description: 'The template to choose the best parameters for type of projects'
required: true
Expand All @@ -11,23 +17,8 @@ inputs:
options:
- laravel
- php
trial:
description: 'Encode file with trial version of ioncube'
required: true
default: false
type: boolean

source:
description: 'The source path or file to encode'
required: true
default: ''
type: string
output:
description: 'The output path or file encoded'
required: true
default: 'encrypted'
type: string

# Encoder inputs
encoder-version:
description: 'Ioncube encoder version'
required: true
Expand All @@ -37,7 +28,6 @@ inputs:
- current
- legacy
- obsolete

php-target-version:
description: 'PHP encoded files target version'
required: true
Expand All @@ -47,7 +37,6 @@ inputs:
- '8.2'
- '8.1'
- '8.0'

arch:
description: 'Architecture of target environment runner'
required: true
Expand All @@ -57,6 +46,92 @@ inputs:
- 86
- 64

# File inputs
source:
description: 'The source path or file to encode'
required: true
default: ''
type: string
output:
description: 'The output path or file encoded'
required: true
default: 'encrypted'
type: string

# Reflection API
allow-reflection:
description: 'Name or glob to funcions or classes for allow the reflection API'
required: true
default: ''
type: string
allow-reflection-all:
description: 'Allow the reflection API at all the PHP code'
required: true
default: false
type: boolean

# Files customization
encrypt:
description: 'Name or glob to files to encrypt'
required: true
default: ''
type: string
binary:
description: 'Encode files in binary format'
required: true
default: false
type: boolean
optimize:
description: 'Level of encoding performance'
required: true
default: 'max'
type: choice
options:
- 'more'
- 'max'

# Output customizations
no-doc-comments:
description: 'Not allow doc comments on encoded files'
required: true
default: true
type: boolean
without-loader-check:
description: 'Disable the ioncube loader installation verification'
required: true
default: true
type: boolean
preamble-file:
description: 'File for insert into header of all encoded files'
required: true
default: ''
type: string

# License options
passphrase:
description: 'Text to identify and encode the project unically'
required: true
default: ''
type: string
license-check:
description: 'Mode of license validation for encoded files'
required: true
default: 'auto'
type: choice
options:
- 'auto'
- 'script'
with-license:
description: 'The license file path at runtime environment'
required: true
default: ''
type: string
callback-file:
description: 'File to validate manually when license is invalid'
required: true
default: ''
type: string

outputs:
status:
description: 'The message of encode proccess'
Expand Down
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.
15 changes: 15 additions & 0 deletions src/inputs/binary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const core = require('@actions/core')

/**
* Validate binary input values.
* @returns {bool|string} Returns a validated binary input.
*/
module.exports = function validateBinary(standard = false) {
const binary = core.getInput('binary', { required: true }) ?? standard
core.debug(
binary === true
? 'Encoding into binary format'
: 'Encoding into ASCII format'
)
return binary
}
16 changes: 16 additions & 0 deletions src/inputs/callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const core = require('@actions/core')

/**
* Validate callback input values.
* @returns {bool|string} Returns a validated callback input.
*/
module.exports = function validateCallback(standard = '') {
const callback =
core.getInput('callback-file', { required: true }) ?? standard
core.debug(
`Using callback file in runtime path: ${
callback === '' ? 'NONE' : callback
}`
)
return callback
}
18 changes: 18 additions & 0 deletions src/inputs/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const core = require('@actions/core')

/**
* Validate check input values.
* @returns {bool|string} Returns a validated check input.
*/
module.exports = function validateCheck(standard = 'auto') {
let check = core.getInput('license-check', { required: true }) ?? standard

if (check === 'auto') {
check = 'auto'
} else {
check = 'script'
}

core.debug(`Using license check: ${check}`)
return check
}
15 changes: 15 additions & 0 deletions src/inputs/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const core = require('@actions/core')

/**
* Validate comments input values.
* @returns {bool|string} Returns a validated comments input.
*/
module.exports = function validateComments(standard = true) {
const comments = !(
core.getInput('no-doc-comments', { required: true }) ?? standard
)
core.debug(
comments === true ? 'Allowing doc comments' : 'Now allow doc comments'
)
return comments
}
11 changes: 11 additions & 0 deletions src/inputs/encrypt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const core = require('@actions/core')

/**
* Validate encrypt input values.
* @returns {bool|string} Returns a validated encrypt input.
*/
module.exports = function validateEncrypt(standard = '') {
const encrypt = core.getInput('encrypt', { required: true }) ?? standard
core.debug(`Encrypting files: ${encrypt === '' ? 'NONE' : encrypt}`)
return encrypt
}
11 changes: 11 additions & 0 deletions src/inputs/license.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const core = require('@actions/core')

/**
* Validate license input values.
* @returns {bool|string} Returns a validated license input.
*/
module.exports = function validateLicense(standard = '') {
const license = core.getInput('with-license', { required: true }) ?? standard
core.debug(`Using license file in runtime path: ${license}`)
return license
}
17 changes: 17 additions & 0 deletions src/inputs/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const core = require('@actions/core')

/**
* Validate loader input values.
* @returns {bool|string} Returns a validated loader input.
*/
module.exports = function validateLoader(standard = true) {
const loader = !(
core.getInput('without-loader-check', { required: true }) ?? standard
)
core.debug(
loader === true
? 'Checking for loader in environment'
: 'Not checking for loader in environment'
)
return loader
}
18 changes: 18 additions & 0 deletions src/inputs/optimize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const core = require('@actions/core')

/**
* Validate optimize input values.
* @returns {bool|string} Returns a validated optimize input.
*/
module.exports = function validateOptimize(standard = 'max') {
let optimize = core.getInput('optimize', { required: true }) ?? standard

if (optimize === 'more') {
optimize = 'more'
} else {
optimize = 'max'
}

core.debug(`Using optimization: ${optimize}`)
return optimize
}
11 changes: 11 additions & 0 deletions src/inputs/passphrase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const core = require('@actions/core')

/**
* Validate passphrase input values.
* @returns {bool|string} Returns a validated passphrase input.
*/
module.exports = function validatePassphrase(standard = '') {
const passphrase = core.getInput('passphrase', { required: true }) ?? standard
core.debug(`Using passphrase: ${passphrase === '' ? 'NONE' : passphrase}`)
return passphrase
}
12 changes: 12 additions & 0 deletions src/inputs/preamble.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const core = require('@actions/core')

/**
* Validate preamble input values.
* @returns {bool|string} Returns a validated preamble input.
*/
module.exports = function validatePreamble(standard = '') {
const preamble =
core.getInput('preamble-file', { required: true }) ?? standard
core.debug(`Adding preamble file: ${preamble === '' ? 'NONE' : preamble}`)
return preamble
}
21 changes: 21 additions & 0 deletions src/inputs/reflection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const core = require('@actions/core')

/**
* Validate reflection input values.
* @returns {bool|string} Returns a validated reflection input.
*/
module.exports = function validateReflection(standard = false) {
const reflectionAll =
core.getInput('allow-reflection-all', { required: true }) ?? standard

if (reflectionAll === true) {
core.debug('Allowing reflection for all')
return true
}

const reflection =
core.getInput('allow-reflection', { required: true }) ??
(standard === false ? '' : standard)
core.debug(`Using reflection for: ${reflection === '' ? 'NONE' : reflection}`)
return reflection
}
15 changes: 13 additions & 2 deletions src/templates/choose.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ const templates = {
* Choose correct template based on template input value.
* @returns {object} Returns defaults values based on templates.
*/
module.exports = async function choose(template = 'laravel') {
module.exports = function choose(template = 'laravel') {
const standard = {
encoderVersion: 'current',
phpTargetVersion: '8.2',
arch: 64,
input: '',
output: 'encrypted'
output: 'encrypted',
reflection: false,
encrypt: '',
binary: false,
optimize: 'more',
comments: false,
loader: false,
preamble: '',
passphrase: '',
check: 'auto',
license: '',
callback: ''
}

const args = templates[template]?.()
Expand Down
15 changes: 13 additions & 2 deletions src/templates/laravel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
* Input values for laravel projects.
* @returns {object} Returns defaults values for laravel template.
*/
module.exports = async function laravel() {
module.exports = function laravel() {
return {
encoderVersion: 'current',
phpTargetVersion: '8.2',
arch: 64,
input: '',
output: 'encrypted'
output: 'encrypted',
reflection: true,
encrypt: '*.blade.php',
binary: true,
optimize: 'max',
comments: false,
loader: false,
preamble: '',
passphrase: '',
check: 'script',
license: '/opt/license',
callback: 'public/ioncube.php'
}
}
Loading

0 comments on commit 44a9a79

Please sign in to comment.