mirror of
				https://github.com/shivammathur/setup-php.git
				synced 2025-10-31 07:16:22 +07:00 
			
		
		
		
	Improve composer setup
This commit is contained in:
		
							
								
								
									
										1
									
								
								.github/workflows/workflow.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.github/workflows/workflow.yml
									
									
									
									
										vendored
									
									
								
							| @ -1,5 +1,6 @@ | |||||||
| name: Main workflow | name: Main workflow | ||||||
| on: | on: | ||||||
|  |   workflow_dispatch: | ||||||
|   pull_request: |   pull_request: | ||||||
|     branches: |     branches: | ||||||
|       - master |       - master | ||||||
|  | |||||||
| @ -1,5 +1,21 @@ | |||||||
|  | import * as httpm from '@actions/http-client'; | ||||||
| import * as tools from '../src/tools'; | import * as tools from '../src/tools'; | ||||||
|  |  | ||||||
|  | httpm.HttpClient.prototype.get = jest.fn().mockImplementation(() => { | ||||||
|  |   return { | ||||||
|  |     message: null, | ||||||
|  |     readBody: jest.fn().mockImplementation(() => { | ||||||
|  |       return JSON.stringify({ | ||||||
|  |         stable: [{path: '/composer-stable.phar'}], | ||||||
|  |         preview: [{path: '/composer-preview.phar'}], | ||||||
|  |         snapshot: [{path: '/composer.phar'}], | ||||||
|  |         '1': [{path: '/composer-1.phar'}], | ||||||
|  |         '2': [{path: '/composer-2.phar'}] | ||||||
|  |       }); | ||||||
|  |     }) | ||||||
|  |   }; | ||||||
|  | }); | ||||||
|  |  | ||||||
| describe('Tools tests', () => { | describe('Tools tests', () => { | ||||||
|   it('checking getCommand', async () => { |   it('checking getCommand', async () => { | ||||||
|     expect(await tools.getCommand('linux', 'tool')).toBe('add_tool '); |     expect(await tools.getCommand('linux', 'tool')).toBe('add_tool '); | ||||||
| @ -239,20 +255,24 @@ describe('Tools tests', () => { | |||||||
|     ).toStrictEqual(['composer:2', 'a', 'b', 'c']); |     ).toStrictEqual(['composer:2', 'a', 'b', 'c']); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   it('checking updateComposer', async () => { |   it('checking getComposerUrl', async () => { | ||||||
|     expect(await tools.updateComposer('latest', 'linux')).toContain(''); |     expect(await tools.getComposerUrl('latest')).toContain( | ||||||
|     expect(await tools.updateComposer('stable', 'win32')).toContain(''); |       'https://getcomposer.org/composer-stable.phar' | ||||||
|     expect(await tools.updateComposer('snapshot', 'darwin')).toContain( |  | ||||||
|       '\ncomposer self-update --snapshot' |  | ||||||
|     ); |     ); | ||||||
|     expect(await tools.updateComposer('preview', 'linux')).toContain( |     expect(await tools.getComposerUrl('stable')).toContain( | ||||||
|       '\ncomposer self-update --preview' |       'https://getcomposer.org/composer-stable.phar' | ||||||
|     ); |     ); | ||||||
|     expect(await tools.updateComposer('1', 'win32')).toContain( |     expect(await tools.getComposerUrl('snapshot')).toContain( | ||||||
|       '\ncomposer self-update --1' |       'https://getcomposer.org/composer.phar' | ||||||
|     ); |     ); | ||||||
|     expect(await tools.updateComposer('2', 'darwin')).toContain( |     expect(await tools.getComposerUrl('preview')).toContain( | ||||||
|       '\ncomposer self-update --2' |       'https://getcomposer.org/composer-preview.phar' | ||||||
|  |     ); | ||||||
|  |     expect(await tools.getComposerUrl('1')).toContain( | ||||||
|  |       'https://getcomposer.org/composer-1.phar' | ||||||
|  |     ); | ||||||
|  |     expect(await tools.getComposerUrl('2')).toContain( | ||||||
|  |       'https://getcomposer.org/composer-2.phar' | ||||||
|     ); |     ); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
| @ -547,17 +567,20 @@ describe('Tools tests', () => { | |||||||
|       'linux' |       'linux' | ||||||
|     ); |     ); | ||||||
|     expect(script).toContain( |     expect(script).toContain( | ||||||
|       'add_tool https://getcomposer.org/composer-stable.phar composer' |       'add_tool https://getcomposer.org/composer-1.phar composer' | ||||||
|     ); |     ); | ||||||
|     expect(script).toContain('composer self-update --1'); |  | ||||||
|  |  | ||||||
|     script = await tools.addTools('composer:preview', '7.4', 'linux'); |     script = await tools.addTools('composer:preview', '7.4', 'linux'); | ||||||
|     expect(script).toContain('composer self-update --preview'); |     expect(script).toContain( | ||||||
|  |       'add_tool https://getcomposer.org/composer-preview.phar composer' | ||||||
|  |     ); | ||||||
|     script = await tools.addTools( |     script = await tools.addTools( | ||||||
|       'composer:v1, composer:preview, composer:snapshot', |       'composer:v1, composer:preview, composer:snapshot', | ||||||
|       '7.4', |       '7.4', | ||||||
|       'linux' |       'linux' | ||||||
|     ); |     ); | ||||||
|     expect(script).toContain('composer self-update --snapshot'); |     expect(script).toContain( | ||||||
|  |       'add_tool https://getcomposer.org/composer.phar composer' | ||||||
|  |     ); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  | |||||||
							
								
								
									
										949
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										949
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										37
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										37
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -17,6 +17,14 @@ | |||||||
|         "@actions/io": "^1.0.1" |         "@actions/io": "^1.0.1" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  |     "@actions/http-client": { | ||||||
|  |       "version": "1.0.8", | ||||||
|  |       "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz", | ||||||
|  |       "integrity": "sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==", | ||||||
|  |       "requires": { | ||||||
|  |         "tunnel": "0.0.6" | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     "@actions/io": { |     "@actions/io": { | ||||||
|       "version": "1.0.2", |       "version": "1.0.2", | ||||||
|       "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz", |       "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz", | ||||||
| @ -970,9 +978,9 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "@types/babel__traverse": { |     "@types/babel__traverse": { | ||||||
|       "version": "7.0.12", |       "version": "7.0.13", | ||||||
|       "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.12.tgz", |       "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.13.tgz", | ||||||
|       "integrity": "sha512-t4CoEokHTfcyfb4hUaF9oOHu9RmmNWnm1CP0YmMqOOfClKascOmvlEM736vlqeScuGvBDsHkf8R2INd4DWreQA==", |       "integrity": "sha512-i+zS7t6/s9cdQvbqKDARrcbrPvtJGlbYsMkazo03nTAK3RX9FNrLllXys22uiTGJapPOTZTQ35nHh4ISph4SLQ==", | ||||||
|       "dev": true, |       "dev": true, | ||||||
|       "requires": { |       "requires": { | ||||||
|         "@babel/types": "^7.3.0" |         "@babel/types": "^7.3.0" | ||||||
| @ -1025,9 +1033,9 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "@types/jest": { |     "@types/jest": { | ||||||
|       "version": "26.0.3", |       "version": "26.0.4", | ||||||
|       "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.3.tgz", |       "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.4.tgz", | ||||||
|       "integrity": "sha512-v89ga1clpVL/Y1+YI0eIu1VMW+KU7Xl8PhylVtDKVWaSUHBHYPLXMQGBdrpHewaKoTvlXkksbYqPgz8b4cmRZg==", |       "integrity": "sha512-4fQNItvelbNA9+sFgU+fhJo8ZFF+AS4Egk3GWwCW2jFtViukXbnztccafAdLhzE/0EiCogljtQQXP8aQ9J7sFg==", | ||||||
|       "dev": true, |       "dev": true, | ||||||
|       "requires": { |       "requires": { | ||||||
|         "jest-diff": "^25.2.1", |         "jest-diff": "^25.2.1", | ||||||
| @ -1047,9 +1055,9 @@ | |||||||
|       "dev": true |       "dev": true | ||||||
|     }, |     }, | ||||||
|     "@types/node": { |     "@types/node": { | ||||||
|       "version": "14.0.14", |       "version": "14.0.18", | ||||||
|       "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.14.tgz", |       "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.18.tgz", | ||||||
|       "integrity": "sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ==", |       "integrity": "sha512-0Z3nS5acM0cIV4JPzrj9g/GH0Et5vmADWtip3YOXOp1NpOLU8V3KoZDc8ny9c1pe/YSYYzQkAWob6dyV/EWg4g==", | ||||||
|       "dev": true |       "dev": true | ||||||
|     }, |     }, | ||||||
|     "@types/normalize-package-data": { |     "@types/normalize-package-data": { | ||||||
| @ -1065,9 +1073,9 @@ | |||||||
|       "dev": true |       "dev": true | ||||||
|     }, |     }, | ||||||
|     "@types/prettier": { |     "@types/prettier": { | ||||||
|       "version": "2.0.1", |       "version": "2.0.2", | ||||||
|       "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.0.1.tgz", |       "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.0.2.tgz", | ||||||
|       "integrity": "sha512-boy4xPNEtiw6N3abRhBi/e7hNvy3Tt8E9ZRAQrwAGzoCGZS/1wjo9KY7JHhnfnEsG5wSjDbymCozUM9a3ea7OQ==", |       "integrity": "sha512-IkVfat549ggtkZUthUzEX49562eGikhSYeVGX97SkMFn+sTZrgRewXjQ4tPKFPCykZHkX1Zfd9OoELGqKU2jJA==", | ||||||
|       "dev": true |       "dev": true | ||||||
|     }, |     }, | ||||||
|     "@types/stack-utils": { |     "@types/stack-utils": { | ||||||
| @ -6713,6 +6721,11 @@ | |||||||
|         "tslib": "^1.8.1" |         "tslib": "^1.8.1" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  |     "tunnel": { | ||||||
|  |       "version": "0.0.6", | ||||||
|  |       "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", | ||||||
|  |       "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" | ||||||
|  |     }, | ||||||
|     "tunnel-agent": { |     "tunnel-agent": { | ||||||
|       "version": "0.6.0", |       "version": "0.6.0", | ||||||
|       "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", |       "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", | ||||||
|  | |||||||
| @ -26,6 +26,7 @@ | |||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "@actions/core": "^1.2.4", |     "@actions/core": "^1.2.4", | ||||||
|     "@actions/exec": "^1.0.4", |     "@actions/exec": "^1.0.4", | ||||||
|  |     "@actions/http-client": "^1.0.8", | ||||||
|     "@actions/io": "^1.0.2", |     "@actions/io": "^1.0.2", | ||||||
|     "fs": "0.0.1-security" |     "fs": "0.0.1-security" | ||||||
|   }, |   }, | ||||||
|  | |||||||
| @ -127,6 +127,26 @@ add_unstable_extension() { | |||||||
|   add_pecl_extension "$extension" "$pecl_version" "$prefix" |   add_pecl_extension "$extension" "$pecl_version" "$prefix" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # Function to configure composer | ||||||
|  | configure_composer() { | ||||||
|  |   tool_path=$1 | ||||||
|  |   sudo ln -sf "$tool_path" "$tool_path.phar" | ||||||
|  |   php -r "try {\$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception \$e) {exit(1);}" | ||||||
|  |   if [ $? -eq 1 ]; then | ||||||
|  |     add_log "$cross" "composer" "Could not download composer" | ||||||
|  |     exit 1; | ||||||
|  |   fi | ||||||
|  |   composer -q global config process-timeout 0 | ||||||
|  |   echo "::add-path::/Users/$USER/.composer/vendor/bin" | ||||||
|  |   if [ -n "$COMPOSER_TOKEN" ]; then | ||||||
|  |     composer -q global config github-oauth.github.com "$COMPOSER_TOKEN" | ||||||
|  |   fi | ||||||
|  |   # TODO: Remove after composer 2.0 update, fixes peer fingerprint error | ||||||
|  |   if [[ "$version" =~ $old_versions ]]; then | ||||||
|  |     composer -q global config repos.packagist composer https://repo-ca-bhs-1.packagist.org | ||||||
|  |   fi | ||||||
|  | } | ||||||
|  |  | ||||||
| # Function to setup a remote tool. | # Function to setup a remote tool. | ||||||
| add_tool() { | add_tool() { | ||||||
|   url=$1 |   url=$1 | ||||||
| @ -140,15 +160,7 @@ add_tool() { | |||||||
|   if [ "$status_code" = "200" ]; then |   if [ "$status_code" = "200" ]; then | ||||||
|     sudo chmod a+x "$tool_path" |     sudo chmod a+x "$tool_path" | ||||||
|     if [ "$tool" = "composer" ]; then |     if [ "$tool" = "composer" ]; then | ||||||
|       composer -q global config process-timeout 0 |       configure_composer "$tool_path" | ||||||
|       echo "::add-path::/Users/$USER/.composer/vendor/bin" |  | ||||||
|       if [ -n "$COMPOSER_TOKEN" ]; then |  | ||||||
|         composer -q global config github-oauth.github.com "$COMPOSER_TOKEN" |  | ||||||
|       fi |  | ||||||
|       # TODO: Remove after composer 2.0 update, fixes peer fingerprint error |  | ||||||
|       if [[ "$version" =~ $old_versions ]]; then |  | ||||||
|         composer -q global config repos.packagist composer https://repo-ca-bhs-1.packagist.org |  | ||||||
|       fi |  | ||||||
|     elif [ "$tool" = "phan" ]; then |     elif [ "$tool" = "phan" ]; then | ||||||
|       add_extension fileinfo "sudo pecl install -f fileinfo" extension >/dev/null 2>&1 |       add_extension fileinfo "sudo pecl install -f fileinfo" extension >/dev/null 2>&1 | ||||||
|       add_extension ast "sudo pecl install -f ast" extension >/dev/null 2>&1 |       add_extension ast "sudo pecl install -f ast" extension >/dev/null 2>&1 | ||||||
|  | |||||||
| @ -228,6 +228,26 @@ add_extension_from_source() { | |||||||
|   ) || add_log "$cross" "$extension" "Could not install $extension-$release on PHP $semver" |   ) || add_log "$cross" "$extension" "Could not install $extension-$release on PHP $semver" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # Function to configure composer | ||||||
|  | configure_composer() { | ||||||
|  |   tool_path=$1 | ||||||
|  |   sudo ln -sf "$tool_path" "$tool_path.phar" | ||||||
|  |   php -r "try {\$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception \$e) {exit(1);}" | ||||||
|  |   if [ $? -eq 1 ]; then | ||||||
|  |     add_log "$cross" "composer" "Could not download composer" | ||||||
|  |     exit 1; | ||||||
|  |   fi | ||||||
|  |   composer -q global config process-timeout 0 | ||||||
|  |   echo "::add-path::/home/$USER/.composer/vendor/bin" | ||||||
|  |   if [ -n "$COMPOSER_TOKEN" ]; then | ||||||
|  |     composer -q global config github-oauth.github.com "$COMPOSER_TOKEN" | ||||||
|  |   fi | ||||||
|  |   # TODO: Remove after composer 2.0 update, fixes peer fingerprint error | ||||||
|  |   if [[ "$version" =~ $old_versions ]]; then | ||||||
|  |     composer -q global config repos.packagist composer https://repo-ca-bhs-1.packagist.org | ||||||
|  |   fi | ||||||
|  | } | ||||||
|  |  | ||||||
| # Function to setup a remote tool. | # Function to setup a remote tool. | ||||||
| add_tool() { | add_tool() { | ||||||
|   url=$1 |   url=$1 | ||||||
| @ -240,15 +260,7 @@ add_tool() { | |||||||
|   if [ "$status_code" = "200" ]; then |   if [ "$status_code" = "200" ]; then | ||||||
|     sudo chmod a+x "$tool_path" |     sudo chmod a+x "$tool_path" | ||||||
|     if [ "$tool" = "composer" ]; then |     if [ "$tool" = "composer" ]; then | ||||||
|       composer -q global config process-timeout 0 |       configure_composer "$tool_path" | ||||||
|       echo "::add-path::/home/$USER/.composer/vendor/bin" |  | ||||||
|       if [ -n "$COMPOSER_TOKEN" ]; then |  | ||||||
|         composer -q global config github-oauth.github.com "$COMPOSER_TOKEN" |  | ||||||
|       fi |  | ||||||
|       # TODO: Remove after composer 2.0 update, fixes peer fingerprint error |  | ||||||
|       if [[ "$version" =~ $old_versions ]]; then |  | ||||||
|         composer -q global config repos.packagist composer https://repo-ca-bhs-1.packagist.org |  | ||||||
|       fi |  | ||||||
|     elif [ "$tool" = "cs2pr" ]; then |     elif [ "$tool" = "cs2pr" ]; then | ||||||
|       sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path" |       sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path" | ||||||
|     elif [ "$tool" = "phan" ]; then |     elif [ "$tool" = "phan" ]; then | ||||||
|  | |||||||
| @ -161,6 +161,31 @@ Function Remove-Extension() { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | Function Edit-ComposerConfig() { | ||||||
|  |   Param( | ||||||
|  |     [Parameter(Position = 0, Mandatory = $true)] | ||||||
|  |     [ValidateNotNull()] | ||||||
|  |     [ValidateLength(1, [int]::MaxValue)] | ||||||
|  |     [string] | ||||||
|  |     $tool_path | ||||||
|  |   ) | ||||||
|  |   Copy-Item $tool_path -Destination "$tool_path.phar" | ||||||
|  |   php -r "try {`$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception `$e) {exit(1);}" | ||||||
|  |   if ($? -eq $False) { | ||||||
|  |     Add-Log "$cross" "composer" "Could not download composer" | ||||||
|  |     exit 1; | ||||||
|  |   } | ||||||
|  |   composer -q global config process-timeout 0 | ||||||
|  |   Write-Output "::add-path::$env:APPDATA\Composer\vendor\bin" | ||||||
|  |   if (Test-Path env:COMPOSER_TOKEN) { | ||||||
|  |     composer -q global config github-oauth.github.com $env:COMPOSER_TOKEN | ||||||
|  |   } | ||||||
|  |   # TODO: Remove after composer 2.0 update, fixes peer fingerprint error | ||||||
|  |   if ($version -lt 5.6) { | ||||||
|  |     composer -q global config repos.packagist composer https://repo-ca-bhs-1.packagist.org | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| # Function to add tools. | # Function to add tools. | ||||||
| Function Add-Tool() { | Function Add-Tool() { | ||||||
|   Param ( |   Param ( | ||||||
| @ -201,15 +226,7 @@ Function Add-Tool() { | |||||||
|   } elseif($tool -eq "cs2pr") { |   } elseif($tool -eq "cs2pr") { | ||||||
|     (Get-Content $bin_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $bin_dir/cs2pr |     (Get-Content $bin_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $bin_dir/cs2pr | ||||||
|   } elseif($tool -eq "composer") { |   } elseif($tool -eq "composer") { | ||||||
|     composer -q global config process-timeout 0 |     Edit-ComposerConfig $bin_dir\$tool | ||||||
|     Write-Output "::add-path::$env:APPDATA\Composer\vendor\bin" |  | ||||||
|     if (Test-Path env:COMPOSER_TOKEN) { |  | ||||||
|       composer -q global config github-oauth.github.com $env:COMPOSER_TOKEN |  | ||||||
|     } |  | ||||||
|     # TODO: Remove after composer 2.0 update, fixes peer fingerprint error |  | ||||||
|     if ($version -lt 5.6) { |  | ||||||
|       composer -q global config repos.packagist composer https://repo-ca-bhs-1.packagist.org |  | ||||||
|     } |  | ||||||
|   } elseif($tool -eq "wp-cli") { |   } elseif($tool -eq "wp-cli") { | ||||||
|     Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat |     Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat | ||||||
|   } |   } | ||||||
|  | |||||||
							
								
								
									
										33
									
								
								src/tools.ts
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								src/tools.ts
									
									
									
									
									
								
							| @ -1,4 +1,6 @@ | |||||||
| import * as utils from './utils'; | import * as utils from './utils'; | ||||||
|  | import * as httpm from '@actions/http-client'; | ||||||
|  | import {IHttpClientResponse as hcr} from '@actions/http-client/interfaces'; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Function to get command to setup tools |  * Function to get command to setup tools | ||||||
| @ -319,27 +321,28 @@ export async function addComposer(tools_list: string[]): Promise<string[]> { | |||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Function to get script to update composer |  * Function to get composer URL for a given version | ||||||
|  * |  * | ||||||
|  * @param version |  * @param version | ||||||
|  * @param os_version |  | ||||||
|  */ |  */ | ||||||
| export async function updateComposer( | export async function getComposerUrl(version: string): Promise<string> { | ||||||
|   version: string, |   const getComposerUrlHelper = async function ( | ||||||
|   os_version: string |     version: string | ||||||
| ): Promise<string> { |   ): Promise<string> { | ||||||
|  |     const client: httpm.HttpClient = new httpm.HttpClient('setup-php'); | ||||||
|  |     const response: hcr = await client.get('https://getcomposer.org/versions'); | ||||||
|  |     const data = JSON.parse(await response.readBody()); | ||||||
|  |     return 'https://getcomposer.org' + data[version][0]['path']; | ||||||
|  |   }; | ||||||
|   switch (version) { |   switch (version) { | ||||||
|     case 'snapshot': |     case 'snapshot': | ||||||
|  |       return 'https://getcomposer.org/composer.phar'; | ||||||
|     case 'preview': |     case 'preview': | ||||||
|     case '1': |     case '1': | ||||||
|     case '2': |     case '2': | ||||||
|       return ( |       return await getComposerUrlHelper(version); | ||||||
|         '\ncomposer self-update --' + |  | ||||||
|         version + |  | ||||||
|         (await utils.suppressOutput(os_version)) |  | ||||||
|       ); |  | ||||||
|     default: |     default: | ||||||
|       return ''; |       return 'https://getcomposer.org/composer-stable.phar'; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -513,10 +516,8 @@ export async function addTools( | |||||||
|         script += await addArchive(tool, version, url, os_version); |         script += await addArchive(tool, version, url, os_version); | ||||||
|         break; |         break; | ||||||
|       case 'composer': |       case 'composer': | ||||||
|         url = 'https://getcomposer.org/composer-stable.phar'; |         url = await getComposerUrl(version); | ||||||
|         script += |         script += await addArchive('composer', version, url, os_version); | ||||||
|           (await addArchive('composer', version, url, os_version)) + |  | ||||||
|           (await updateComposer(version, os_version)); |  | ||||||
|         break; |         break; | ||||||
|       case 'codeception': |       case 'codeception': | ||||||
|         url = |         url = | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Shivam Mathur
					Shivam Mathur