Skip to content

Commit

Permalink
Merge pull request #9 from shivammathur/develop
Browse files Browse the repository at this point in the history
1.0.6
  • Loading branch information
shivammathur authored May 10, 2020
2 parents 340bfd7 + 28ef0db commit 76f84c1
Show file tree
Hide file tree
Showing 7 changed files with 2,091 additions and 1,044 deletions.
21 changes: 15 additions & 6 deletions __tests__/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import * as install from '../src/cache';
import * as utils from '../src/utils';

/**
* Mock cache.ts
*/
jest.mock('../src/cache', () => ({
run: jest.fn().mockImplementation(
async (): Promise<string> => {
const version: string = process.env['php-version'] || '';
const extensions: string = process.env['extensions'] || '';
let version: string = process.env['php-version'] || '';
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
const extensions = await utils.filterExtensions(
process.env['extensions'] || ''
);
const key: string = process.env['key'] || '';
const script_path = 'extensions.sh';

Expand All @@ -22,10 +26,8 @@ jest.mock('../src/cache', () => ({
* Function to set the process.env
*
* @param version
* @param os
* @param extension_csv
* @param ini_values_csv
* @param coverage_driver
* @param extensions
* @param key
*/
function setEnv(
version: string | number,
Expand All @@ -51,4 +53,11 @@ describe('Install', () => {
const script: string = await install.run();
expect(script).toContain('bash extensions.sh "xdebug, zip" cache-v2 7.4');
});

it('Test Run', async () => {
setEnv('7.4', 'xdebug, :zip', 'cache-v2');
// @ts-ignore
const script: string = await install.run();
expect(script).toContain('bash extensions.sh "xdebug" cache-v2 7.4');
});
});
7 changes: 5 additions & 2 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as fs from 'fs';
import * as path from 'path';
import * as utils from '../src/utils';

jest.mock('@actions/core', () => ({
Expand All @@ -19,4 +17,9 @@ describe('Utils tests', () => {
);
expect(await utils.getInput('DoesNotExist', false)).toBe('');
});

it('checking filterExtensions', async () => {
expect(await utils.filterExtensions('a,:b,c')).toBe('a,c');
expect(await utils.filterExtensions('a, :b, c')).toBe('a, c');
});
});
101 changes: 82 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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 });
const os = __webpack_require__(87);
const events = __webpack_require__(614);
const child = __webpack_require__(129);
const path = __webpack_require__(622);
const io = __webpack_require__(1);
const ioUtil = __webpack_require__(672);
const os = __importStar(__webpack_require__(87));
const events = __importStar(__webpack_require__(614));
const child = __importStar(__webpack_require__(129));
const path = __importStar(__webpack_require__(622));
const io = __importStar(__webpack_require__(1));
const ioUtil = __importStar(__webpack_require__(672));
/* eslint-disable @typescript-eslint/unbound-method */
const IS_WINDOWS = process.platform === 'win32';
/*
Expand Down Expand Up @@ -804,6 +811,12 @@ class ToolRunner extends events.EventEmitter {
resolve(exitCode);
}
});
if (this.options.input) {
if (!cp.stdin) {
throw new Error('child process missing stdin');
}
cp.stdin.end(this.options.input);
}
});
});
}
Expand Down Expand Up @@ -990,6 +1003,22 @@ function getInput(name, mandatory) {
});
}
exports.getInput = getInput;
/**
* Function to filter extensions
*
* @param extension_csv
*/
function filterExtensions(extension_csv) {
return __awaiter(this, void 0, void 0, function* () {
return extension_csv
.split(',')
.filter(extension => {
return extension.trim()[0] != ':';
})
.join(',');
});
}
exports.filterExtensions = filterExtensions;


/***/ }),
Expand Down Expand Up @@ -1068,14 +1097,28 @@ 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 (s || '')
return toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A');
}
function escapeProperty(s) {
return (s || '')
return toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
Expand Down Expand Up @@ -1131,11 +1174,13 @@ var ExitCode;
/**
* Sets env variable for this action and future actions in the job
* @param name the name of the variable to set
* @param val the value of the variable
* @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function exportVariable(name, val) {
process.env[name] = val;
command_1.issueCommand('set-env', { name }, val);
const convertedVal = command_1.toCommandValue(val);
process.env[name] = convertedVal;
command_1.issueCommand('set-env', { name }, convertedVal);
}
exports.exportVariable = exportVariable;
/**
Expand Down Expand Up @@ -1174,12 +1219,22 @@ exports.getInput = getInput;
* Sets the value of an output.
*
* @param name name of the output to set
* @param value value to store
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setOutput(name, value) {
command_1.issueCommand('set-output', { name }, value);
}
exports.setOutput = setOutput;
/**
* Enables or disables the echoing of commands into stdout for the rest of the step.
* Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.
*
*/
function setCommandEcho(enabled) {
command_1.issue('echo', enabled ? 'on' : 'off');
}
exports.setCommandEcho = setCommandEcho;
//-----------------------------------------------------------------------
// Results
//-----------------------------------------------------------------------
Expand Down Expand Up @@ -1213,18 +1268,18 @@ function debug(message) {
exports.debug = debug;
/**
* Adds an error issue
* @param message error issue message
* @param message error issue message. Errors will be converted to string via toString()
*/
function error(message) {
command_1.issue('error', message);
command_1.issue('error', message instanceof Error ? message.toString() : message);
}
exports.error = error;
/**
* Adds an warning issue
* @param message warning issue message
* @param message warning issue message. Errors will be converted to string via toString()
*/
function warning(message) {
command_1.issue('warning', message);
command_1.issue('warning', message instanceof Error ? message.toString() : message);
}
exports.warning = warning;
/**
Expand Down Expand Up @@ -1282,8 +1337,9 @@ exports.group = group;
* Saves state for current action, the state can only be retrieved by this action's post job execution.
*
* @param name name of the state to store
* @param value value to store
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function saveState(name, value) {
command_1.issueCommand('save-state', { name }, value);
}
Expand Down Expand Up @@ -1559,7 +1615,7 @@ function run() {
try {
let version = yield utils.getInput('php-version', true);
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
const extensions = yield utils.getInput('extensions', true);
const extensions = yield utils.filterExtensions(yield utils.getInput('extensions', true));
const key = yield utils.getInput('key', true);
const script_path = path.join(__dirname, '../src/extensions.sh');
yield exec_1.exec('bash ' + script_path + ' "' + extensions + '" ' + key + ' ' + version);
Expand Down Expand Up @@ -1597,8 +1653,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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 });
const tr = __webpack_require__(9);
const tr = __importStar(__webpack_require__(9));
/**
* Exec a command.
* Output will be streamed to the live console.
Expand Down
Loading

0 comments on commit 76f84c1

Please sign in to comment.