Filter extensions marked for removal

This commit is contained in:
Shivam Mathur
2020-05-10 13:56:23 +05:30
parent 340bfd72bd
commit 28ef0db7df
7 changed files with 2090 additions and 1043 deletions

View File

@@ -1,4 +1,5 @@
import * as install from '../src/cache';
import * as utils from '../src/utils';
/**
* Mock cache.ts
@@ -6,8 +7,11 @@ import * as install from '../src/cache';
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';
@@ -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,
@@ -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');
});
});

View File

@@ -1,5 +1,3 @@
import * as fs from 'fs';
import * as path from 'path';
import * as utils from '../src/utils';
jest.mock('@actions/core', () => ({
@@ -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
dist/index.js vendored
View File

@@ -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';
/*
@@ -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);
}
});
});
}
@@ -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;
/***/ }),
@@ -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')
@@ -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;
/**
@@ -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
//-----------------------------------------------------------------------
@@ -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;
/**
@@ -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);
}
@@ -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);
@@ -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.

2956
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "cache-extensions",
"version": "1.0.5",
"version": "1.0.6",
"private": false,
"description": "Cache extensions in GitHub Actions",
"main": "dist/index.js",
@@ -24,25 +24,25 @@
"author": "shivammathur",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/exec": "^1.0.3"
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4"
},
"devDependencies": {
"@types/jest": "^25.2.1",
"@types/node": "^13.11.1",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"@types/node": "^13.13.5",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"@zeit/ncc": "^0.22.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.2",
"husky": "^4.2.4",
"jest": "^25.3.0",
"jest-circus": "^25.3.0",
"prettier": "^2.0.4",
"ts-jest": "^25.3.1",
"eslint-plugin-jest": "^23.10.0",
"eslint-plugin-prettier": "^3.1.3",
"husky": "^4.2.5",
"jest": "^26.0.1",
"jest-circus": "^26.0.1",
"prettier": "^2.0.5",
"ts-jest": "^25.5.1",
"typescript": "^3.8.3"
},
"husky": {

View File

@@ -10,7 +10,9 @@ export async function run(): Promise<void> {
try {
let version: string = await utils.getInput('php-version', true);
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
const extensions: string = await utils.getInput('extensions', true);
const extensions = await utils.filterExtensions(
await utils.getInput('extensions', true)
);
const key: string = await utils.getInput('key', true);
const script_path: string = path.join(__dirname, '../src/extensions.sh');
await exec(

View File

@@ -20,3 +20,17 @@ export async function getInput(
return input;
}
}
/**
* Function to filter extensions
*
* @param extension_csv
*/
export async function filterExtensions(extension_csv: string): Promise<string> {
return extension_csv
.split(',')
.filter(extension => {
return extension.trim()[0] != ':';
})
.join(',');
}