Merge pull request #266 from shivammathur/develop

Hotfix
This commit is contained in:
Shivam Mathur 2020-08-04 22:00:38 +05:30 committed by GitHub
commit 2a44b78bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 20 deletions

View File

@ -424,7 +424,7 @@ describe('Tools tests', () => {
'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player' 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player'
); );
expect(script).toContain( 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( expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr' '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' 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player'
); );
expect(script).toContain( 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( expect(script).toContain(
'add_tool https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar composer-normalize' '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' 'Add-Tool https://get.blackfire.io/blackfire-player-v1.8.1.phar blackfire-player'
); );
expect(script).toContain( 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( expect(script).toContain(
'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr' '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( 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 prestissimo prestissimo hirak/');
expect(script).toContain('Add-Composertool phinx phinx robmorgan/'); expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
@ -649,12 +649,12 @@ describe('Tools tests', () => {
); );
expect(script).toContain( 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'); script = await tools.addTools('composer:preview', '7.4', 'linux');
expect(script).toContain( 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( script = await tools.addTools(
'composer:v1, composer:preview, composer:snapshot', 'composer:v1, composer:preview, composer:snapshot',
@ -662,7 +662,7 @@ describe('Tools tests', () => {
'linux' 'linux'
); );
expect(script).toContain( 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
View File

@ -2229,21 +2229,24 @@ exports.addComposer = addComposer;
* @param version * @param version
*/ */
async function getComposerUrl(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 getComposerUrlHelper = async function (version) {
const client = new httpm.HttpClient('setup-php'); const client = new httpm.HttpClient('setup-php');
const response = await client.get('https://getcomposer.org/versions'); const response = await client.get('https://getcomposer.org/versions');
const data = JSON.parse(await response.readBody()); 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) { switch (version) {
case 'snapshot': case 'snapshot':
return 'https://getcomposer.org/composer.phar'; return cache_url + 'https://getcomposer.org/composer.phar';
case 'preview': case 'preview':
case '1': case '1':
case '2': case '2':
return await getComposerUrlHelper(version); return await getComposerUrlHelper(version);
default: default:
return 'https://getcomposer.org/composer-stable.phar'; return cache_url + 'https://getcomposer.org/composer-stable.phar';
} }
} }
exports.getComposerUrl = getComposerUrl; exports.getComposerUrl = getComposerUrl;

View File

@ -167,7 +167,13 @@ add_tool() {
rm -rf "$tool_path" rm -rf "$tool_path"
fi 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") status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
fi
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
@ -235,7 +241,7 @@ version=$1
nodot_version=${1/./} nodot_version=${1/./}
old_versions="5.[3-5]" old_versions="5.[3-5]"
tool_path_dir="/usr/local/bin" tool_path_dir="/usr/local/bin"
curl_opts=(-sSL --retry 5 --retry-delay 1) curl_opts=(-sSL --retry 5)
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3) existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
read_env read_env

View File

@ -261,7 +261,13 @@ add_tool() {
if [ ! -e "$tool_path" ]; then if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path" rm -rf "$tool_path"
fi 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") status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
fi
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
@ -392,7 +398,7 @@ debconf_fix="DEBIAN_FRONTEND=noninteractive"
github="https://github.com/shivammathur" github="https://github.com/shivammathur"
apt_install="sudo $debconf_fix apt-fast install -y" apt_install="sudo $debconf_fix apt-fast install -y"
tool_path_dir="/usr/local/bin" tool_path_dir="/usr/local/bin"
curl_opts=(-sSL --retry 5 --retry-delay 1) curl_opts=(-sSL --retry 5)
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3) existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
read_env read_env

View File

@ -19,7 +19,7 @@ add_protoc() {
[ "$(uname -s)" = "Darwin" ] && platform='osx' [ "$(uname -s)" = "Darwin" ] && platform='osx'
curl -o /tmp/protobuf.zip "${curl_opts[@]:?}" "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-${protobuf_tag:1}-$platform-x86_64.zip" curl -o /tmp/protobuf.zip "${curl_opts[@]:?}" "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-${protobuf_tag:1}-$platform-x86_64.zip"
sudo unzip /tmp/protobuf.zip -d /usr/local/ sudo unzip /tmp/protobuf.zip -d /usr/local/
sudo chmod a+x /usr/local/bin/protoc sudo chmod 777 /usr/local/bin/protoc -R /usr/local/include/google
) >/dev/null 2>&1 ) >/dev/null 2>&1
add_log "${tick:?}" "protoc" "Added" add_log "${tick:?}" "protoc" "Added"
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "protoc" "Click to read the protoc related license information" printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "protoc" "Click to read the protoc related license information"

View File

@ -187,8 +187,6 @@ Function Add-Tool() {
Param ( Param (
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()] [ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$url, $url,
[Parameter(Position = 1, Mandatory = $true)] [Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNull()] [ValidateNotNull()]
@ -199,6 +197,7 @@ Function Add-Tool() {
if (Test-Path $bin_dir\$tool) { if (Test-Path $bin_dir\$tool) {
Remove-Item $bin_dir\$tool Remove-Item $bin_dir\$tool
} }
if($url.Count -gt 1) { $url = $url[0] }
if ($tool -eq "symfony") { if ($tool -eq "symfony") {
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $bin_dir\$tool.exe 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 Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.exe" >$null 2>&1

View File

@ -329,23 +329,27 @@ export async function addComposer(tools_list: string[]): Promise<string[]> {
* @param version * @param version
*/ */
export async function getComposerUrl(version: string): Promise<string> { 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 ( const getComposerUrlHelper = async function (
version: string version: string
): Promise<string> { ): Promise<string> {
const client: httpm.HttpClient = new httpm.HttpClient('setup-php'); const client: httpm.HttpClient = new httpm.HttpClient('setup-php');
const response: hcr = await client.get('https://getcomposer.org/versions'); const response: hcr = await client.get('https://getcomposer.org/versions');
const data = JSON.parse(await response.readBody()); 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) { switch (version) {
case 'snapshot': case 'snapshot':
return 'https://getcomposer.org/composer.phar'; return cache_url + 'https://getcomposer.org/composer.phar';
case 'preview': case 'preview':
case '1': case '1':
case '2': case '2':
return await getComposerUrlHelper(version); return await getComposerUrlHelper(version);
default: default:
return 'https://getcomposer.org/composer-stable.phar'; return cache_url + 'https://getcomposer.org/composer-stable.phar';
} }
} }