mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 11:51:07 +07:00
Improve composer setup
This commit is contained in:
parent
e763fddf01
commit
a3d5500a6a
1
.github/workflows/main-workflow.yml
vendored
1
.github/workflows/main-workflow.yml
vendored
@ -1,5 +1,6 @@
|
||||
name: Main workflow
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
branches:
|
||||
- releases/v1
|
||||
|
@ -1,5 +1,21 @@
|
||||
import * as httpm from '@actions/http-client';
|
||||
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', () => {
|
||||
it('checking getCommand', async () => {
|
||||
expect(await tools.getCommand('linux', 'tool')).toBe('add_tool ');
|
||||
@ -263,20 +279,24 @@ describe('Tools tests', () => {
|
||||
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
|
||||
});
|
||||
|
||||
it('checking updateComposer', async () => {
|
||||
expect(await tools.updateComposer('latest', 'linux')).toContain('');
|
||||
expect(await tools.updateComposer('stable', 'win32')).toContain('');
|
||||
expect(await tools.updateComposer('snapshot', 'darwin')).toContain(
|
||||
'\ncomposer self-update --snapshot'
|
||||
it('checking getComposerUrl', async () => {
|
||||
expect(await tools.getComposerUrl('latest')).toContain(
|
||||
'https://getcomposer.org/composer-stable.phar'
|
||||
);
|
||||
expect(await tools.updateComposer('preview', 'linux')).toContain(
|
||||
'\ncomposer self-update --preview'
|
||||
expect(await tools.getComposerUrl('stable')).toContain(
|
||||
'https://getcomposer.org/composer-stable.phar'
|
||||
);
|
||||
expect(await tools.updateComposer('1', 'win32')).toContain(
|
||||
'\ncomposer self-update --1'
|
||||
expect(await tools.getComposerUrl('snapshot')).toContain(
|
||||
'https://getcomposer.org/composer.phar'
|
||||
);
|
||||
expect(await tools.updateComposer('2', 'darwin')).toContain(
|
||||
'\ncomposer self-update --2'
|
||||
expect(await tools.getComposerUrl('preview')).toContain(
|
||||
'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'
|
||||
);
|
||||
});
|
||||
|
||||
@ -527,17 +547,20 @@ describe('Tools tests', () => {
|
||||
'linux'
|
||||
);
|
||||
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');
|
||||
expect(script).toContain('composer self-update --preview');
|
||||
expect(script).toContain(
|
||||
'add_tool https://getcomposer.org/composer-preview.phar composer'
|
||||
);
|
||||
script = await tools.addTools(
|
||||
'composer:v1, composer:preview, composer:snapshot',
|
||||
'7.4',
|
||||
'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/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": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz",
|
||||
@ -970,9 +978,9 @@
|
||||
}
|
||||
},
|
||||
"@types/babel__traverse": {
|
||||
"version": "7.0.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.12.tgz",
|
||||
"integrity": "sha512-t4CoEokHTfcyfb4hUaF9oOHu9RmmNWnm1CP0YmMqOOfClKascOmvlEM736vlqeScuGvBDsHkf8R2INd4DWreQA==",
|
||||
"version": "7.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.13.tgz",
|
||||
"integrity": "sha512-i+zS7t6/s9cdQvbqKDARrcbrPvtJGlbYsMkazo03nTAK3RX9FNrLllXys22uiTGJapPOTZTQ35nHh4ISph4SLQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/types": "^7.3.0"
|
||||
@ -1025,9 +1033,9 @@
|
||||
}
|
||||
},
|
||||
"@types/jest": {
|
||||
"version": "26.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.3.tgz",
|
||||
"integrity": "sha512-v89ga1clpVL/Y1+YI0eIu1VMW+KU7Xl8PhylVtDKVWaSUHBHYPLXMQGBdrpHewaKoTvlXkksbYqPgz8b4cmRZg==",
|
||||
"version": "26.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.4.tgz",
|
||||
"integrity": "sha512-4fQNItvelbNA9+sFgU+fhJo8ZFF+AS4Egk3GWwCW2jFtViukXbnztccafAdLhzE/0EiCogljtQQXP8aQ9J7sFg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"jest-diff": "^25.2.1",
|
||||
@ -1047,9 +1055,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "14.0.14",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.14.tgz",
|
||||
"integrity": "sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ==",
|
||||
"version": "14.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.18.tgz",
|
||||
"integrity": "sha512-0Z3nS5acM0cIV4JPzrj9g/GH0Et5vmADWtip3YOXOp1NpOLU8V3KoZDc8ny9c1pe/YSYYzQkAWob6dyV/EWg4g==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/normalize-package-data": {
|
||||
@ -1065,9 +1073,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/prettier": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.0.1.tgz",
|
||||
"integrity": "sha512-boy4xPNEtiw6N3abRhBi/e7hNvy3Tt8E9ZRAQrwAGzoCGZS/1wjo9KY7JHhnfnEsG5wSjDbymCozUM9a3ea7OQ==",
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.0.2.tgz",
|
||||
"integrity": "sha512-IkVfat549ggtkZUthUzEX49562eGikhSYeVGX97SkMFn+sTZrgRewXjQ4tPKFPCykZHkX1Zfd9OoELGqKU2jJA==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/stack-utils": {
|
||||
@ -6713,6 +6721,11 @@
|
||||
"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": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
|
||||
|
@ -26,6 +26,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.4",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/http-client": "^1.0.8",
|
||||
"@actions/io": "^1.0.2",
|
||||
"fs": "0.0.1-security"
|
||||
},
|
||||
|
@ -105,7 +105,23 @@ add_unstable_extension() {
|
||||
add_pecl_extension "$extension" "$pecl_version" "$prefix"
|
||||
}
|
||||
|
||||
# Function to setup a remote tool
|
||||
# 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
|
||||
}
|
||||
|
||||
# Function to setup a remote tool.
|
||||
add_tool() {
|
||||
url=$1
|
||||
tool=$2
|
||||
@ -118,11 +134,10 @@ add_tool() {
|
||||
if [ "$status_code" = "200" ]; then
|
||||
sudo chmod a+x "$tool_path"
|
||||
if [ "$tool" = "composer" ]; then
|
||||
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
|
||||
configure_composer "$tool_path"
|
||||
elif [ "$tool" = "phan" ]; then
|
||||
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
|
||||
elif [ "$tool" = "phive" ]; then
|
||||
add_extension curl "sudo pecl install -f curl" extension >/dev/null 2>&1
|
||||
add_extension mbstring "sudo pecl install -f mbstring" extension >/dev/null 2>&1
|
||||
|
@ -16,6 +16,16 @@ add_log() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to backup and cleanup package lists.
|
||||
cleanup_lists() {
|
||||
if [ ! -e /etc/apt/sources.list.d.save ]; then
|
||||
sudo mv /etc/apt/sources.list.d /etc/apt/sources.list.d.save
|
||||
sudo mkdir /etc/apt/sources.list.d
|
||||
sudo mv /etc/apt/sources.list.d.save/*ondrej*.list /etc/apt/sources.list.d/
|
||||
trap "sudo mv /etc/apt/sources.list.d.save/*.list /etc/apt/sources.list.d/" exit
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to update php ppa
|
||||
update_lists() {
|
||||
if [ "$lists_updated" = "false" ]; then
|
||||
@ -140,7 +150,23 @@ update_extension() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to setup a remote tool
|
||||
# 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
|
||||
}
|
||||
|
||||
# Function to setup a remote tool.
|
||||
add_tool() {
|
||||
url=$1
|
||||
tool=$2
|
||||
@ -152,11 +178,7 @@ add_tool() {
|
||||
if [ "$status_code" = "200" ]; then
|
||||
sudo chmod a+x "$tool_path"
|
||||
if [ "$tool" = "composer" ]; then
|
||||
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
|
||||
configure_composer "$tool_path"
|
||||
elif [ "$tool" = "cs2pr" ]; then
|
||||
sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path"
|
||||
elif [ "$tool" = "phive" ]; then
|
||||
|
@ -109,6 +109,32 @@ 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 Add-Tool() {
|
||||
Param (
|
||||
[Parameter(Position = 0, Mandatory = $true)]
|
||||
@ -147,11 +173,9 @@ Function Add-Tool() {
|
||||
} elseif($tool -eq "cs2pr") {
|
||||
(Get-Content $php_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $php_dir/cs2pr
|
||||
} elseif($tool -eq "composer") {
|
||||
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
|
||||
}
|
||||
Edit-ComposerConfig $php_dir\$tool
|
||||
} elseif($tool -eq "wp-cli") {
|
||||
Copy-Item $php_dir\wp-cli.bat -Destination $php_dir\wp.bat
|
||||
}
|
||||
|
||||
if (((Get-ChildItem -Path $php_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
|
||||
|
33
src/tools.ts
33
src/tools.ts
@ -1,4 +1,6 @@
|
||||
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
|
||||
@ -298,27 +300,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 os_version
|
||||
*/
|
||||
export async function updateComposer(
|
||||
version: string,
|
||||
os_version: string
|
||||
): Promise<string> {
|
||||
export async function getComposerUrl(version: string): Promise<string> {
|
||||
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'];
|
||||
};
|
||||
switch (version) {
|
||||
case 'snapshot':
|
||||
return 'https://getcomposer.org/composer.phar';
|
||||
case 'preview':
|
||||
case '1':
|
||||
case '2':
|
||||
return (
|
||||
'\ncomposer self-update --' +
|
||||
version +
|
||||
(await utils.suppressOutput(os_version))
|
||||
);
|
||||
return await getComposerUrlHelper(version);
|
||||
default:
|
||||
return '';
|
||||
return 'https://getcomposer.org/composer-stable.phar';
|
||||
}
|
||||
}
|
||||
|
||||
@ -473,10 +476,8 @@ export async function addTools(
|
||||
script += await addArchive(tool, version, url, os_version);
|
||||
break;
|
||||
case 'composer':
|
||||
url = 'https://getcomposer.org/composer-stable.phar';
|
||||
script +=
|
||||
(await addArchive('composer', version, url, os_version)) +
|
||||
(await updateComposer(version, os_version));
|
||||
url = await getComposerUrl(version);
|
||||
script += await addArchive('composer', version, url, os_version);
|
||||
break;
|
||||
case 'codeception':
|
||||
url =
|
||||
|
Loading…
Reference in New Issue
Block a user