diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index a70050887..374f777a9 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -45,7 +45,11 @@ jest.mock('../src/fetch', () => ({ .fn() .mockImplementation( async (url: string, token?: string): Promise> => { - if (url.includes('atom') && !url.includes('no-')) { + if (url.includes('deployer')) { + return { + data: '[{"version": "1.2.3", "url": "https://deployer.org/releases/v1.2.3/deployer.phar"}]' + }; + } else if (url.includes('atom') && !url.includes('no-')) { return { data: '"releases/tag/1.2.3", "releases/tag/3.2.1", "releases/tag/2.3.1"' }; @@ -283,6 +287,7 @@ describe('Tools tests', () => { version | url ${'latest'} | ${'https://deployer.org/deployer.phar'} ${'1.2.3'} | ${'https://deployer.org/releases/v1.2.3/deployer.phar'} + ${'3.2.1'} | ${'Version missing in deployer manifest'} `('checking addDeployer: $version', async ({version, url}) => { const data = getData({ tool: 'deployer', diff --git a/dist/index.js b/dist/index.js index eb273e646..dee0f1b7d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -799,8 +799,17 @@ async function addDeployer(data) { data['url'] = data['domain'] + '/deployer.phar'; } else { - data['url'] = - data['domain'] + '/releases/v' + data['version'] + '/deployer.phar'; + const manifest = await fetch.fetch('https://deployer.org/manifest.json'); + const version_data = JSON.parse(manifest.data); + const version_key = Object.keys(version_data).find((key) => { + return version_data[key]['version'] === data['version']; + }); + if (version_key) { + data['url'] = version_data[version_key]['url']; + } + else { + return await utils.addLog('$cross', 'deployer', 'Version missing in deployer manifest', data['os']); + } } return await addArchive(data); } diff --git a/src/scripts/tools/add_tools.ps1 b/src/scripts/tools/add_tools.ps1 index a3b7a7390..f69d24e75 100644 --- a/src/scripts/tools/add_tools.ps1 +++ b/src/scripts/tools/add_tools.ps1 @@ -37,7 +37,7 @@ Function Get-ToolVersion() { [Parameter(Position = 1, Mandatory = $true)] $param ) - $alp = "[a-zA-Z0-9]" + $alp = "[a-zA-Z0-9\.]" $version_regex = "[0-9]+((\.{1}$alp+)+)(\.{0})(-$alp+){0,1}" if($tool -eq 'composer') { $composer_branch_alias = Select-String -Pattern "const\sBRANCH_ALIAS_VERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value } @@ -67,6 +67,13 @@ Function Add-ToolsHelper() { Edit-ComposerConfig $bin_dir\$tool } elseif($tool -eq "cs2pr") { (Get-Content $bin_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $bin_dir/cs2pr + } elseif($tool -eq "deployer") { + if(Test-Path $composer_bin\deployer.phar.bat) { + Copy-Item $composer_bin\deployer.phar.bat -Destination $composer_bin\dep.bat + } + if(Test-Path $composer_bin\dep.bat) { + Copy-Item $composer_bin\dep.bat -Destination $composer_bin\deployer.bat + } } elseif($tool -eq "phan") { $extensions += @('fileinfo', 'ast') } elseif($tool -eq "phinx") { diff --git a/src/scripts/tools/add_tools.sh b/src/scripts/tools/add_tools.sh index 06a9a7e26..afc837083 100644 --- a/src/scripts/tools/add_tools.sh +++ b/src/scripts/tools/add_tools.sh @@ -9,7 +9,7 @@ export composer_lock="$composer_home/composer.lock" get_tool_version() { tool=$1 param=$2 - alp="[a-zA-Z0-9]" + alp="[a-zA-Z0-9\.]" version_regex="[0-9]+((\.{1}$alp+)+)(\.{0})(-$alp+){0,1}" if [ "$tool" = "composer" ]; then composer_alias_version="$(grep -Ea "const\sBRANCH_ALIAS_VERSION" "$tool_path_dir/composer" | grep -Eo "$version_regex")" @@ -61,6 +61,13 @@ add_tools_helper() { elif [ "$tool" = "cs2pr" ]; then sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path" 2>/dev/null || sudo sed -i '' 's/\r$//; s/exit(9)/exit(0)/' "$tool_path" + elif [ "$tool" = "deployer" ]; then + if [ -e "$composer_bin"/deployer.phar ]; then + sudo ln -s "$composer_bin"/deployer.phar "$composer_bin"/dep + fi + if [ -e "$composer_bin"/dep ]; then + sudo ln -s "$composer_bin"/dep "$composer_bin"/deployer + fi elif [ "$tool" = "phan" ]; then extensions+=(fileinfo ast) elif [ "$tool" = "phinx" ]; then diff --git a/src/tools.ts b/src/tools.ts index e1315651c..067363a42 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -274,8 +274,25 @@ export async function addDeployer(data: RS): Promise { if (data['version'] === 'latest') { data['url'] = data['domain'] + '/deployer.phar'; } else { - data['url'] = - data['domain'] + '/releases/v' + data['version'] + '/deployer.phar'; + const manifest: RS = await fetch.fetch( + 'https://deployer.org/manifest.json' + ); + const version_data: RSRS = JSON.parse(manifest.data); + const version_key: string | undefined = Object.keys(version_data).find( + (key: string) => { + return version_data[key]['version'] === data['version']; + } + ); + if (version_key) { + data['url'] = version_data[version_key]['url']; + } else { + return await utils.addLog( + '$cross', + 'deployer', + 'Version missing in deployer manifest', + data['os'] + ); + } } return await addArchive(data); }