mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Fixed support for php-cs-fixer
Added fetch_latest to tools.json. When fetch_latest is true for a tool it will fetch the release.atom for the tool and parse that to get the latest release. Bumped lib version to ES2020 in tsconfig.json for string.matchAll.
This commit is contained in:
parent
c8b716540c
commit
4d3cfaa653
@ -3,7 +3,7 @@ import * as utils from '../src/utils';
|
|||||||
|
|
||||||
interface IData {
|
interface IData {
|
||||||
tool: string;
|
tool: string;
|
||||||
version: string;
|
version?: string;
|
||||||
domain?: string;
|
domain?: string;
|
||||||
extension?: string;
|
extension?: string;
|
||||||
os_version?: string;
|
os_version?: string;
|
||||||
@ -11,6 +11,7 @@ interface IData {
|
|||||||
release?: string;
|
release?: string;
|
||||||
repository?: string;
|
repository?: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
|
fetch_latest?: string;
|
||||||
version_parameter?: string;
|
version_parameter?: string;
|
||||||
version_prefix?: string;
|
version_prefix?: string;
|
||||||
}
|
}
|
||||||
@ -18,7 +19,7 @@ interface IData {
|
|||||||
function getData(data: IData): Record<string, string> {
|
function getData(data: IData): Record<string, string> {
|
||||||
return {
|
return {
|
||||||
tool: data.tool,
|
tool: data.tool,
|
||||||
version: data.version,
|
version: data.version || '',
|
||||||
domain: data.domain || 'https://example.com',
|
domain: data.domain || 'https://example.com',
|
||||||
extension: data.extension || '.phar',
|
extension: data.extension || '.phar',
|
||||||
os_version: data.os_version || 'linux',
|
os_version: data.os_version || 'linux',
|
||||||
@ -26,6 +27,7 @@ function getData(data: IData): Record<string, string> {
|
|||||||
release: data.release || [data.tool, data.version].join(':'),
|
release: data.release || [data.tool, data.version].join(':'),
|
||||||
repository: data.repository || '',
|
repository: data.repository || '',
|
||||||
type: data.type || 'phar',
|
type: data.type || 'phar',
|
||||||
|
fetch_latest: data.fetch_latest || 'false',
|
||||||
version_parameter: data.version_parameter || '-V',
|
version_parameter: data.version_parameter || '-V',
|
||||||
version_prefix: data.version_prefix || '',
|
version_prefix: data.version_prefix || '',
|
||||||
github: 'https://github.com',
|
github: 'https://github.com',
|
||||||
@ -38,7 +40,13 @@ jest
|
|||||||
.spyOn(utils, 'fetch')
|
.spyOn(utils, 'fetch')
|
||||||
.mockImplementation(
|
.mockImplementation(
|
||||||
async (url: string, token?: string): Promise<Record<string, string>> => {
|
async (url: string, token?: string): Promise<Record<string, string>> => {
|
||||||
if (!token || token === 'valid_token') {
|
if (url.includes('atom') && !url.includes('no-release')) {
|
||||||
|
return {
|
||||||
|
data: '"releases/tag/1.2.3", "releases/tag/3.2.1", "releases/tag/2.3.1"'
|
||||||
|
};
|
||||||
|
} else if (url.includes('no-release')) {
|
||||||
|
return {data: ''};
|
||||||
|
} else if (!token || token === 'valid_token') {
|
||||||
return {data: `[{"ref": "refs/tags/1.2.3", "url": "${url}"}]`};
|
return {data: `[{"ref": "refs/tags/1.2.3", "url": "${url}"}]`};
|
||||||
} else if (token === 'beta_token') {
|
} else if (token === 'beta_token') {
|
||||||
return {data: `[{"ref": "refs/tags/1.2.3-beta1", "url": "${url}"}]`};
|
return {data: `[{"ref": "refs/tags/1.2.3-beta1", "url": "${url}"}]`};
|
||||||
@ -64,6 +72,26 @@ describe('Tools tests', () => {
|
|||||||
).toBe(version);
|
).toBe(version);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each`
|
||||||
|
tool | fetch_latest | version
|
||||||
|
${'tool'} | ${'true'} | ${'3.2.1'}
|
||||||
|
${'tool-no-release'} | ${'true'} | ${'latest'}
|
||||||
|
${'tool'} | ${'false'} | ${'latest'}
|
||||||
|
`(
|
||||||
|
'checking getLatestVersion: $tool, $fetch_latest, $version',
|
||||||
|
async ({tool, fetch_latest, version}) => {
|
||||||
|
expect(
|
||||||
|
await tools.getLatestVersion(
|
||||||
|
getData({
|
||||||
|
tool: tool,
|
||||||
|
repository: 'user/' + tool,
|
||||||
|
fetch_latest: fetch_latest
|
||||||
|
})
|
||||||
|
)
|
||||||
|
).toBe(version);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
it.each`
|
it.each`
|
||||||
version | tool | type | expected
|
version | tool | type | expected
|
||||||
${'latest'} | ${'tool'} | ${'phar'} | ${'latest'}
|
${'latest'} | ${'tool'} | ${'phar'} | ${'latest'}
|
||||||
@ -353,7 +381,7 @@ describe('Tools tests', () => {
|
|||||||
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"',
|
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"',
|
||||||
'add_composertool flex flex symfony/',
|
'add_composertool flex flex symfony/',
|
||||||
'add_grpc_php_plugin latest',
|
'add_grpc_php_plugin latest',
|
||||||
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer "-V"',
|
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.2.1/php-cs-fixer.phar php-cs-fixer "-V"',
|
||||||
'add_composertool phplint phplint overtrue/',
|
'add_composertool phplint phplint overtrue/',
|
||||||
'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan "-V"',
|
'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan "-V"',
|
||||||
'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"',
|
'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"',
|
||||||
|
24
dist/index.js
vendored
24
dist/index.js
vendored
@ -493,7 +493,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.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.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));
|
||||||
async function getSemverVersion(data) {
|
async function getSemverVersion(data) {
|
||||||
var _a;
|
var _a;
|
||||||
@ -513,6 +513,19 @@ async function getSemverVersion(data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.getSemverVersion = getSemverVersion;
|
exports.getSemverVersion = getSemverVersion;
|
||||||
|
async function getLatestVersion(data) {
|
||||||
|
if (!data['version'] && data['fetch_latest'] === 'false') {
|
||||||
|
return 'latest';
|
||||||
|
}
|
||||||
|
const resp = await utils.fetch(`${data['github']}/${data['repository']}/releases.atom`);
|
||||||
|
const releases = [
|
||||||
|
...resp['data'].matchAll(/releases\/tag\/([a-zA-Z]*)?(\d+.\d+.\d+)"/g)
|
||||||
|
].map(match => match[2]);
|
||||||
|
return (releases
|
||||||
|
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
|
||||||
|
.pop() || 'latest');
|
||||||
|
}
|
||||||
|
exports.getLatestVersion = getLatestVersion;
|
||||||
async function getVersion(version, data) {
|
async function getVersion(version, data) {
|
||||||
const semver_regex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
const semver_regex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
||||||
const composer_regex = /^composer:(stable|preview|snapshot|[1|2])$/;
|
const composer_regex = /^composer:(stable|preview|snapshot|[1|2])$/;
|
||||||
@ -747,7 +760,7 @@ 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;
|
var _a, _b, _c, _d;
|
||||||
const json_file = await utils.readFile('tools.json', 'src/configs');
|
const json_file = await utils.readFile('tools.json', 'src/configs');
|
||||||
const json_objects = JSON.parse(json_file);
|
const json_objects = JSON.parse(json_file);
|
||||||
release = release.replace(/\s+/g, '');
|
release = release.replace(/\s+/g, '');
|
||||||
@ -783,10 +796,13 @@ async function getData(release, php_version, os_version) {
|
|||||||
data['php_version'] = php_version;
|
data['php_version'] = php_version;
|
||||||
data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
|
data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
|
||||||
data['verb'] = data['github'] === data['domain'] ? 'download' : '';
|
data['verb'] = data['github'] === data['domain'] ? 'download' : '';
|
||||||
|
(_c = data['fetch_latest']) !== null && _c !== void 0 ? _c : (data['fetch_latest'] = 'false');
|
||||||
data['version_parameter'] = JSON.stringify(data['version_parameter']) || '';
|
data['version_parameter'] = JSON.stringify(data['version_parameter']) || '';
|
||||||
(_c = data['version_prefix']) !== null && _c !== void 0 ? _c : (data['version_prefix'] = '');
|
(_d = data['version_prefix']) !== null && _d !== void 0 ? _d : (data['version_prefix'] = '');
|
||||||
data['release'] = await getRelease(release, data);
|
data['release'] = await getRelease(release, data);
|
||||||
data['version'] = version ? await getVersion(version, data) : 'latest';
|
data['version'] = version
|
||||||
|
? await getVersion(version, data)
|
||||||
|
: await getLatestVersion(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
exports.getData = getData;
|
exports.getData = getData;
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
"repository": "FriendsOfPHP/PHP-CS-Fixer",
|
"repository": "FriendsOfPHP/PHP-CS-Fixer",
|
||||||
"extension": ".phar",
|
"extension": ".phar",
|
||||||
"domain": "https://github.com",
|
"domain": "https://github.com",
|
||||||
|
"fetch_latest": "true",
|
||||||
"version_prefix": "v",
|
"version_prefix": "v",
|
||||||
"version_parameter": "-V"
|
"version_parameter": "-V"
|
||||||
},
|
},
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"alias": "tool_alias",
|
"alias": "tool_alias",
|
||||||
"domain": "https://example.com",
|
"domain": "https://example.com",
|
||||||
"extension": ".ext",
|
"extension": ".ext",
|
||||||
|
"fetch_latest": "true",
|
||||||
"function": "function_name",
|
"function": "function_name",
|
||||||
"repository": "user/tool",
|
"repository": "user/tool",
|
||||||
"type": "phar, composer, custom-package or custom-function",
|
"type": "phar, composer, custom-package or custom-function",
|
||||||
@ -47,6 +48,16 @@
|
|||||||
".ext"
|
".ext"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"fetch_latest": {
|
||||||
|
"$id": "#/items/properties/fetch_latest",
|
||||||
|
"type": "string",
|
||||||
|
"title": "The fetch_latest schema",
|
||||||
|
"description": "Fetch the latest version from GitHub releases.",
|
||||||
|
"enum": [
|
||||||
|
"true",
|
||||||
|
"false"
|
||||||
|
]
|
||||||
|
},
|
||||||
"function": {
|
"function": {
|
||||||
"$id": "#/items/properties/function",
|
"$id": "#/items/properties/function",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
30
src/tools.ts
30
src/tools.ts
@ -31,6 +31,31 @@ export async function getSemverVersion(data: RS): Promise<string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to get latest version from releases.atom
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function getLatestVersion(data: RS): Promise<string> {
|
||||||
|
if (!data['version'] && data['fetch_latest'] === 'false') {
|
||||||
|
return 'latest';
|
||||||
|
}
|
||||||
|
const resp: Record<string, string> = await utils.fetch(
|
||||||
|
`${data['github']}/${data['repository']}/releases.atom`
|
||||||
|
);
|
||||||
|
const releases: string[] = [
|
||||||
|
...resp['data'].matchAll(/releases\/tag\/([a-zA-Z]*)?(\d+.\d+.\d+)"/g)
|
||||||
|
].map(match => match[2]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
releases
|
||||||
|
.sort((a: string, b: string) =>
|
||||||
|
a.localeCompare(b, undefined, {numeric: true})
|
||||||
|
)
|
||||||
|
.pop() || 'latest'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get tool version
|
* Function to get tool version
|
||||||
*
|
*
|
||||||
@ -423,10 +448,13 @@ export async function getData(
|
|||||||
data['php_version'] = php_version;
|
data['php_version'] = php_version;
|
||||||
data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
|
data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
|
||||||
data['verb'] = data['github'] === data['domain'] ? 'download' : '';
|
data['verb'] = data['github'] === data['domain'] ? 'download' : '';
|
||||||
|
data['fetch_latest'] ??= 'false';
|
||||||
data['version_parameter'] = JSON.stringify(data['version_parameter']) || '';
|
data['version_parameter'] = JSON.stringify(data['version_parameter']) || '';
|
||||||
data['version_prefix'] ??= '';
|
data['version_prefix'] ??= '';
|
||||||
data['release'] = await getRelease(release, data);
|
data['release'] = await getRelease(release, data);
|
||||||
data['version'] = version ? await getVersion(version, data) : 'latest';
|
data['version'] = version
|
||||||
|
? await getVersion(version, data)
|
||||||
|
: await getLatestVersion(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"ES2019"
|
"ES2020"
|
||||||
],
|
],
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
|
Loading…
Reference in New Issue
Block a user