mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-08-01 19:27:57 +07:00
Add support to fetch tool versions from packagist
This commit is contained in:
@ -267,7 +267,7 @@
|
||||
},
|
||||
"phpunit": {
|
||||
"type": "custom-function",
|
||||
"repository": "sebastianbergmann/phpunit",
|
||||
"repository": "phpunit/phpunit",
|
||||
"domain": "https://phar.phpunit.de",
|
||||
"function": "phpunit",
|
||||
"version_prefix": "",
|
||||
|
37
src/packagist.ts
Normal file
37
src/packagist.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import * as cv from 'compare-versions';
|
||||
import * as fetch from './fetch';
|
||||
|
||||
type RS = Record<string, string>;
|
||||
type RSRS = Record<string, RS>;
|
||||
|
||||
export async function search(
|
||||
package_name: string,
|
||||
php_version: string
|
||||
): Promise<string | null> {
|
||||
const response = await fetch.fetch(
|
||||
`https://repo.packagist.org/p2/${package_name}.json`
|
||||
);
|
||||
if (response.error || response.data === '[]') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = JSON.parse(response['data']);
|
||||
if (data && data.packages) {
|
||||
const versions = data.packages[package_name];
|
||||
versions.sort((a: RS, b: RS) => cv.compareVersions(b.version, a.version));
|
||||
|
||||
const result = versions.find((versionData: RSRS) => {
|
||||
if (versionData?.require?.php) {
|
||||
return versionData?.require?.php
|
||||
.split('|')
|
||||
.some(
|
||||
require => require && cv.satisfies(php_version + '.0', require)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return result ? result.version : null;
|
||||
}
|
||||
return null;
|
||||
}
|
15
src/tools.ts
15
src/tools.ts
@ -1,6 +1,7 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import * as fetch from './fetch';
|
||||
import * as packagist from './packagist';
|
||||
import * as utils from './utils';
|
||||
|
||||
type RS = Record<string, string>;
|
||||
@ -392,16 +393,10 @@ export async function addPhive(data: RS): Promise<string> {
|
||||
* @param data
|
||||
*/
|
||||
export async function addPHPUnitTools(data: RS): Promise<string> {
|
||||
if (data['version'] == 'latest') {
|
||||
if (/7\.3|8\.0/.test(data['php_version'])) {
|
||||
data['version'] = '9.6.8';
|
||||
} else if (/7\.[2-3]/.test(data['php_version'])) {
|
||||
data['version'] = '8.5.33';
|
||||
} else if (/7\.[1-3]/.test(data['php_version'])) {
|
||||
data['version'] = '7.5.20';
|
||||
} else if (/7\.[0-2]/.test(data['php_version'])) {
|
||||
data['version'] = '6.5.14';
|
||||
}
|
||||
if (data['version'] === 'latest') {
|
||||
data['version'] =
|
||||
(await packagist.search(data['repository'], data['php_version'])) ??
|
||||
'latest';
|
||||
}
|
||||
data['url'] = await getPharUrl(data);
|
||||
return await addArchive(data);
|
||||
|
Reference in New Issue
Block a user