Scope binary tools installed using composer

This commit is contained in:
Shivam Mathur 2021-12-31 00:03:15 +05:30
parent 7789b4e03e
commit f24f33ea89
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
9 changed files with 134 additions and 65 deletions

View File

@ -10,6 +10,7 @@ interface IData {
php_version?: string; php_version?: string;
release?: string; release?: string;
repository?: string; repository?: string;
scope?: string;
type?: string; type?: string;
fetch_latest?: string; fetch_latest?: string;
version_parameter?: string; version_parameter?: string;
@ -26,6 +27,7 @@ function getData(data: IData): Record<string, string> {
php_version: data.php_version || '7.4', php_version: data.php_version || '7.4',
release: data.release || [data.tool, data.version].join(':'), release: data.release || [data.tool, data.version].join(':'),
repository: data.repository || '', repository: data.repository || '',
scope: data.scope || 'global',
type: data.type || 'phar', type: data.type || 'phar',
fetch_latest: data.fetch_latest || 'false', fetch_latest: data.fetch_latest || 'false',
version_parameter: data.version_parameter || '-V', version_parameter: data.version_parameter || '-V',
@ -209,21 +211,25 @@ describe('Tools tests', () => {
}); });
it.each` it.each`
os_version | script os_version | script | scope
${'linux'} | ${'add_composertool tool tool:1.2.3 user/'} ${'linux'} | ${'add_composertool tool tool:1.2.3 user/ global'} | ${'global'}
${'darwin'} | ${'add_composertool tool tool:1.2.3 user/'} ${'darwin'} | ${'add_composertool tool tool:1.2.3 user/ scoped'} | ${'scoped'}
${'win32'} | ${'Add-Composertool tool tool:1.2.3 user/'} ${'win32'} | ${'Add-Composertool tool tool:1.2.3 user/ scoped'} | ${'scoped'}
${'openbsd'} | ${'Platform openbsd is not supported'} ${'openbsd'} | ${'Platform openbsd is not supported'} | ${'global'}
`('checking addPackage: $os_version', async ({os_version, script}) => { `(
const data = getData({ 'checking addPackage: $os_version, $scope',
tool: 'tool', async ({os_version, script, scope}) => {
version: '1.2.3', const data = getData({
repository: 'user/tool', tool: 'tool',
os_version: os_version version: '1.2.3',
}); repository: 'user/tool',
data['release'] = [data['tool'], data['version']].join(':'); os_version: os_version,
expect(await tools.addPackage(data)).toContain(script); scope: scope
}); });
data['release'] = [data['tool'], data['version']].join(':');
expect(await tools.addPackage(data)).toContain(script);
}
);
it.each` it.each`
version | php_version | os_version | script version | php_version | os_version | script
@ -378,7 +384,7 @@ describe('Tools tests', () => {
'add_blackfire', 'add_blackfire',
'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player "-V"', 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player "-V"',
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"', 'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"',
'add_composertool flex flex symfony/', 'add_composertool flex flex symfony/ global',
'add_grpc_php_plugin latest', 'add_grpc_php_plugin latest',
'add_tool https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/latest/download/parallel-lint.phar parallel-lint "--version"', 'add_tool https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/latest/download/parallel-lint.phar parallel-lint "--version"',
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.2.1/php-cs-fixer.phar php-cs-fixer "-V"', 'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.2.1/php-cs-fixer.phar php-cs-fixer "-V"',
@ -388,16 +394,16 @@ describe('Tools tests', () => {
'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"', 'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"',
'add_pecl', 'add_pecl',
'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"', 'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"',
'add_composertool phinx phinx robmorgan/', 'add_composertool phinx phinx robmorgan/ scoped',
'add_composertool phinx phinx:1.2.3 robmorgan/', 'add_composertool phinx phinx:1.2.3 robmorgan/ scoped',
'add_tool https://github.com/phar-io/phive/releases/download/3.2.1/phive-3.2.1.phar phive "status"', 'add_tool https://github.com/phar-io/phive/releases/download/3.2.1/phive-3.2.1.phar phive "status"',
'add_composertool phpunit-bridge phpunit-bridge symfony/', 'add_composertool phpunit-bridge phpunit-bridge symfony/ global',
'add_composertool phpunit-polyfills phpunit-polyfills yoast/', 'add_composertool phpunit-polyfills phpunit-polyfills yoast/ global',
'add_devtools php-config', 'add_devtools php-config',
'add_devtools phpize', 'add_devtools phpize',
'add_protoc latest', 'add_protoc latest',
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony-cli "version"', 'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony-cli "version"',
'add_composertool vapor-cli vapor-cli laravel/', 'add_composertool vapor-cli vapor-cli laravel/ scoped',
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"' 'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
] ]
] ]
@ -413,20 +419,20 @@ describe('Tools tests', () => {
'behat, blackfire, blackfire-player, composer-normalize, composer-require-checker, composer-unused, cs2pr:1.2.3, flex, grpc_php_plugin:1.2.3, infection, phan, phan:1.2.3, phing:1.2.3, phinx, phive:1.2.3, php-config, phpcbf, phpcpd, phpcs, phpdoc, phpize, phpmd, phpspec, phpunit-bridge:5.6, phpunit-polyfills:1.0.1, protoc:v1.2.3, psalm, symfony-cli, symfony:1.2.3, vapor-cli, wp-cli', 'behat, blackfire, blackfire-player, composer-normalize, composer-require-checker, composer-unused, cs2pr:1.2.3, flex, grpc_php_plugin:1.2.3, infection, phan, phan:1.2.3, phing:1.2.3, phinx, phive:1.2.3, php-config, phpcbf, phpcpd, phpcs, phpdoc, phpize, phpmd, phpspec, phpunit-bridge:5.6, phpunit-polyfills:1.0.1, protoc:v1.2.3, psalm, symfony-cli, symfony:1.2.3, vapor-cli, wp-cli',
[ [
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer', 'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer',
'add_composertool behat behat behat/', 'add_composertool behat behat behat/ scoped',
'add_blackfire', 'add_blackfire',
'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player "-V"', 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player "-V"',
'add_tool https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar composer-normalize "-V"', 'add_tool https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar composer-normalize "-V"',
'add_composertool composer-require-checker composer-require-checker maglnet/', 'add_composertool composer-require-checker composer-require-checker maglnet/ scoped',
'add_composertool composer-unused composer-unused icanhazstring/', 'add_composertool composer-unused composer-unused icanhazstring/ scoped',
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr "-V"', 'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr "-V"',
'add_composertool flex flex symfony/', 'add_composertool flex flex symfony/ global',
'add_grpc_php_plugin 1.2.3', 'add_grpc_php_plugin 1.2.3',
'add_tool https://github.com/infection/infection/releases/latest/download/infection.phar infection "-V"', 'add_tool https://github.com/infection/infection/releases/latest/download/infection.phar infection "-V"',
'add_tool https://github.com/phan/phan/releases/latest/download/phan.phar phan "-v"', 'add_tool https://github.com/phan/phan/releases/latest/download/phan.phar phan "-v"',
'add_tool https://github.com/phan/phan/releases/download/1.2.3/phan.phar phan "-v"', 'add_tool https://github.com/phan/phan/releases/download/1.2.3/phan.phar phan "-v"',
'add_tool https://www.phing.info/get/phing-1.2.3.phar phing "-v"', 'add_tool https://www.phing.info/get/phing-1.2.3.phar phing "-v"',
'add_composertool phinx phinx robmorgan/', 'add_composertool phinx phinx robmorgan/ scoped',
'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive', 'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive',
'add_devtools php-config', 'add_devtools php-config',
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf "--version"', 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf "--version"',
@ -436,13 +442,13 @@ describe('Tools tests', () => {
'add_devtools phpize', 'add_devtools phpize',
'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"', 'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"',
'add_tool https://github.com/phpspec/phpspec/releases/latest/download/phpspec.phar phpspec "-V"', 'add_tool https://github.com/phpspec/phpspec/releases/latest/download/phpspec.phar phpspec "-V"',
'add_composertool phpunit-bridge phpunit-bridge:5.6.* symfony/', 'add_composertool phpunit-bridge phpunit-bridge:5.6.* symfony/ global',
'add_composertool phpunit-polyfills phpunit-polyfills:1.0.1 yoast/', 'add_composertool phpunit-polyfills phpunit-polyfills:1.0.1 yoast/ global',
'add_protoc 1.2.3', 'add_protoc 1.2.3',
'add_tool https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm "-v"', 'add_tool https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm "-v"',
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony-cli "version"', 'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony-cli "version"',
'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony-cli "version"', 'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony-cli "version"',
'add_composertool vapor-cli vapor-cli laravel/', 'add_composertool vapor-cli vapor-cli laravel/ scoped',
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"' 'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
] ]
] ]
@ -463,13 +469,13 @@ describe('Tools tests', () => {
'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"', 'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"',
'Add-Tool https://deployer.org/deployer.phar deployer "-V"', 'Add-Tool https://deployer.org/deployer.phar deployer "-V"',
'Tool does_not_exist is not supported', 'Tool does_not_exist is not supported',
'Add-Composertool flex flex symfony/', 'Add-Composertool flex flex symfony/ global',
'Add-Composertool phinx phinx robmorgan/', 'Add-Composertool phinx phinx robmorgan/ scoped',
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive "status"', 'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive "status"',
'php-config is not a windows tool', 'php-config is not a windows tool',
'phpize is not a windows tool', 'phpize is not a windows tool',
'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"', 'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"',
'Add-Composertool phpunit-bridge phpunit-bridge symfony/', 'Add-Composertool phpunit-bridge phpunit-bridge symfony/ global',
'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony-cli "version"', 'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony-cli "version"',
'Add-Tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"' 'Add-Tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
] ]
@ -486,13 +492,13 @@ describe('Tools tests', () => {
'composer:v1, codeception/codeception, prestissimo, hirak/prestissimo, composer-prefetcher, narrowspark/automatic-composer-prefetcher, phinx: 1.2, robmorgan/phinx: ^1.2, user/tool:1.2.3, user/tool:~1.2', 'composer:v1, codeception/codeception, prestissimo, hirak/prestissimo, composer-prefetcher, narrowspark/automatic-composer-prefetcher, phinx: 1.2, robmorgan/phinx: ^1.2, user/tool:1.2.3, user/tool:~1.2',
[ [
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-1.phar,https://getcomposer.org/composer-1.phar composer', 'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-1.phar,https://getcomposer.org/composer-1.phar composer',
'Add-Composertool codeception codeception codeception/', 'Add-Composertool codeception codeception codeception/ global',
'Add-Composertool prestissimo prestissimo hirak/', 'Add-Composertool prestissimo prestissimo hirak/ global',
'Add-Composertool automatic-composer-prefetcher automatic-composer-prefetcher narrowspark/', 'Add-Composertool automatic-composer-prefetcher automatic-composer-prefetcher narrowspark/ global',
'Add-Composertool phinx phinx:1.2.* robmorgan/', 'Add-Composertool phinx phinx:1.2.* robmorgan/ scoped',
'Add-Composertool phinx phinx:^1.2 robmorgan/', 'Add-Composertool phinx phinx:^1.2 robmorgan/ global',
'Add-Composertool tool tool:1.2.3 user/', 'Add-Composertool tool tool:1.2.3 user/ global',
'Add-Composertool tool tool:~1.2 user/' 'Add-Composertool tool tool:~1.2 user/ global'
] ]
] ]
])( ])(

8
dist/index.js vendored
View File

@ -650,7 +650,8 @@ exports.addArchive = addArchive;
async function addPackage(data) { async function addPackage(data) {
const command = await utils.getCommand(data['os_version'], 'composertool'); const command = await utils.getCommand(data['os_version'], 'composertool');
const parts = data['repository'].split('/'); const parts = data['repository'].split('/');
return command + parts[1] + ' ' + data['release'] + ' ' + parts[0] + '/'; const args = await utils.joins(parts[1], data['release'], parts[0] + '/', data['scope']);
return command + args;
} }
exports.addPackage = addPackage; exports.addPackage = addPackage;
async function addBlackfirePlayer(data) { async function addBlackfirePlayer(data) {
@ -782,7 +783,7 @@ async function addWPCLI(data) {
} }
exports.addWPCLI = addWPCLI; exports.addWPCLI = addWPCLI;
async function getData(release, php_version, os_version) { async function getData(release, php_version, os_version) {
var _a, _b, _c, _d; var _a, _b, _c, _d, _e;
const json_file = await utils.readFile('tools.json', 'src/configs'); const json_file = await utils.readFile('tools.json', 'src/configs');
const json_objects = JSON.parse(json_file); const json_objects = JSON.parse(json_file);
release = release.replace(/\s+/g, ''); release = release.replace(/\s+/g, '');
@ -819,8 +820,9 @@ async function getData(release, php_version, os_version) {
data['prefix'] = data['github'] === data['domain'] ? 'releases' : ''; data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
data['verb'] = data['github'] === data['domain'] ? 'download' : ''; data['verb'] = data['github'] === data['domain'] ? 'download' : '';
(_c = data['fetch_latest']) !== null && _c !== void 0 ? _c : (data['fetch_latest'] = 'false'); (_c = data['fetch_latest']) !== null && _c !== void 0 ? _c : (data['fetch_latest'] = 'false');
(_d = data['scope']) !== null && _d !== void 0 ? _d : (data['scope'] = 'global');
data['version_parameter'] = JSON.stringify(data['version_parameter']) || ''; data['version_parameter'] = JSON.stringify(data['version_parameter']) || '';
(_d = data['version_prefix']) !== null && _d !== void 0 ? _d : (data['version_prefix'] = ''); (_e = data['version_prefix']) !== null && _e !== void 0 ? _e : (data['version_prefix'] = '');
data['release'] = await getRelease(release, data); data['release'] = await getRelease(release, data);
data['version'] = version data['version'] = version
? await getVersion(version, data) ? await getVersion(version, data)

View File

@ -107,54 +107,66 @@
}, },
"behat": { "behat": {
"type": "composer", "type": "composer",
"repository": "behat/behat" "repository": "behat/behat",
"scope": "scoped"
}, },
"codeception": { "codeception": {
"type": "composer", "type": "composer",
"repository": "codeception/codeception" "repository": "codeception/codeception",
"scope": "scoped"
}, },
"automatic-composer-prefetcher": { "automatic-composer-prefetcher": {
"type": "composer", "type": "composer",
"alias": "composer-prefetcher", "alias": "composer-prefetcher",
"repository": "narrowspark/automatic-composer-prefetcher" "repository": "narrowspark/automatic-composer-prefetcher",
"scope": "global"
}, },
"composer-require-checker": { "composer-require-checker": {
"type": "composer", "type": "composer",
"repository": "maglnet/composer-require-checker" "repository": "maglnet/composer-require-checker",
"scope": "scoped"
}, },
"composer-unused": { "composer-unused": {
"type": "composer", "type": "composer",
"repository": "icanhazstring/composer-unused" "repository": "icanhazstring/composer-unused",
"scope": "scoped"
}, },
"flex": { "flex": {
"type": "composer", "type": "composer",
"repository": "symfony/flex" "repository": "symfony/flex",
"scope": "global"
}, },
"phinx": { "phinx": {
"type": "composer", "type": "composer",
"repository": "robmorgan/phinx" "repository": "robmorgan/phinx",
"scope": "scoped"
}, },
"phplint": { "phplint": {
"type": "composer", "type": "composer",
"repository": "overtrue/phplint" "repository": "overtrue/phplint",
"scope": "scoped"
}, },
"phpunit-bridge": { "phpunit-bridge": {
"alias": "simple-phpunit", "alias": "simple-phpunit",
"type": "composer", "type": "composer",
"repository": "symfony/phpunit-bridge" "repository": "symfony/phpunit-bridge",
"scope": "global"
}, },
"phpunit-polyfills": { "phpunit-polyfills": {
"type": "composer", "type": "composer",
"repository": "yoast/phpunit-polyfills" "repository": "yoast/phpunit-polyfills",
"scope": "global"
}, },
"prestissimo": { "prestissimo": {
"type": "composer", "type": "composer",
"repository": "hirak/prestissimo" "repository": "hirak/prestissimo",
"scope": "global"
}, },
"vapor-cli": { "vapor-cli": {
"type": "composer", "type": "composer",
"alias": "vapor", "alias": "vapor",
"repository": "laravel/vapor-cli" "repository": "laravel/vapor-cli",
"scope": "scoped"
}, },
"blackfire": { "blackfire": {
"type": "custom-package", "type": "custom-package",

View File

@ -13,6 +13,7 @@
"fetch_latest": "true", "fetch_latest": "true",
"function": "function_name", "function": "function_name",
"repository": "user/tool", "repository": "user/tool",
"scope": "global, scoped",
"type": "phar, composer, custom-package or custom-function", "type": "phar, composer, custom-package or custom-function",
"version_parameter": "--version", "version_parameter": "--version",
"version_prefix": "v" "version_prefix": "v"
@ -76,6 +77,16 @@
"user/tool" "user/tool"
] ]
}, },
"scope": {
"$id": "#/items/properties/scope",
"type": "string",
"title": "The scope schema",
"description": "Scope of tool installation: global or scoped",
"enum": [
"global",
"scoped"
]
},
"type": { "type": {
"$id": "#/items/properties/type", "$id": "#/items/properties/type",
"type": "string", "type": "string",

View File

@ -331,6 +331,7 @@ add_composertool() {
tool=$1 tool=$1
release=$2 release=$2
prefix=$3 prefix=$3
scope=$4
if [[ "$tool" =~ prestissimo|composer-prefetcher ]]; then if [[ "$tool" =~ prestissimo|composer-prefetcher ]]; then
composer_version=$(cat /tmp/composer_version) composer_version=$(cat /tmp/composer_version)
if [ "$(echo "$composer_version" | cut -d'.' -f 1)" != "1" ]; then if [ "$(echo "$composer_version" | cut -d'.' -f 1)" != "1" ]; then
@ -340,8 +341,19 @@ add_composertool() {
fi fi
fi fi
( (
sudo rm -f "$composer_lock" >/dev/null 2>&1 || true if [ "$scope" = "global" ]; then
composer global require "$prefix$release" 2>&1 | tee /tmp/composer.log >/dev/null 2>&1 sudo rm -f "$composer_lock" >/dev/null 2>&1 || true
composer global require "$prefix$release" 2>&1 | tee /tmp/composer.log >/dev/null 2>&1
else
scoped_dir="$composer_bin/_tools/$tool-$(echo -n "$release" | shasum -a 256 | cut -d ' ' -f 1)"
if ! [ -e "$scoped_dir" ]; then
mkdir -p "$scoped_dir"
composer require "$prefix$release" -d "$scoped_dir" 2>&1 | tee /tmp/composer.log >/dev/null 2>&1
export PATH=$PATH:"$scoped_dir"/vendor/bin
echo "${tool}"_bin="$scoped_dir"/vendor/bin | sudo tee -a "$GITHUB_ENV" >/dev/null
echo "$scoped_dir"/vendor/bin >>"$GITHUB_PATH"
fi
fi
log=$(grep "$prefix$tool" /tmp/composer.log) && log=$(grep "$prefix$tool" /tmp/composer.log) &&
tool_version=$(get_tool_version 'echo' "$log") && tool_version=$(get_tool_version 'echo' "$log") &&
add_log "$tick" "$tool" "Added $tool $tool_version" add_log "$tick" "$tool" "Added $tool $tool_version"

View File

@ -5,7 +5,7 @@ Function Add-ToolsHelper() {
$tool $tool
) )
if($tool -eq "codeception") { if($tool -eq "codeception") {
Copy-Item $composer_bin\codecept.bat -Destination $composer_bin\codeception.bat Copy-Item $codeception_bin\codecept.bat -Destination $codeception_bin\codeception.bat
} elseif($tool -eq "composer") { } elseif($tool -eq "composer") {
Edit-ComposerConfig $bin_dir\$tool Edit-ComposerConfig $bin_dir\$tool
} elseif($tool -eq "cs2pr") { } elseif($tool -eq "cs2pr") {
@ -22,7 +22,7 @@ Function Add-ToolsHelper() {
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\symfony-cli.exe" Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\symfony-cli.exe"
Add-ToProfile $current_profile "symfony_cli" "New-Alias symfony-cli $bin_dir\symfony-cli.exe" Add-ToProfile $current_profile "symfony_cli" "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
} elseif($tool -match "vapor-cli") { } elseif($tool -match "vapor-cli") {
Copy-Item $composer_bin\vapor.bat -Destination $composer_bin\vapor-cli.bat Copy-Item $vapor_cli_bin\vapor.bat -Destination $vapor_cli_bin\vapor-cli.bat
} 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
} }

View File

@ -1,7 +1,8 @@
add_tools_helper() { add_tools_helper() {
tool=$1 tool=$1
if [ "$tool" = "codeception" ]; then if [ "$tool" = "codeception" ]; then
sudo ln -s "${composer_bin:?}"/codecept "${composer_bin:?}"/codeception codeception_bin=$(grep codeception_bin "${GITHUB_ENV:?}" | cut -d '=' -f 2)
sudo ln -s "${codeception_bin:?}"/codecept "${codeception_bin:?}"/codeception
elif [ "$tool" = "composer" ]; then elif [ "$tool" = "composer" ]; then
configure_composer "${tool_path:?}" configure_composer "${tool_path:?}"
elif [ "$tool" = "cs2pr" ]; then elif [ "$tool" = "cs2pr" ]; then

View File

@ -423,18 +423,36 @@ Function Add-Composertool() {
[ValidateNotNull()] [ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)] [ValidateLength(1, [int]::MaxValue)]
[string] [string]
$prefix $prefix,
[Parameter(Position = 3, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$scope
) )
if($tool -match "prestissimo|composer-prefetcher" -and $composer_version.split('.')[0] -ne "1") { if($tool -match "prestissimo|composer-prefetcher" -and $composer_version.split('.')[0] -ne "1") {
Write-Output "::warning:: Skipping $tool, as it does not support Composer $composer_version. Specify composer:v1 in tools to use $tool" Write-Output "::warning:: Skipping $tool, as it does not support Composer $composer_version. Specify composer:v1 in tools to use $tool"
Add-Log $cross $tool "Skipped" Add-Log $cross $tool "Skipped"
Return Return
} }
if(Test-Path $composer_lock) { if($scope -eq 'global') {
Remove-Item -Path $composer_lock -Force if(Test-Path $composer_lock) {
Remove-Item -Path $composer_lock -Force
}
(composer global require $prefix$release 2>&1 | Tee-Object -FilePath $env:APPDATA\Composer\composer.log) >$null 2>&1
$json = findstr $prefix$tool $env:APPDATA\Composer\composer.json
} else {
$release_stream = [System.IO.MemoryStream]::New([System.Text.Encoding]::ASCII.GetBytes($release))
$scoped_tool_dir_suffix = (Get-FileHash -InputStream $release_stream -Algorithm sha256).Hash
$scoped_tool_dir = "$composer_bin\_tools\$tool-$scoped_tool_dir_suffix"
if(-not(Test-Path $scoped_tool_dir)) {
New-Item -ItemType Directory -Force -Path $scoped_tool_dir > $null 2>&1
(composer global require $prefix$release -d $scoped_tool_dir.replace('\', '/') 2>&1 | Tee-Object -FilePath $env:APPDATA\Composer\composer.log) >$null 2>&1
Add-Content $scoped_tool_dir\vendor\bin -Path $env:GITHUB_PATH -Encoding utf8
New-Variable -Name ($tool.replace('-', '_') + '_bin') -Value $scoped_tool_dir\vendor\bin
}
$json = (Test-Path $scoped_tool_dir\composer.json) -and (findstr $prefix$tool $scoped_tool_dir\composer.json)
} }
(composer global require $prefix$release 2>&1 | Tee-Object -FilePath $env:APPDATA\Composer\composer.log) >$null 2>&1
$json = findstr $prefix$tool $env:APPDATA\Composer\composer.json
$log = findstr $prefix$tool $env:APPDATA\Composer\composer.log $log = findstr $prefix$tool $env:APPDATA\Composer\composer.log
if(Test-Path $composer_bin\composer) { if(Test-Path $composer_bin\composer) {
Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force

View File

@ -193,7 +193,13 @@ export async function addArchive(data: RS): Promise<string> {
export async function addPackage(data: RS): Promise<string> { export async function addPackage(data: RS): Promise<string> {
const command = await utils.getCommand(data['os_version'], 'composertool'); const command = await utils.getCommand(data['os_version'], 'composertool');
const parts: string[] = data['repository'].split('/'); const parts: string[] = data['repository'].split('/');
return command + parts[1] + ' ' + data['release'] + ' ' + parts[0] + '/'; const args: string = await utils.joins(
parts[1],
data['release'],
parts[0] + '/',
data['scope']
);
return command + args;
} }
/** /**
@ -443,6 +449,7 @@ export async function getData(
data['prefix'] = data['github'] === data['domain'] ? 'releases' : ''; data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
data['verb'] = data['github'] === data['domain'] ? 'download' : ''; data['verb'] = data['github'] === data['domain'] ? 'download' : '';
data['fetch_latest'] ??= 'false'; data['fetch_latest'] ??= 'false';
data['scope'] ??= 'global';
data['version_parameter'] = JSON.stringify(data['version_parameter']) || ''; data['version_parameter'] = JSON.stringify(data['version_parameter']) || '';
data['version_prefix'] ??= ''; data['version_prefix'] ??= '';
data['release'] = await getRelease(release, data); data['release'] = await getRelease(release, data);