From 9d6b61c5af801dd3642ba6b53eeb8667b09d92cc Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Tue, 21 Jan 2020 01:40:24 +0530 Subject: [PATCH] Add support for phive --- __tests__/tools.test.ts | 30 +++++++++++++++++++++++++++--- dist/index.js | 28 ++++++++++++++++++++++++++++ src/scripts/darwin.sh | 5 +++++ src/scripts/linux.sh | 5 +++++ src/scripts/win32.ps1 | 5 +++++ src/tools.ts | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 3 deletions(-) diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 4ccf9658..dfb632a0 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -160,6 +160,18 @@ describe('Tools tests', () => { ); }); + it('checking addPhive', async () => { + let script: string = await tools.addPhive('1.2.3', 'linux'); + expect(script).toContain( + 'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive' + ); + + script = await tools.addPhive('latest', 'win32'); + expect(script).toContain( + 'Add-Tool https://phar.io/releases/phive.phar phive' + ); + }); + it('checking getPhpunitUri', async () => { expect(await tools.getPhpunitUrl('tool', 'latest')).toBe( 'https://phar.phpunit.de/tool.phar' @@ -289,7 +301,7 @@ describe('Tools tests', () => { it('checking addTools on linux', async () => { const script: string = await tools.addTools( - 'php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, php-config, phpize', + 'php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize', '7.4', 'linux' ); @@ -302,6 +314,9 @@ describe('Tools tests', () => { expect(script).toContain( 'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan' ); + expect(script).toContain( + 'add_tool https://phar.io/releases/phive.phar phive' + ); expect(script).toContain( 'add_tool https://phar.phpunit.de/phpunit.phar phpunit' ); @@ -314,7 +329,7 @@ describe('Tools tests', () => { }); it('checking addTools on darwin', async () => { const script: string = await tools.addTools( - 'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, composer-prefetcher:1.2.3, phpize, php-config', + 'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, composer-prefetcher:1.2.3, phpize, php-config', '7.4', 'darwin' ); @@ -337,6 +352,9 @@ describe('Tools tests', () => { 'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm' ); expect(script).toContain('add_composer_tool phinx phinx robmorgan/'); + expect(script).toContain( + 'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive' + ); expect(script).toContain( 'add_composer_tool composer-prefetcher composer-prefetcher:1.2.3 narrowspark/automatic-' ); @@ -345,7 +363,7 @@ describe('Tools tests', () => { }); it('checking addTools on windows', async () => { const script: string = await tools.addTools( - 'codeception, deployer, prestissimo, phpmd, phinx, php-config, phpize, does_not_exit', + 'codeception, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, does_not_exit', '7.4', 'win32' ); @@ -358,7 +376,13 @@ describe('Tools tests', () => { expect(script).toContain( 'Add-Composer-Tool prestissimo prestissimo hirak/' ); + expect(script).toContain( + 'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd' + ); expect(script).toContain('Add-Composer-Tool phinx phinx robmorgan/'); + expect(script).toContain( + 'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive' + ); expect(script).toContain('phpize is not a windows tool'); expect(script).toContain('php-config is not a windows tool'); expect(script).toContain('Tool does_not_exit is not supported'); diff --git a/dist/index.js b/dist/index.js index 60003b76..b35cd40e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1731,6 +1731,31 @@ function getCodeceptionUri(version, php_version) { }); } exports.getCodeceptionUri = getCodeceptionUri; +/** + * Helper function to get script to setup phive + * + * @param tool + * @param version + * @param url + * @param os_version + */ +function addPhive(version, os_version) { + return __awaiter(this, void 0, void 0, function* () { + switch (version) { + case 'latest': + return ((yield getArchiveCommand(os_version)) + + 'https://phar.io/releases/phive.phar phive'); + default: + return ((yield getArchiveCommand(os_version)) + + 'https://github.com/phar-io/phive/releases/download/' + + version + + '/phive-' + + version + + '.phar phive'); + } + }); +} +exports.addPhive = addPhive; /** * Function to get the PHPUnit url * @@ -1888,6 +1913,9 @@ function addTools(tools_csv, php_version, os_version) { url = github + 'squizlabs/PHP_CodeSniffer/' + uri; script += yield addArchive(tool, version, url, os_version); break; + case 'phive': + script += yield addPhive(version, os_version); + break; case 'phpstan': url = github + 'phpstan/phpstan/' + uri; script += yield addArchive(tool, version, url, os_version); diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 37e94238..c584da3a 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -67,6 +67,11 @@ add_tool() { add_log "$cross" "$tool" "Could not setup $tool" fi fi + if [ "$tool" = "phive" ]; then + add_extension curl >/dev/null 2>&1 + add_extension mbstring >/dev/null 2>&1 + add_extension xml >/dev/null 2>&1 + fi } add_composer_tool() { diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index 89ea04be..fe2d2815 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -83,6 +83,11 @@ add_tool() { if [ "$tool" = "composer" ]; then composer -q global config process-timeout 0 fi + if [ "$tool" = "phive" ]; then + add_extension curl >/dev/null 2>&1 + add_extension mbstring >/dev/null 2>&1 + add_extension xml >/dev/null 2>&1 + fi } add_composer_tool() { diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index e3b3f289..19772ade 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -115,6 +115,11 @@ Function Add-Tool() { Add-Log $cross $tool "Could not add $tool" } } + if($tool -eq "phive") { + Add-Extension curl >$null 2>&1 + Add-Extension mbstring >$null 2>&1 + Add-Extension xml >$null 2>&1 + } } Function Add-Composer-Tool() { diff --git a/src/tools.ts b/src/tools.ts index d88e285c..3a60f5f6 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -180,6 +180,36 @@ export async function getCodeceptionUri( } } +/** + * Helper function to get script to setup phive + * + * @param tool + * @param version + * @param url + * @param os_version + */ +export async function addPhive( + version: string, + os_version: string +): Promise { + switch (version) { + case 'latest': + return ( + (await getArchiveCommand(os_version)) + + 'https://phar.io/releases/phive.phar phive' + ); + default: + return ( + (await getArchiveCommand(os_version)) + + 'https://github.com/phar-io/phive/releases/download/' + + version + + '/phive-' + + version + + '.phar phive' + ); + } +} + /** * Function to get the PHPUnit url * @@ -354,6 +384,9 @@ export async function addTools( url = github + 'squizlabs/PHP_CodeSniffer/' + uri; script += await addArchive(tool, version, url, os_version); break; + case 'phive': + script += await addPhive(version, os_version); + break; case 'phpstan': url = github + 'phpstan/phpstan/' + uri; script += await addArchive(tool, version, url, os_version);