mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-23 04:11:06 +07:00
Use cached composer builds
This commit is contained in:
parent
9dae796baf
commit
91bd6b26c2
@ -424,7 +424,7 @@ describe('Tools tests', () => {
|
||||
'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player'
|
||||
);
|
||||
expect(script).toContain(
|
||||
'add_tool https://getcomposer.org/composer-stable.phar composer'
|
||||
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer'
|
||||
);
|
||||
expect(script).toContain(
|
||||
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
|
||||
@ -499,7 +499,7 @@ describe('Tools tests', () => {
|
||||
'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player'
|
||||
);
|
||||
expect(script).toContain(
|
||||
'add_tool https://getcomposer.org/composer-stable.phar composer'
|
||||
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer'
|
||||
);
|
||||
expect(script).toContain(
|
||||
'add_tool https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar composer-normalize'
|
||||
@ -590,7 +590,7 @@ describe('Tools tests', () => {
|
||||
'Add-Tool https://get.blackfire.io/blackfire-player-v1.8.1.phar blackfire-player'
|
||||
);
|
||||
expect(script).toContain(
|
||||
'Add-Tool https://getcomposer.org/composer-stable.phar composer'
|
||||
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer'
|
||||
);
|
||||
expect(script).toContain(
|
||||
'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
|
||||
@ -631,7 +631,7 @@ describe('Tools tests', () => {
|
||||
);
|
||||
|
||||
expect(script).toContain(
|
||||
'Add-Tool https://getcomposer.org/composer-stable.phar composer'
|
||||
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer'
|
||||
);
|
||||
expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/');
|
||||
expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
|
||||
@ -649,12 +649,12 @@ describe('Tools tests', () => {
|
||||
);
|
||||
|
||||
expect(script).toContain(
|
||||
'add_tool https://getcomposer.org/composer-1.phar composer'
|
||||
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar,https://getcomposer.org/composer-1.phar composer'
|
||||
);
|
||||
|
||||
script = await tools.addTools('composer:preview', '7.4', 'linux');
|
||||
expect(script).toContain(
|
||||
'add_tool https://getcomposer.org/composer-preview.phar composer'
|
||||
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-preview.phar,https://getcomposer.org/composer-preview.phar composer'
|
||||
);
|
||||
script = await tools.addTools(
|
||||
'composer:v1, composer:preview, composer:snapshot',
|
||||
@ -662,7 +662,7 @@ describe('Tools tests', () => {
|
||||
'linux'
|
||||
);
|
||||
expect(script).toContain(
|
||||
'add_tool https://getcomposer.org/composer.phar composer'
|
||||
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-snapshot.phar,https://getcomposer.org/composer.phar composer'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
9
dist/index.js
vendored
9
dist/index.js
vendored
@ -2229,21 +2229,24 @@ exports.addComposer = addComposer;
|
||||
* @param version
|
||||
*/
|
||||
async function getComposerUrl(version) {
|
||||
const cache_url = 'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-' +
|
||||
version.replace('latest', 'stable') +
|
||||
'.phar,';
|
||||
const getComposerUrlHelper = async function (version) {
|
||||
const client = new httpm.HttpClient('setup-php');
|
||||
const response = await client.get('https://getcomposer.org/versions');
|
||||
const data = JSON.parse(await response.readBody());
|
||||
return 'https://getcomposer.org' + data[version][0]['path'];
|
||||
return cache_url + 'https://getcomposer.org' + data[version][0]['path'];
|
||||
};
|
||||
switch (version) {
|
||||
case 'snapshot':
|
||||
return 'https://getcomposer.org/composer.phar';
|
||||
return cache_url + 'https://getcomposer.org/composer.phar';
|
||||
case 'preview':
|
||||
case '1':
|
||||
case '2':
|
||||
return await getComposerUrlHelper(version);
|
||||
default:
|
||||
return 'https://getcomposer.org/composer-stable.phar';
|
||||
return cache_url + 'https://getcomposer.org/composer-stable.phar';
|
||||
}
|
||||
}
|
||||
exports.getComposerUrl = getComposerUrl;
|
||||
|
@ -167,7 +167,13 @@ add_tool() {
|
||||
rm -rf "$tool_path"
|
||||
fi
|
||||
|
||||
if [ "$tool" = "composer" ]; then
|
||||
IFS="," read -r -a urls <<< "$url"
|
||||
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[0]}") ||
|
||||
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[1]}")
|
||||
else
|
||||
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
|
||||
fi
|
||||
if [ "$status_code" = "200" ]; then
|
||||
sudo chmod a+x "$tool_path"
|
||||
if [ "$tool" = "composer" ]; then
|
||||
|
@ -261,7 +261,13 @@ add_tool() {
|
||||
if [ ! -e "$tool_path" ]; then
|
||||
rm -rf "$tool_path"
|
||||
fi
|
||||
if [ "$tool" = "composer" ]; then
|
||||
IFS="," read -r -a urls <<< "$url"
|
||||
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[0]}") ||
|
||||
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[1]}")
|
||||
else
|
||||
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
|
||||
fi
|
||||
if [ "$status_code" = "200" ]; then
|
||||
sudo chmod a+x "$tool_path"
|
||||
if [ "$tool" = "composer" ]; then
|
||||
|
@ -187,8 +187,6 @@ Function Add-Tool() {
|
||||
Param (
|
||||
[Parameter(Position = 0, Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[ValidateLength(1, [int]::MaxValue)]
|
||||
[string]
|
||||
$url,
|
||||
[Parameter(Position = 1, Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
@ -199,6 +197,7 @@ Function Add-Tool() {
|
||||
if (Test-Path $bin_dir\$tool) {
|
||||
Remove-Item $bin_dir\$tool
|
||||
}
|
||||
if($url.Count -gt 1) { $url = $url[0] }
|
||||
if ($tool -eq "symfony") {
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $bin_dir\$tool.exe
|
||||
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.exe" >$null 2>&1
|
||||
|
10
src/tools.ts
10
src/tools.ts
@ -329,23 +329,27 @@ export async function addComposer(tools_list: string[]): Promise<string[]> {
|
||||
* @param version
|
||||
*/
|
||||
export async function getComposerUrl(version: string): Promise<string> {
|
||||
const cache_url =
|
||||
'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-' +
|
||||
version.replace('latest', 'stable') +
|
||||
'.phar,';
|
||||
const getComposerUrlHelper = async function (
|
||||
version: 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'];
|
||||
return cache_url + 'https://getcomposer.org' + data[version][0]['path'];
|
||||
};
|
||||
switch (version) {
|
||||
case 'snapshot':
|
||||
return 'https://getcomposer.org/composer.phar';
|
||||
return cache_url + 'https://getcomposer.org/composer.phar';
|
||||
case 'preview':
|
||||
case '1':
|
||||
case '2':
|
||||
return await getComposerUrlHelper(version);
|
||||
default:
|
||||
return 'https://getcomposer.org/composer-stable.phar';
|
||||
return cache_url + 'https://getcomposer.org/composer-stable.phar';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user