mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-23 04:11:06 +07:00
Add support to specify version in \d.x notation
This commit is contained in:
parent
6972aed899
commit
fbc8407035
@ -8,6 +8,12 @@ jest.mock('@actions/core', () => ({
|
|||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
jest.spyOn(utils, 'fetch').mockImplementation(
|
||||||
|
async (url): Promise<string> => {
|
||||||
|
return `{ "latest": "8.0", "5.x": "5.6", "url": "${url}" }`;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
async function cleanup(path: string): Promise<void> {
|
async function cleanup(path: string): Promise<void> {
|
||||||
fs.unlink(path, error => {
|
fs.unlink(path, error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -33,10 +39,18 @@ describe('Utils tests', () => {
|
|||||||
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
|
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('checking fetch', async () => {
|
||||||
|
expect(await utils.fetch('test_url')).toBe(
|
||||||
|
'{ "latest": "8.0", "5.x": "5.6", "url": "test_url" }'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('checking parseVersion', async () => {
|
it('checking parseVersion', async () => {
|
||||||
|
expect(await utils.parseVersion('latest')).toBe('8.0');
|
||||||
expect(await utils.parseVersion('7')).toBe('7.0');
|
expect(await utils.parseVersion('7')).toBe('7.0');
|
||||||
expect(await utils.parseVersion('7.4')).toBe('7.4');
|
expect(await utils.parseVersion('7.4')).toBe('7.4');
|
||||||
expect(await utils.parseVersion('latest')).toBe('8.0');
|
expect(await utils.parseVersion('5.x')).toBe('5.6');
|
||||||
|
expect(await utils.parseVersion('4.x')).toBe(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking asyncForEach', async () => {
|
it('checking asyncForEach', async () => {
|
||||||
|
40
dist/index.js
vendored
40
dist/index.js
vendored
@ -1054,8 +1054,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseVersion = exports.getInput = exports.readEnv = void 0;
|
exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseVersion = exports.fetch = exports.getInput = exports.readEnv = void 0;
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
|
const https = __importStar(__webpack_require__(211));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
/**
|
/**
|
||||||
@ -1094,15 +1095,34 @@ async function getInput(name, mandatory) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.getInput = getInput;
|
exports.getInput = getInput;
|
||||||
|
/**
|
||||||
|
* Function to fetch an URL
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
async function fetch(url) {
|
||||||
|
const fetch_promise = new Promise(resolve => {
|
||||||
|
const req = https.get(url, (res) => {
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
let body = '';
|
||||||
|
res.on('data', chunk => (body += chunk));
|
||||||
|
res.on('end', () => resolve(body));
|
||||||
|
});
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
|
return await fetch_promise;
|
||||||
|
}
|
||||||
|
exports.fetch = fetch;
|
||||||
/**
|
/**
|
||||||
* Function to parse PHP version.
|
* Function to parse PHP version.
|
||||||
*
|
*
|
||||||
* @param version
|
* @param version
|
||||||
*/
|
*/
|
||||||
async function parseVersion(version) {
|
async function parseVersion(version) {
|
||||||
switch (version) {
|
const manifest = 'https://dl.bintray.com/shivammathur/php/php-versions.json';
|
||||||
case 'latest':
|
switch (true) {
|
||||||
return '8.0';
|
case /latest|\d.x/.test(version):
|
||||||
|
return JSON.parse(await fetch(manifest))[version];
|
||||||
default:
|
default:
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case version.length > 1:
|
case version.length > 1:
|
||||||
@ -1394,6 +1414,13 @@ async function customPackage(pkg, type, version, os_version) {
|
|||||||
exports.customPackage = customPackage;
|
exports.customPackage = customPackage;
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 211:
|
||||||
|
/***/ (function(module) {
|
||||||
|
|
||||||
|
module.exports = require("https");
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 357:
|
/***/ 357:
|
||||||
@ -2595,12 +2622,17 @@ exports.getScript = getScript;
|
|||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const version = await utils.parseVersion(await utils.getInput('php-version', true));
|
const version = await utils.parseVersion(await utils.getInput('php-version', true));
|
||||||
|
if (version) {
|
||||||
const os_version = process.platform;
|
const os_version = process.platform;
|
||||||
const tool = await utils.scriptTool(os_version);
|
const tool = await utils.scriptTool(os_version);
|
||||||
const script = os_version + (await utils.scriptExtension(os_version));
|
const script = os_version + (await utils.scriptExtension(os_version));
|
||||||
const location = await getScript(script, version, os_version);
|
const location = await getScript(script, version, os_version);
|
||||||
await exec_1.exec(await utils.joins(tool, location, version, __dirname));
|
await exec_1.exec(await utils.joins(tool, location, version, __dirname));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
core.setFailed('Unable to get the PHP version');
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
6
src/configs/php-versions.json
Normal file
6
src/configs/php-versions.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"latest": "8.0",
|
||||||
|
"5.x": "5.6",
|
||||||
|
"7.x": "7.4",
|
||||||
|
"8.x": "8.0"
|
||||||
|
}
|
@ -54,11 +54,15 @@ export async function run(): Promise<void> {
|
|||||||
const version: string = await utils.parseVersion(
|
const version: string = await utils.parseVersion(
|
||||||
await utils.getInput('php-version', true)
|
await utils.getInput('php-version', true)
|
||||||
);
|
);
|
||||||
|
if (version) {
|
||||||
const os_version: string = process.platform;
|
const os_version: string = process.platform;
|
||||||
const tool = await utils.scriptTool(os_version);
|
const tool = await utils.scriptTool(os_version);
|
||||||
const script = os_version + (await utils.scriptExtension(os_version));
|
const script = os_version + (await utils.scriptExtension(os_version));
|
||||||
const location = await getScript(script, version, os_version);
|
const location = await getScript(script, version, os_version);
|
||||||
await exec(await utils.joins(tool, location, version, __dirname));
|
await exec(await utils.joins(tool, location, version, __dirname));
|
||||||
|
} else {
|
||||||
|
core.setFailed('Unable to get the PHP version');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
27
src/utils.ts
27
src/utils.ts
@ -1,4 +1,6 @@
|
|||||||
|
import {IncomingMessage} from 'http';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as https from 'https';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
@ -41,15 +43,34 @@ export async function getInput(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to fetch an URL
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
export async function fetch(url: string): Promise<string> {
|
||||||
|
const fetch_promise: Promise<string> = new Promise(resolve => {
|
||||||
|
const req = https.get(url, (res: IncomingMessage) => {
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
let body = '';
|
||||||
|
res.on('data', chunk => (body += chunk));
|
||||||
|
res.on('end', () => resolve(body));
|
||||||
|
});
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
|
return await fetch_promise;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to parse PHP version.
|
* Function to parse PHP version.
|
||||||
*
|
*
|
||||||
* @param version
|
* @param version
|
||||||
*/
|
*/
|
||||||
export async function parseVersion(version: string): Promise<string> {
|
export async function parseVersion(version: string): Promise<string> {
|
||||||
switch (version) {
|
const manifest = 'https://dl.bintray.com/shivammathur/php/php-versions.json';
|
||||||
case 'latest':
|
switch (true) {
|
||||||
return '8.0';
|
case /latest|\d.x/.test(version):
|
||||||
|
return JSON.parse(await fetch(manifest))[version];
|
||||||
default:
|
default:
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case version.length > 1:
|
case version.length > 1:
|
||||||
|
Loading…
Reference in New Issue
Block a user