Skip to content

Commit 76f84c1

Browse files
authored
Merge pull request #9 from shivammathur/develop
1.0.6
2 parents 340bfd7 + 28ef0db commit 76f84c1

File tree

7 files changed

+2091
-1044
lines changed

7 files changed

+2091
-1044
lines changed

__tests__/cache.test.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import * as install from '../src/cache';
2+
import * as utils from '../src/utils';
23

34
/**
45
* Mock cache.ts
56
*/
67
jest.mock('../src/cache', () => ({
78
run: jest.fn().mockImplementation(
89
async (): Promise<string> => {
9-
const version: string = process.env['php-version'] || '';
10-
const extensions: string = process.env['extensions'] || '';
10+
let version: string = process.env['php-version'] || '';
11+
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
12+
const extensions = await utils.filterExtensions(
13+
process.env['extensions'] || ''
14+
);
1115
const key: string = process.env['key'] || '';
1216
const script_path = 'extensions.sh';
1317

@@ -22,10 +26,8 @@ jest.mock('../src/cache', () => ({
2226
* Function to set the process.env
2327
*
2428
* @param version
25-
* @param os
26-
* @param extension_csv
27-
* @param ini_values_csv
28-
* @param coverage_driver
29+
* @param extensions
30+
* @param key
2931
*/
3032
function setEnv(
3133
version: string | number,
@@ -51,4 +53,11 @@ describe('Install', () => {
5153
const script: string = await install.run();
5254
expect(script).toContain('bash extensions.sh "xdebug, zip" cache-v2 7.4');
5355
});
56+
57+
it('Test Run', async () => {
58+
setEnv('7.4', 'xdebug, :zip', 'cache-v2');
59+
// @ts-ignore
60+
const script: string = await install.run();
61+
expect(script).toContain('bash extensions.sh "xdebug" cache-v2 7.4');
62+
});
5463
});

__tests__/utils.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as fs from 'fs';
2-
import * as path from 'path';
31
import * as utils from '../src/utils';
42

53
jest.mock('@actions/core', () => ({
@@ -19,4 +17,9 @@ describe('Utils tests', () => {
1917
);
2018
expect(await utils.getInput('DoesNotExist', false)).toBe('');
2119
});
20+
21+
it('checking filterExtensions', async () => {
22+
expect(await utils.filterExtensions('a,:b,c')).toBe('a,c');
23+
expect(await utils.filterExtensions('a, :b, c')).toBe('a, c');
24+
});
2225
});

dist/index.js

+82-19
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
354354
step((generator = generator.apply(thisArg, _arguments || [])).next());
355355
});
356356
};
357+
var __importStar = (this && this.__importStar) || function (mod) {
358+
if (mod && mod.__esModule) return mod;
359+
var result = {};
360+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
361+
result["default"] = mod;
362+
return result;
363+
};
357364
Object.defineProperty(exports, "__esModule", { value: true });
358-
const os = __webpack_require__(87);
359-
const events = __webpack_require__(614);
360-
const child = __webpack_require__(129);
361-
const path = __webpack_require__(622);
362-
const io = __webpack_require__(1);
363-
const ioUtil = __webpack_require__(672);
365+
const os = __importStar(__webpack_require__(87));
366+
const events = __importStar(__webpack_require__(614));
367+
const child = __importStar(__webpack_require__(129));
368+
const path = __importStar(__webpack_require__(622));
369+
const io = __importStar(__webpack_require__(1));
370+
const ioUtil = __importStar(__webpack_require__(672));
364371
/* eslint-disable @typescript-eslint/unbound-method */
365372
const IS_WINDOWS = process.platform === 'win32';
366373
/*
@@ -804,6 +811,12 @@ class ToolRunner extends events.EventEmitter {
804811
resolve(exitCode);
805812
}
806813
});
814+
if (this.options.input) {
815+
if (!cp.stdin) {
816+
throw new Error('child process missing stdin');
817+
}
818+
cp.stdin.end(this.options.input);
819+
}
807820
});
808821
});
809822
}
@@ -990,6 +1003,22 @@ function getInput(name, mandatory) {
9901003
});
9911004
}
9921005
exports.getInput = getInput;
1006+
/**
1007+
* Function to filter extensions
1008+
*
1009+
* @param extension_csv
1010+
*/
1011+
function filterExtensions(extension_csv) {
1012+
return __awaiter(this, void 0, void 0, function* () {
1013+
return extension_csv
1014+
.split(',')
1015+
.filter(extension => {
1016+
return extension.trim()[0] != ':';
1017+
})
1018+
.join(',');
1019+
});
1020+
}
1021+
exports.filterExtensions = filterExtensions;
9931022

9941023

9951024
/***/ }),
@@ -1068,14 +1097,28 @@ class Command {
10681097
return cmdStr;
10691098
}
10701099
}
1100+
/**
1101+
* Sanitizes an input into a string so it can be passed into issueCommand safely
1102+
* @param input input to sanitize into a string
1103+
*/
1104+
function toCommandValue(input) {
1105+
if (input === null || input === undefined) {
1106+
return '';
1107+
}
1108+
else if (typeof input === 'string' || input instanceof String) {
1109+
return input;
1110+
}
1111+
return JSON.stringify(input);
1112+
}
1113+
exports.toCommandValue = toCommandValue;
10711114
function escapeData(s) {
1072-
return (s || '')
1115+
return toCommandValue(s)
10731116
.replace(/%/g, '%25')
10741117
.replace(/\r/g, '%0D')
10751118
.replace(/\n/g, '%0A');
10761119
}
10771120
function escapeProperty(s) {
1078-
return (s || '')
1121+
return toCommandValue(s)
10791122
.replace(/%/g, '%25')
10801123
.replace(/\r/g, '%0D')
10811124
.replace(/\n/g, '%0A')
@@ -1131,11 +1174,13 @@ var ExitCode;
11311174
/**
11321175
* Sets env variable for this action and future actions in the job
11331176
* @param name the name of the variable to set
1134-
* @param val the value of the variable
1177+
* @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify
11351178
*/
1179+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11361180
function exportVariable(name, val) {
1137-
process.env[name] = val;
1138-
command_1.issueCommand('set-env', { name }, val);
1181+
const convertedVal = command_1.toCommandValue(val);
1182+
process.env[name] = convertedVal;
1183+
command_1.issueCommand('set-env', { name }, convertedVal);
11391184
}
11401185
exports.exportVariable = exportVariable;
11411186
/**
@@ -1174,12 +1219,22 @@ exports.getInput = getInput;
11741219
* Sets the value of an output.
11751220
*
11761221
* @param name name of the output to set
1177-
* @param value value to store
1222+
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
11781223
*/
1224+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11791225
function setOutput(name, value) {
11801226
command_1.issueCommand('set-output', { name }, value);
11811227
}
11821228
exports.setOutput = setOutput;
1229+
/**
1230+
* Enables or disables the echoing of commands into stdout for the rest of the step.
1231+
* Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.
1232+
*
1233+
*/
1234+
function setCommandEcho(enabled) {
1235+
command_1.issue('echo', enabled ? 'on' : 'off');
1236+
}
1237+
exports.setCommandEcho = setCommandEcho;
11831238
//-----------------------------------------------------------------------
11841239
// Results
11851240
//-----------------------------------------------------------------------
@@ -1213,18 +1268,18 @@ function debug(message) {
12131268
exports.debug = debug;
12141269
/**
12151270
* Adds an error issue
1216-
* @param message error issue message
1271+
* @param message error issue message. Errors will be converted to string via toString()
12171272
*/
12181273
function error(message) {
1219-
command_1.issue('error', message);
1274+
command_1.issue('error', message instanceof Error ? message.toString() : message);
12201275
}
12211276
exports.error = error;
12221277
/**
12231278
* Adds an warning issue
1224-
* @param message warning issue message
1279+
* @param message warning issue message. Errors will be converted to string via toString()
12251280
*/
12261281
function warning(message) {
1227-
command_1.issue('warning', message);
1282+
command_1.issue('warning', message instanceof Error ? message.toString() : message);
12281283
}
12291284
exports.warning = warning;
12301285
/**
@@ -1282,8 +1337,9 @@ exports.group = group;
12821337
* Saves state for current action, the state can only be retrieved by this action's post job execution.
12831338
*
12841339
* @param name name of the state to store
1285-
* @param value value to store
1340+
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
12861341
*/
1342+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
12871343
function saveState(name, value) {
12881344
command_1.issueCommand('save-state', { name }, value);
12891345
}
@@ -1559,7 +1615,7 @@ function run() {
15591615
try {
15601616
let version = yield utils.getInput('php-version', true);
15611617
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
1562-
const extensions = yield utils.getInput('extensions', true);
1618+
const extensions = yield utils.filterExtensions(yield utils.getInput('extensions', true));
15631619
const key = yield utils.getInput('key', true);
15641620
const script_path = path.join(__dirname, '../src/extensions.sh');
15651621
yield exec_1.exec('bash ' + script_path + ' "' + extensions + '" ' + key + ' ' + version);
@@ -1597,8 +1653,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15971653
step((generator = generator.apply(thisArg, _arguments || [])).next());
15981654
});
15991655
};
1656+
var __importStar = (this && this.__importStar) || function (mod) {
1657+
if (mod && mod.__esModule) return mod;
1658+
var result = {};
1659+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1660+
result["default"] = mod;
1661+
return result;
1662+
};
16001663
Object.defineProperty(exports, "__esModule", { value: true });
1601-
const tr = __webpack_require__(9);
1664+
const tr = __importStar(__webpack_require__(9));
16021665
/**
16031666
* Exec a command.
16041667
* Output will be streamed to the live console.

0 commit comments

Comments
 (0)