mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 13:23:05 +07:00
Remove unnecessary writing of scripts to RUNNER_TOOL_CACHE
This commit is contained in:
parent
175c9649c4
commit
63c7766312
@ -8,14 +8,6 @@ jest.mock('@actions/core', () => ({
|
|||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|
||||||
async function cleanup(path: string): Promise<void> {
|
|
||||||
fs.unlink(path, error => {
|
|
||||||
if (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Utils tests', () => {
|
describe('Utils tests', () => {
|
||||||
it('checking readEnv', async () => {
|
it('checking readEnv', async () => {
|
||||||
process.env['test'] = 'setup-php';
|
process.env['test'] = 'setup-php';
|
||||||
@ -99,41 +91,6 @@ describe('Utils tests', () => {
|
|||||||
expect(await utils.color('warning')).toBe('33');
|
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 () => {
|
it('checking extensionArray', async () => {
|
||||||
expect(
|
expect(
|
||||||
await utils.extensionArray('a, :b, php_c, none, php-d, Zend e, :Zend f')
|
await utils.extensionArray('a, :b, php_c, none, php-d, Zend e, :Zend f')
|
||||||
|
33
dist/index.js
vendored
33
dist/index.js
vendored
@ -433,6 +433,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
__setModuleDefault(result, mod);
|
__setModuleDefault(result, mod);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.run = exports.getScript = void 0;
|
exports.run = exports.getScript = void 0;
|
||||||
const exec_1 = __nccwpck_require__(514);
|
const exec_1 = __nccwpck_require__(514);
|
||||||
@ -442,6 +445,8 @@ const coverage = __importStar(__nccwpck_require__(730));
|
|||||||
const extensions = __importStar(__nccwpck_require__(390));
|
const extensions = __importStar(__nccwpck_require__(390));
|
||||||
const tools = __importStar(__nccwpck_require__(740));
|
const tools = __importStar(__nccwpck_require__(740));
|
||||||
const utils = __importStar(__nccwpck_require__(918));
|
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) {
|
async function getScript(filename, version, os_version) {
|
||||||
const url = 'https://setup-php.com/sponsor';
|
const url = 'https://setup-php.com/sponsor';
|
||||||
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
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 ini_values_csv = await utils.getInput('ini-values', false);
|
||||||
const coverage_driver = await utils.getInput('coverage', false);
|
const coverage_driver = await utils.getInput('coverage', false);
|
||||||
const tools_csv = await utils.getInput('tools', 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) {
|
if (extension_csv) {
|
||||||
script += await extensions.addExtension(extension_csv, version, os_version);
|
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.stepLog(`Sponsor setup-php`, os_version));
|
||||||
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, 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;
|
exports.getScript = getScript;
|
||||||
async function run() {
|
async function run() {
|
||||||
@ -522,9 +529,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
__setModuleDefault(result, mod);
|
__setModuleDefault(result, mod);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
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;
|
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 utils = __importStar(__nccwpck_require__(918));
|
||||||
|
const path_1 = __importDefault(__nccwpck_require__(17));
|
||||||
|
const fs_1 = __importDefault(__nccwpck_require__(147));
|
||||||
async function getSemverVersion(data) {
|
async function getSemverVersion(data) {
|
||||||
var _a;
|
var _a;
|
||||||
const search = data['version_prefix'] + data['version'];
|
const search = data['version_prefix'] + data['version'];
|
||||||
@ -788,7 +800,8 @@ async function addWPCLI(data) {
|
|||||||
exports.addWPCLI = addWPCLI;
|
exports.addWPCLI = addWPCLI;
|
||||||
async function getData(release, php_version, os_version) {
|
async function getData(release, php_version, os_version) {
|
||||||
var _a, _b, _c, _d, _e;
|
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);
|
const json_objects = JSON.parse(json_file);
|
||||||
release = release.replace(/\s+/g, '');
|
release = release.replace(/\s+/g, '');
|
||||||
const parts = release.split(':');
|
const parts = release.split(':');
|
||||||
@ -915,8 +928,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
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;
|
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 fs = __importStar(__nccwpck_require__(147));
|
|
||||||
const https = __importStar(__nccwpck_require__(687));
|
const https = __importStar(__nccwpck_require__(687));
|
||||||
const path = __importStar(__nccwpck_require__(17));
|
const path = __importStar(__nccwpck_require__(17));
|
||||||
const url = __importStar(__nccwpck_require__(310));
|
const url = __importStar(__nccwpck_require__(310));
|
||||||
@ -1064,17 +1076,6 @@ async function addLog(mark, subject, message, os_version) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.addLog = addLog;
|
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) {
|
async function extensionArray(extension_csv) {
|
||||||
switch (extension_csv) {
|
switch (extension_csv) {
|
||||||
case '':
|
case '':
|
||||||
|
@ -5,6 +5,8 @@ import * as coverage from './coverage';
|
|||||||
import * as extensions from './extensions';
|
import * as extensions from './extensions';
|
||||||
import * as tools from './tools';
|
import * as tools from './tools';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the script
|
* Build the script
|
||||||
@ -25,8 +27,8 @@ export async function getScript(
|
|||||||
const ini_values_csv: string = await utils.getInput('ini-values', false);
|
const ini_values_csv: string = await utils.getInput('ini-values', false);
|
||||||
const coverage_driver: string = await utils.getInput('coverage', false);
|
const coverage_driver: string = await utils.getInput('coverage', false);
|
||||||
const tools_csv: string = await utils.getInput('tools', false);
|
const tools_csv: string = await utils.getInput('tools', false);
|
||||||
|
const script_path = path.join(__dirname, '../src/scripts', filename);
|
||||||
let script: string = await utils.readFile(filename, 'src/scripts');
|
let script: string = fs.readFileSync(script_path, 'utf8');
|
||||||
if (extension_csv) {
|
if (extension_csv) {
|
||||||
script += await extensions.addExtension(extension_csv, version, os_version);
|
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.stepLog(`Sponsor setup-php`, os_version));
|
||||||
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
type RS = Record<string, string>;
|
type RS = Record<string, string>;
|
||||||
type RSRS = Record<string, RS>;
|
type RSRS = Record<string, RS>;
|
||||||
@ -416,7 +418,8 @@ export async function getData(
|
|||||||
php_version: string,
|
php_version: string,
|
||||||
os_version: string
|
os_version: string
|
||||||
): Promise<RS> {
|
): Promise<RS> {
|
||||||
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);
|
const json_objects: RSRS = JSON.parse(json_file);
|
||||||
release = release.replace(/\s+/g, '');
|
release = release.replace(/\s+/g, '');
|
||||||
const parts: string[] = release.split(':');
|
const parts: string[] = release.split(':');
|
||||||
|
33
src/utils.ts
33
src/utils.ts
@ -1,5 +1,4 @@
|
|||||||
import {IncomingMessage, OutgoingHttpHeaders} from 'http';
|
import {IncomingMessage, OutgoingHttpHeaders} from 'http';
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as url from 'url';
|
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<string> {
|
|
||||||
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<string> {
|
|
||||||
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
|
* Function to break extension csv into an array
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user