Skip to content

Commit

Permalink
Fix support for deployer
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed May 31, 2022
1 parent aa1fe47 commit 74d43be
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
7 changes: 6 additions & 1 deletion __tests__/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
};
Expand Down Expand Up @@ -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',
Expand Down
13 changes: 11 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 8 additions & 1 deletion src/scripts/tools/add_tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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") {
Expand Down
9 changes: 8 additions & 1 deletion src/scripts/tools/add_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 74d43be

Please sign in to comment.