Fix support for deployer

This commit is contained in:
Shivam Mathur 2022-05-31 10:12:38 +05:30
parent aa1fe473f9
commit 74d43be8a3
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
5 changed files with 52 additions and 7 deletions

View File

@ -45,7 +45,11 @@ jest.mock('../src/fetch', () => ({
.fn()
.mockImplementation(
async (url: string, token?: string): Promise<Record<string, string>> => {
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',

13
dist/index.js vendored
View File

@ -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);
}

View File

@ -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") {

View File

@ -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

View File

@ -274,8 +274,25 @@ export async function addDeployer(data: RS): Promise<string> {
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);
}