mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 13:23:05 +07:00
Fix second run in the same job
Refactor install.ts and its tests
This commit is contained in:
parent
0022878947
commit
5acd006232
@ -5,81 +5,49 @@ import * as utils from '../src/utils';
|
|||||||
* Mock install.ts
|
* Mock install.ts
|
||||||
*/
|
*/
|
||||||
jest.mock('../src/install', () => ({
|
jest.mock('../src/install', () => ({
|
||||||
getScript: jest.fn().mockImplementation(async (): Promise<string> => {
|
getScript: jest
|
||||||
const extension_csv: string = process.env['extensions'] || '';
|
.fn()
|
||||||
const ini_values_csv: string = process.env['ini-values'] || '';
|
.mockImplementation(async (os: string): Promise<string> => {
|
||||||
const coverage_driver: string = process.env['coverage'] || '';
|
const filename = os + (await utils.scriptExtension(os));
|
||||||
const tools_csv: string = process.env['tools'] || '';
|
const version: string = await utils.parseVersion(
|
||||||
let script = 'initial script';
|
await utils.getInput('php-version', true)
|
||||||
script += extension_csv ? ' install extensions' : '';
|
);
|
||||||
script += tools_csv ? ' add_tool' : '';
|
const ini_file: string = await utils.parseIniFile(
|
||||||
script += coverage_driver ? ' set coverage driver' : '';
|
await utils.getInput('ini-file', false)
|
||||||
script += ini_values_csv ? ' edit php.ini' : '';
|
);
|
||||||
return script;
|
const extension_csv: string = process.env['extensions'] || '';
|
||||||
}),
|
const ini_values_csv: string = process.env['ini-values'] || '';
|
||||||
|
const coverage_driver: string = process.env['coverage'] || '';
|
||||||
|
const tools_csv: string = process.env['tools'] || '';
|
||||||
|
let script = await utils.joins(filename, version, ini_file);
|
||||||
|
script += extension_csv ? ' install extensions' : '';
|
||||||
|
script += tools_csv ? ' add_tool' : '';
|
||||||
|
script += coverage_driver ? ' set coverage driver' : '';
|
||||||
|
script += ini_values_csv ? ' edit php.ini' : '';
|
||||||
|
return script;
|
||||||
|
}),
|
||||||
run: jest.fn().mockImplementation(async (): Promise<string> => {
|
run: jest.fn().mockImplementation(async (): Promise<string> => {
|
||||||
const os: string = process.env['RUNNER_OS'] || '';
|
const os: string = process.env['RUNNER_OS'] || '';
|
||||||
const version: string = await utils.parseVersion(
|
|
||||||
await utils.getInput('php-version', true)
|
|
||||||
);
|
|
||||||
const ini_file: string = await utils.parseIniFile(
|
|
||||||
await utils.getInput('ini-file', false)
|
|
||||||
);
|
|
||||||
const tool = await utils.scriptTool(os);
|
const tool = await utils.scriptTool(os);
|
||||||
const filename = os + (await utils.scriptExtension(os));
|
return tool + (await install.getScript(os));
|
||||||
return [
|
|
||||||
await install.getScript(filename, version, os),
|
|
||||||
tool,
|
|
||||||
filename,
|
|
||||||
version,
|
|
||||||
ini_file
|
|
||||||
].join(' ');
|
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to set the process.env
|
|
||||||
*
|
|
||||||
* @param version
|
|
||||||
* @param os
|
|
||||||
* @param extension_csv
|
|
||||||
* @param ini_values_csv
|
|
||||||
* @param coverage_driver
|
|
||||||
* @param tools
|
|
||||||
*/
|
|
||||||
function setEnv(
|
|
||||||
version: string | number,
|
|
||||||
os: string,
|
|
||||||
extension_csv: string,
|
|
||||||
ini_file: string,
|
|
||||||
ini_values_csv: string,
|
|
||||||
coverage_driver: string,
|
|
||||||
tools: string
|
|
||||||
): void {
|
|
||||||
process.env['php-version'] = version.toString();
|
|
||||||
process.env['RUNNER_OS'] = os;
|
|
||||||
process.env['extensions'] = extension_csv;
|
|
||||||
process.env['ini-file'] = ini_file;
|
|
||||||
process.env['ini-values'] = ini_values_csv;
|
|
||||||
process.env['coverage'] = coverage_driver;
|
|
||||||
process.env['tools'] = tools;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Install', () => {
|
describe('Install', () => {
|
||||||
it.each`
|
it.each`
|
||||||
version | os | extension_csv | ini_file | ini_values_csv | coverage_driver | tools | output
|
version | os | extension_csv | ini_file | ini_values_csv | coverage_driver | tools | output
|
||||||
${'7.3'} | ${'darwin'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.3 production'}
|
${'7.3'} | ${'darwin'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'bash darwin.sh 7.3 production'}
|
||||||
${'7.3'} | ${'darwin'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini bash darwin.sh 7.3 development'}
|
${'7.3'} | ${'darwin'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${''} | ${'bash darwin.sh 7.3 development install extensions set coverage driver edit php.ini'}
|
||||||
${'7.4.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.4 none'}
|
${'7.4.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'bash darwin.sh 7.4 none'}
|
||||||
${'8'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 production'}
|
${'8'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${''} | ${'bash darwin.sh 8.0 production'}
|
||||||
${'8.0'} | ${'darwin'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 development'}
|
${'8.0'} | ${'darwin'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'bash darwin.sh 8.0 development'}
|
||||||
${'8.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.1 none'}
|
${'8.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'bash darwin.sh 8.1 none'}
|
||||||
${'7.3'} | ${'linux'} | ${''} | ${'invalid'} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 7.3 production'}
|
${'7.3'} | ${'linux'} | ${''} | ${'invalid'} | ${''} | ${''} | ${''} | ${'bash linux.sh 7.3 production'}
|
||||||
${'7.3'} | ${'linux'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${'initial script install extensions add_tool set coverage driver edit php.ini bash linux.sh 7.3 development'}
|
${'7.3'} | ${'linux'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${'bash linux.sh 7.3 development install extensions add_tool set coverage driver edit php.ini'}
|
||||||
${'latest'} | ${'linux'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 8.1 none'}
|
${'latest'} | ${'linux'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'bash linux.sh 8.1 none'}
|
||||||
${'7.0'} | ${'win32'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.0 production'}
|
${'7.0'} | ${'win32'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'pwsh win32.ps1 7.0 production'}
|
||||||
${'7.3'} | ${'win32'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.3 development'}
|
${'7.3'} | ${'win32'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'pwsh win32.ps1 7.3 development'}
|
||||||
${'7.3'} | ${'win32'} | ${'a, b'} | ${'none'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini pwsh win32.ps1 7.3 none'}
|
${'7.3'} | ${'win32'} | ${'a, b'} | ${'none'} | ${'a=b'} | ${'x'} | ${''} | ${'pwsh win32.ps1 7.3 none install extensions set coverage driver edit php.ini'}
|
||||||
`(
|
`(
|
||||||
'Test install on $os for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools',
|
'Test install on $os for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools',
|
||||||
async ({
|
async ({
|
||||||
@ -92,16 +60,13 @@ describe('Install', () => {
|
|||||||
tools,
|
tools,
|
||||||
output
|
output
|
||||||
}) => {
|
}) => {
|
||||||
setEnv(
|
process.env['php-version'] = version.toString();
|
||||||
version,
|
process.env['RUNNER_OS'] = os;
|
||||||
os,
|
process.env['extensions'] = extension_csv;
|
||||||
extension_csv,
|
process.env['ini-file'] = ini_file;
|
||||||
ini_file,
|
process.env['ini-values'] = ini_values_csv;
|
||||||
ini_values_csv,
|
process.env['coverage'] = coverage_driver;
|
||||||
coverage_driver,
|
process.env['tools'] = tools;
|
||||||
tools
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(await install.run()).toBe(output);
|
expect(await install.run()).toBe(output);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -219,9 +219,9 @@ describe('Utils tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checking scriptTool', async () => {
|
it('checking scriptTool', async () => {
|
||||||
expect(await utils.scriptTool('linux')).toBe('bash');
|
expect(await utils.scriptTool('linux')).toBe('bash ');
|
||||||
expect(await utils.scriptTool('darwin')).toBe('bash');
|
expect(await utils.scriptTool('darwin')).toBe('bash ');
|
||||||
expect(await utils.scriptTool('win32')).toBe('pwsh');
|
expect(await utils.scriptTool('win32')).toBe('pwsh ');
|
||||||
expect(await utils.scriptTool('openbsd')).toContain(
|
expect(await utils.scriptTool('openbsd')).toContain(
|
||||||
'Platform openbsd is not supported'
|
'Platform openbsd is not supported'
|
||||||
);
|
);
|
||||||
|
47
dist/index.js
vendored
47
dist/index.js
vendored
@ -434,6 +434,8 @@ var __importDefault = (this && this.__importDefault) || function (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 path_1 = __importDefault(__nccwpck_require__(17));
|
||||||
|
const fs_1 = __importDefault(__nccwpck_require__(147));
|
||||||
const exec_1 = __nccwpck_require__(514);
|
const exec_1 = __nccwpck_require__(514);
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
const config = __importStar(__nccwpck_require__(88));
|
const config = __importStar(__nccwpck_require__(88));
|
||||||
@ -441,17 +443,19 @@ 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));
|
async function getScript(os) {
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(147));
|
|
||||||
async function getScript(filename, version, os) {
|
|
||||||
const url = 'https://setup-php.com/sponsor';
|
const url = 'https://setup-php.com/sponsor';
|
||||||
|
const filename = os + (await utils.scriptExtension(os));
|
||||||
|
const script_path = path_1.default.join(__dirname, '../src/scripts', filename);
|
||||||
|
const run_path = script_path.replace(os, 'run');
|
||||||
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
||||||
const extension_csv = await utils.getInput('extensions', false);
|
const extension_csv = await utils.getInput('extensions', false);
|
||||||
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);
|
||||||
const script_path = path_1.default.join(__dirname, '../src/scripts', filename);
|
const version = await utils.parseVersion(await utils.getInput('php-version', true));
|
||||||
let script = '\n';
|
const ini_file = await utils.parseIniFile(await utils.getInput('ini-file', false));
|
||||||
|
let script = await utils.joins('.', script_path, version, ini_file);
|
||||||
if (extension_csv) {
|
if (extension_csv) {
|
||||||
script += await extensions.addExtension(extension_csv, version, os);
|
script += await extensions.addExtension(extension_csv, version, os);
|
||||||
}
|
}
|
||||||
@ -464,32 +468,15 @@ async function getScript(filename, version, os) {
|
|||||||
}
|
}
|
||||||
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os));
|
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os));
|
||||||
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os));
|
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os));
|
||||||
fs_1.default.appendFileSync(script_path, script, { mode: 0o755 });
|
fs_1.default.writeFileSync(run_path, script, { mode: 0o755 });
|
||||||
return script_path;
|
return run_path;
|
||||||
}
|
}
|
||||||
exports.getScript = getScript;
|
exports.getScript = getScript;
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
const os = process.platform;
|
||||||
if ((await utils.readEnv('ImageOS')) == 'ubuntu16') {
|
const tool = await utils.scriptTool(os);
|
||||||
core.setFailed('setup-php is not supported on Ubuntu 16.04. Please upgrade to Ubuntu 18.04 or Ubuntu 20.04 - https://setup-php.com/i/452');
|
const run_path = await getScript(os);
|
||||||
return;
|
await (0, exec_1.exec)(tool + run_path);
|
||||||
}
|
|
||||||
const version = await utils.parseVersion(await utils.getInput('php-version', true));
|
|
||||||
const ini_file = await utils.parseIniFile(await utils.getInput('ini-file', false));
|
|
||||||
if (version) {
|
|
||||||
const os = process.platform;
|
|
||||||
const tool = await utils.scriptTool(os);
|
|
||||||
const script = os + (await utils.scriptExtension(os));
|
|
||||||
const location = await getScript(script, version, os);
|
|
||||||
await (0, exec_1.exec)(await utils.joins(tool, location, version, ini_file));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.setFailed('Unable to get the PHP version');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
core.setFailed(error.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.run = run;
|
exports.run = run;
|
||||||
(async () => {
|
(async () => {
|
||||||
@ -1147,10 +1134,10 @@ exports.scriptExtension = scriptExtension;
|
|||||||
async function scriptTool(os) {
|
async function scriptTool(os) {
|
||||||
switch (os) {
|
switch (os) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return 'pwsh';
|
return 'pwsh ';
|
||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return 'bash';
|
return 'bash ';
|
||||||
default:
|
default:
|
||||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
import {exec} from '@actions/exec';
|
import {exec} from '@actions/exec';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as config from './config';
|
import * as config from './config';
|
||||||
@ -5,30 +7,29 @@ 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
|
||||||
*
|
*
|
||||||
* @param filename
|
|
||||||
* @param version
|
|
||||||
* @param os
|
* @param os
|
||||||
*/
|
*/
|
||||||
export async function getScript(
|
export async function getScript(os: string): Promise<string> {
|
||||||
filename: string,
|
|
||||||
version: string,
|
|
||||||
os: string
|
|
||||||
): Promise<string> {
|
|
||||||
const url = 'https://setup-php.com/sponsor';
|
const url = 'https://setup-php.com/sponsor';
|
||||||
// taking inputs
|
const filename = os + (await utils.scriptExtension(os));
|
||||||
|
const script_path = path.join(__dirname, '../src/scripts', filename);
|
||||||
|
const run_path = script_path.replace(os, 'run');
|
||||||
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
||||||
const extension_csv: string = await utils.getInput('extensions', false);
|
const extension_csv: string = await utils.getInput('extensions', false);
|
||||||
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);
|
const version: string = await utils.parseVersion(
|
||||||
let script = '\n';
|
await utils.getInput('php-version', true)
|
||||||
|
);
|
||||||
|
const ini_file: string = await utils.parseIniFile(
|
||||||
|
await utils.getInput('ini-file', false)
|
||||||
|
);
|
||||||
|
let script = await utils.joins('.', script_path, version, ini_file);
|
||||||
if (extension_csv) {
|
if (extension_csv) {
|
||||||
script += await extensions.addExtension(extension_csv, version, os);
|
script += await extensions.addExtension(extension_csv, version, os);
|
||||||
}
|
}
|
||||||
@ -42,40 +43,19 @@ export async function getScript(
|
|||||||
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os));
|
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os));
|
||||||
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os));
|
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os));
|
||||||
|
|
||||||
fs.appendFileSync(script_path, script, {mode: 0o755});
|
fs.writeFileSync(run_path, script, {mode: 0o755});
|
||||||
|
|
||||||
return script_path;
|
return run_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the script
|
* Run the script
|
||||||
*/
|
*/
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
const os: string = process.platform;
|
||||||
if ((await utils.readEnv('ImageOS')) == 'ubuntu16') {
|
const tool = await utils.scriptTool(os);
|
||||||
core.setFailed(
|
const run_path = await getScript(os);
|
||||||
'setup-php is not supported on Ubuntu 16.04. Please upgrade to Ubuntu 18.04 or Ubuntu 20.04 - https://setup-php.com/i/452'
|
await exec(tool + run_path);
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const version: string = await utils.parseVersion(
|
|
||||||
await utils.getInput('php-version', true)
|
|
||||||
);
|
|
||||||
const ini_file: string = await utils.parseIniFile(
|
|
||||||
await utils.getInput('ini-file', false)
|
|
||||||
);
|
|
||||||
if (version) {
|
|
||||||
const os: string = process.platform;
|
|
||||||
const tool = await utils.scriptTool(os);
|
|
||||||
const script = os + (await utils.scriptExtension(os));
|
|
||||||
const location = await getScript(script, version, os);
|
|
||||||
await exec(await utils.joins(tool, location, version, ini_file));
|
|
||||||
} else {
|
|
||||||
core.setFailed('Unable to get the PHP version');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
core.setFailed((error as Error).message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// call the run function
|
// call the run function
|
||||||
|
@ -401,10 +401,10 @@ export async function scriptExtension(os: string): Promise<string> {
|
|||||||
export async function scriptTool(os: string): Promise<string> {
|
export async function scriptTool(os: string): Promise<string> {
|
||||||
switch (os) {
|
switch (os) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return 'pwsh';
|
return 'pwsh ';
|
||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return 'bash';
|
return 'bash ';
|
||||||
default:
|
default:
|
||||||
return await log('Platform ' + os + ' is not supported', os, 'error');
|
return await log('Platform ' + os + ' is not supported', os, 'error');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user