Add mago tool support as custom package

Co-authored-by: shivammathur <1571086+shivammathur@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-07-17 10:57:30 +00:00
parent 8d11cf02d2
commit 26dc9b4fed
4 changed files with 83 additions and 3 deletions

View File

@ -393,7 +393,7 @@ describe('Tools tests', () => {
it.each([
[
'blackfire, blackfire-player, box, churn, cs2pr, flex, grpc_php_plugin, name-collision-detector, parallel-lint, php-cs-fixer, php-scoper, phpDocumentor, phplint, phpstan, phpunit, pecl, phing, phinx, phinx:1.2.3, phive, phpunit-bridge, phpunit-polyfills, pint, php-config, phpize, protoc, symfony, vapor, wp, pie',
'blackfire, blackfire-player, box, churn, cs2pr, flex, grpc_php_plugin, mago, name-collision-detector, parallel-lint, php-cs-fixer, php-scoper, phpDocumentor, phplint, phpstan, phpunit, pecl, phing, phinx, phinx:1.2.3, phive, phpunit-bridge, phpunit-polyfills, pint, php-config, phpize, protoc, symfony, vapor, wp, pie',
[
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer',
'add_blackfire',
@ -403,6 +403,7 @@ describe('Tools tests', () => {
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"',
'add_composer_tool flex flex symfony/ global',
'add_grpc_php_plugin latest',
'add_mago latest',
'add_composer_tool name-collision-detector name-collision-detector shipmonk/ scoped',
'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-CS-Fixer/PHP-CS-Fixer/releases/download/v3.2.1/php-cs-fixer.phar php-cs-fixer "-V"',
@ -437,7 +438,7 @@ describe('Tools tests', () => {
it.each([
[
'backward-compatibility-check, behat, blackfire, blackfire-player, churn, composer-dependency-analyser, composer-normalize, composer-require-checker, composer-unused, cs2pr:1.2.3, ecs, flex, grpc_php_plugin:1.2.3, infection, name-collision-detector, 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, rector, symfony-cli, vapor-cli, wp-cli, pie',
'backward-compatibility-check, behat, blackfire, blackfire-player, churn, composer-dependency-analyser, composer-normalize, composer-require-checker, composer-unused, cs2pr:1.2.3, ecs, flex, grpc_php_plugin:1.2.3, infection, mago:0.26.1, name-collision-detector, 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, rector, symfony-cli, vapor-cli, wp-cli, pie',
[
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer',
'add_composer_tool behat behat behat/ scoped',
@ -452,6 +453,7 @@ describe('Tools tests', () => {
'add_composer_tool flex flex symfony/ global',
'add_grpc_php_plugin 1.2.3',
'add_tool https://github.com/infection/infection/releases/latest/download/infection.phar infection "-V"',
'add_mago 0.26.1',
'add_composer_tool name-collision-detector name-collision-detector shipmonk/ scoped',
'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"',
@ -488,7 +490,7 @@ describe('Tools tests', () => {
it.each([
[
'blackfire, blackfire-player:1.2.3, cs2pr, churn, deployer, does_not_exist, flex, name-collision-detector, phinx, phive:0.13.2, php-config, phpize, phpmd, simple-phpunit, symfony, wp, pie',
'blackfire, blackfire-player:1.2.3, cs2pr, churn, deployer, does_not_exist, flex, mago, name-collision-detector, phinx, phive:0.13.2, php-config, phpize, phpmd, simple-phpunit, symfony, wp, pie',
[
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer',
'Add-Blackfire',
@ -498,6 +500,7 @@ describe('Tools tests', () => {
'Add-Tool https://deployer.org/deployer.phar deployer "-V"',
'Tool does_not_exist is not supported',
'Add-ComposerTool flex flex symfony/ global',
'Add-Mago latest',
'Add-ComposerTool name-collision-detector name-collision-detector shipmonk/ scoped',
'Add-ComposerTool phinx phinx robmorgan/ scoped',
'Add-Tool https://github.com/phar-io/phive/releases/download/0.15.3/phive-0.15.3.phar phive "status"',

View File

@ -249,6 +249,12 @@
"domain": "https://github.com",
"version_prefix": "v"
},
"mago": {
"type": "custom-package",
"repository": "carthage-software/mago",
"domain": "https://github.com",
"version_prefix": ""
},
"protoc": {
"type": "custom-package",
"repository": "protocolbuffers/protobuf",

View File

@ -0,0 +1,39 @@
Function Get-MagoTag() {
$releases = 'https://github.com/carthage-software/mago/releases'
if("$mago_tag" -eq "latest") {
$mago_tag = (Get-File -Url $releases/latest).BaseResponse.RequestMessage.RequestUri.Segments[-1]
} else {
try {
[net.httpWebRequest] $request = [net.webRequest]::create("$releases/tag/$mago_tag")
$request.Method = "HEAD"
[net.httpWebResponse] $response = $request.getResponse()
$response.Close()
$mago_tag = "$mago_tag"
} catch {
$mago_tag = (Get-File -Url $releases/latest).BaseResponse.RequestMessage.RequestUri.Segments[-1]
}
}
return $mago_tag
}
Function Add-Mago() {
param(
[Parameter(Mandatory = $true, Position = 0, HelpMessage = 'The mago version to be installed')]
[ValidatePattern('^latest$|^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$')]
[string] $mago_tag
)
$mago_tag = Get-MagoTag
$arch_name = 'x86_64'
if(-not([Environment]::Is64BitOperatingSystem)) {
$arch_name = 'i686'
}
$url = "https://github.com/carthage-software/mago/releases/download/$mago_tag/mago-$mago_tag-$arch_name-pc-windows-msvc.zip"
Get-File -Url $url -OutFile $bin_dir\mago.zip >$null 2>&1
Expand-Archive -Path $bin_dir\mago.zip -DestinationPath $bin_dir\mago -Force >$null 2>&1
Move-Item -Path $bin_dir\mago\mago.exe -Destination $bin_dir\mago.exe
Add-ToProfile $current_profile 'mago' "New-Alias mago $bin_dir\mago.exe"
Add-Log $tick "mago" "Added mago $mago_tag"
printf "$env:GROUP\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "mago" "Click to read the mago related license information"
Write-Output (Invoke-WebRequest https://raw.githubusercontent.com/carthage-software/mago/main/LICENSE).Content
Write-Output "$env:END_GROUP"
}

32
src/scripts/tools/mago.sh Normal file
View File

@ -0,0 +1,32 @@
get_mago_tag() {
if [ "$mago_tag" = "latest" ]; then
mago_tag=$(get -s -n "" https://github.com/carthage-software/mago/releases/latest 2<&1 | grep -m 1 -Eo "tag/([0-9]+(\.[0-9]+)?(\.[0-9]+)?)" | head -n 1 | cut -d '/' -f 2)
else
status_code=$(get -v -n /tmp/mago.tmp "https://github.com/carthage-software/mago/releases/tag/$mago_tag")
if [ "$status_code" = "200" ]; then
mago_tag="$mago_tag"
else
mago_tag=$(get -s -n "" https://github.com/carthage-software/mago/releases/latest 2<&1 | grep -m 1 -Eo "tag/([0-9]+(\.[0-9]+)?(\.[0-9]+)?)" | head -n 1 | cut -d '/' -f 2)
fi
fi
}
add_mago() {
mago_tag=$1
get_mago_tag
(
platform='unknown-linux-gnu'
[ "$(uname -s)" = "Darwin" ] && platform='apple-darwin'
arch="$(uname -m)"
[[ "$arch" = 'arm64' || "$arch" = 'aarch64' ]] && arch='aarch64'
[[ "$arch" = 'x86_64' || "$arch" = 'amd64' ]] && arch='x86_64'
get -q -n /tmp/mago.tar.gz "https://github.com/carthage-software/mago/releases/download/$mago_tag/mago-$mago_tag-$arch-$platform.tar.gz"
sudo tar -xzf /tmp/mago.tar.gz -C /tmp/
sudo mv /tmp/mago /usr/local/bin/mago
sudo chmod +x /usr/local/bin/mago
) >/dev/null 2>&1
add_log "${tick:?}" "mago" "Added mago $mago_tag"
printf "$GROUP\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "mago" "Click to read the mago related license information"
curl "${curl_opts[@]:?}" https://raw.githubusercontent.com/carthage-software/mago/main/LICENSE
echo "$END_GROUP"
}