From 15b20027cf4e61cb21f2582a8f125cafb1c0492e Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 13 Dec 2021 07:47:57 +0530 Subject: [PATCH] Use GitHub releases for phive's latest version --- __tests__/tools.test.ts | 5 ++--- dist/index.js | 22 ++++++++++------------ src/configs/tools.json | 2 +- src/tools.ts | 21 ++++++++++----------- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 3072015a..ee9d3488 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -227,7 +227,7 @@ describe('Tools tests', () => { it.each` version | php_version | os_version | script - ${'latest'} | ${'7.4'} | ${'linux'} | ${'add_tool https://phar.io/releases/phive.phar phive'} + ${'latest'} | ${'7.4'} | ${'linux'} | ${'add_tool https://github.com/phar-io/phive/releases/download/3.2.1/phive-3.2.1.phar phive'} ${'1.2.3'} | ${'7.4'} | ${'darwin'} | ${'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive'} ${'1.2.3'} | ${'7.2'} | ${'win32'} | ${'Add-Tool https://github.com/phar-io/phive/releases/download/0.14.5/phive-0.14.5.phar phive'} ${'1.2.3'} | ${'7.1'} | ${'win32'} | ${'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.5/phive-0.13.5.phar phive'} @@ -238,7 +238,6 @@ describe('Tools tests', () => { async ({version, php_version, os_version, script}) => { const data = getData({ tool: 'phive', - domain: 'https://phar.io', repository: 'phar-io/phive', version_parameter: 'status', version: version, @@ -391,7 +390,7 @@ describe('Tools tests', () => { 'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"', 'add_composertool phinx phinx robmorgan/', 'add_composertool phinx phinx:1.2.3 robmorgan/', - 'add_tool https://phar.io/releases/phive.phar phive "status"', + 'add_tool https://github.com/phar-io/phive/releases/download/3.2.1/phive-3.2.1.phar phive "status"', 'add_composertool phpunit-bridge phpunit-bridge symfony/', 'add_composertool phpunit-polyfills phpunit-polyfills yoast/', 'add_devtools php-config', diff --git a/dist/index.js b/dist/index.js index 5987db1c..af590123 100644 --- a/dist/index.js +++ b/dist/index.js @@ -724,26 +724,24 @@ async function addPhive(data) { case /5\.[3-5]/.test(data['php_version']): return await utils.addLog('$cross', 'phive', 'Phive is not supported on PHP ' + data['php_version'], data['os_version']); case /5\.6|7\.0/.test(data['php_version']): - data['version'] = data['version'].replace('latest', '0.12.1'); + data['version'] = '0.12.1'; break; case /7\.1/.test(data['php_version']): - data['version'] = data['version'].replace('latest', '0.13.5'); + data['version'] = '0.13.5'; break; case /7\.2/.test(data['php_version']): - data['version'] = data['version'].replace('latest', '0.14.5'); + data['version'] = '0.14.5'; break; } if (data['version'] === 'latest') { - data['domain'] = data['domain'] + '/releases'; - } - else { - data['domain'] = [ - data['github'], - data['repository'], - 'releases/download', - data['version'] - ].join('/'); + data['version'] = await getLatestVersion(data); } + data['domain'] = [ + data['github'], + data['repository'], + 'releases/download', + data['version'] + ].join('/'); data['url'] = await getPharUrl(data); return await addArchive(data); } diff --git a/src/configs/tools.json b/src/configs/tools.json index 38eab418..583fc275 100644 --- a/src/configs/tools.json +++ b/src/configs/tools.json @@ -205,7 +205,7 @@ "phive": { "type": "custom-function", "repository": "phar-io/phive", - "domain": "https://phar.io", + "domain": "https://github.com", "function": "phive", "version_prefix": "", "version_parameter": "status" diff --git a/src/tools.ts b/src/tools.ts index 607bb6ab..5f5915ad 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -319,25 +319,24 @@ export async function addPhive(data: RS): Promise { data['os_version'] ); case /5\.6|7\.0/.test(data['php_version']): - data['version'] = data['version'].replace('latest', '0.12.1'); + data['version'] = '0.12.1'; break; case /7\.1/.test(data['php_version']): - data['version'] = data['version'].replace('latest', '0.13.5'); + data['version'] = '0.13.5'; break; case /7\.2/.test(data['php_version']): - data['version'] = data['version'].replace('latest', '0.14.5'); + data['version'] = '0.14.5'; break; } if (data['version'] === 'latest') { - data['domain'] = data['domain'] + '/releases'; - } else { - data['domain'] = [ - data['github'], - data['repository'], - 'releases/download', - data['version'] - ].join('/'); + data['version'] = await getLatestVersion(data); } + data['domain'] = [ + data['github'], + data['repository'], + 'releases/download', + data['version'] + ].join('/'); data['url'] = await getPharUrl(data); return await addArchive(data); }