diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 6772f6d0..725bb3bf 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -8,14 +8,6 @@ jest.mock('@actions/core', () => ({ }) })); -async function cleanup(path: string): Promise { - fs.unlink(path, error => { - if (error) { - console.log(error); - } - }); -} - describe('Utils tests', () => { it('checking readEnv', async () => { process.env['test'] = 'setup-php'; @@ -99,41 +91,6 @@ describe('Utils tests', () => { expect(await utils.color('warning')).toBe('33'); }); - it('checking readFile', async () => { - const darwin: string = fs.readFileSync( - path.join(__dirname, '../src/scripts/darwin.sh'), - 'utf8' - ); - const linux: string = fs.readFileSync( - path.join(__dirname, '../src/scripts/linux.sh'), - 'utf8' - ); - const win32: string = fs.readFileSync( - path.join(__dirname, '../src/scripts/win32.ps1'), - 'utf8' - ); - expect(await utils.readFile('darwin.sh', 'src/scripts')).toBe(darwin); - expect(await utils.readFile('darwin.sh', 'src/scripts')).toBe(darwin); - expect(await utils.readFile('linux.sh', 'src/scripts')).toBe(linux); - expect(await utils.readFile('linux.sh', 'src/scripts')).toBe(linux); - expect(await utils.readFile('win32.ps1', 'src/scripts')).toBe(win32); - expect(await utils.readFile('win32.ps1', 'src/scripts')).toBe(win32); - }); - - it('checking writeScripts', async () => { - const testString = 'sudo apt-get install php'; - const runner_dir: string = process.env['RUNNER_TOOL_CACHE'] || ''; - const script_path: string = path.join(runner_dir, 'test.sh'); - await utils.writeScript('test.sh', testString); - await fs.readFile( - script_path, - function (error: Error | null, data: Buffer) { - expect(testString).toBe(data.toString()); - } - ); - await cleanup(script_path); - }); - it('checking extensionArray', async () => { expect( await utils.extensionArray('a, :b, php_c, none, php-d, Zend e, :Zend f') diff --git a/dist/index.js b/dist/index.js index c61687e0..ad156132 100644 --- a/dist/index.js +++ b/dist/index.js @@ -433,6 +433,9 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = exports.getScript = void 0; const exec_1 = __nccwpck_require__(514); @@ -442,6 +445,8 @@ const coverage = __importStar(__nccwpck_require__(730)); const extensions = __importStar(__nccwpck_require__(390)); const tools = __importStar(__nccwpck_require__(740)); const utils = __importStar(__nccwpck_require__(918)); +const path_1 = __importDefault(__nccwpck_require__(17)); +const fs_1 = __importDefault(__nccwpck_require__(147)); async function getScript(filename, version, os_version) { const url = 'https://setup-php.com/sponsor'; process.env['fail_fast'] = await utils.getInput('fail-fast', false); @@ -449,7 +454,8 @@ async function getScript(filename, version, os_version) { const ini_values_csv = await utils.getInput('ini-values', false); const coverage_driver = await utils.getInput('coverage', false); const tools_csv = await utils.getInput('tools', false); - let script = await utils.readFile(filename, 'src/scripts'); + const script_path = path_1.default.join(__dirname, '../src/scripts', filename); + let script = fs_1.default.readFileSync(script_path, 'utf8'); if (extension_csv) { script += await extensions.addExtension(extension_csv, version, os_version); } @@ -462,7 +468,8 @@ async function getScript(filename, version, os_version) { } script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os_version)); script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os_version)); - return await utils.writeScript(filename, script); + fs_1.default.writeFileSync(script_path, script, { mode: 0o755 }); + return script_path; } exports.getScript = getScript; async function run() { @@ -522,9 +529,14 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.addTools = exports.functionRecord = exports.getData = exports.addWPCLI = exports.addSymfony = exports.addPHPUnitTools = exports.addPhive = exports.addPhing = exports.addPECL = exports.addDevTools = exports.addDeployer = exports.addComposer = exports.addBlackfirePlayer = exports.addPackage = exports.addArchive = exports.getPharUrl = exports.getUrl = exports.filterList = exports.getRelease = exports.getVersion = exports.getLatestVersion = exports.getSemverVersion = void 0; const utils = __importStar(__nccwpck_require__(918)); +const path_1 = __importDefault(__nccwpck_require__(17)); +const fs_1 = __importDefault(__nccwpck_require__(147)); async function getSemverVersion(data) { var _a; const search = data['version_prefix'] + data['version']; @@ -788,7 +800,8 @@ async function addWPCLI(data) { exports.addWPCLI = addWPCLI; async function getData(release, php_version, os_version) { var _a, _b, _c, _d, _e; - const json_file = await utils.readFile('tools.json', 'src/configs'); + const json_file_path = path_1.default.join(__dirname, '../src/configs/tools.json'); + const json_file = fs_1.default.readFileSync(json_file_path, 'utf8'); const json_objects = JSON.parse(json_file); release = release.replace(/\s+/g, ''); const parts = release.split(':'); @@ -915,8 +928,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.parseExtensionSource = exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readFile = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseIniFile = exports.parseVersion = exports.getManifestURL = exports.fetch = exports.getInput = exports.readEnv = void 0; -const fs = __importStar(__nccwpck_require__(147)); +exports.parseExtensionSource = exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseIniFile = exports.parseVersion = exports.getManifestURL = exports.fetch = exports.getInput = exports.readEnv = void 0; const https = __importStar(__nccwpck_require__(687)); const path = __importStar(__nccwpck_require__(17)); const url = __importStar(__nccwpck_require__(310)); @@ -1064,17 +1076,6 @@ async function addLog(mark, subject, message, os_version) { } } exports.addLog = addLog; -async function readFile(filename, directory) { - return fs.readFileSync(path.join(__dirname, '../' + directory, filename), 'utf8'); -} -exports.readFile = readFile; -async function writeScript(filename, script) { - const runner_dir = await getInput('RUNNER_TOOL_CACHE', false); - const script_path = path.join(runner_dir, filename); - fs.writeFileSync(script_path, script, { mode: 0o755 }); - return script_path; -} -exports.writeScript = writeScript; async function extensionArray(extension_csv) { switch (extension_csv) { case '': diff --git a/src/install.ts b/src/install.ts index 262ca6aa..40e79a96 100644 --- a/src/install.ts +++ b/src/install.ts @@ -5,6 +5,8 @@ import * as coverage from './coverage'; import * as extensions from './extensions'; import * as tools from './tools'; import * as utils from './utils'; +import path from 'path'; +import fs from 'fs'; /** * Build the script @@ -25,8 +27,8 @@ export async function getScript( const ini_values_csv: string = await utils.getInput('ini-values', false); const coverage_driver: string = await utils.getInput('coverage', false); const tools_csv: string = await utils.getInput('tools', false); - - let script: string = await utils.readFile(filename, 'src/scripts'); + const script_path = path.join(__dirname, '../src/scripts', filename); + let script: string = fs.readFileSync(script_path, 'utf8'); if (extension_csv) { script += await extensions.addExtension(extension_csv, version, os_version); } @@ -40,7 +42,9 @@ export async function getScript( script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os_version)); script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os_version)); - return await utils.writeScript(filename, script); + fs.writeFileSync(script_path, script, {mode: 0o755}); + + return script_path; } /** diff --git a/src/tools.ts b/src/tools.ts index 8b040f5f..edf758fc 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -1,4 +1,6 @@ import * as utils from './utils'; +import path from 'path'; +import fs from 'fs'; type RS = Record; type RSRS = Record; @@ -416,7 +418,8 @@ export async function getData( php_version: string, os_version: string ): Promise { - const json_file: string = await utils.readFile('tools.json', 'src/configs'); + const json_file_path = path.join(__dirname, '../src/configs/tools.json'); + const json_file: string = fs.readFileSync(json_file_path, 'utf8'); const json_objects: RSRS = JSON.parse(json_file); release = release.replace(/\s+/g, ''); const parts: string[] = release.split(':'); diff --git a/src/utils.ts b/src/utils.ts index bc7992bc..58c1f4e2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,4 @@ import {IncomingMessage, OutgoingHttpHeaders} from 'http'; -import * as fs from 'fs'; import * as https from 'https'; import * as path from 'path'; import * as url from 'url'; @@ -251,38 +250,6 @@ export async function addLog( } } -/** - * Read the scripts - * - * @param filename - * @param directory - */ -export async function readFile( - filename: string, - directory: string -): Promise { - return fs.readFileSync( - path.join(__dirname, '../' + directory, filename), - 'utf8' - ); -} - -/** - * Write final script which runs - * - * @param filename - * @param script - */ -export async function writeScript( - filename: string, - script: string -): Promise { - const runner_dir: string = await getInput('RUNNER_TOOL_CACHE', false); - const script_path: string = path.join(runner_dir, filename); - fs.writeFileSync(script_path, script, {mode: 0o755}); - return script_path; -} - /** * Function to break extension csv into an array *