Only check castor version if castor.php is present

This commit is contained in:
Shivam Mathur 2023-06-24 02:25:43 +05:30
parent c63f07d82e
commit 9d529a72e0
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
5 changed files with 21 additions and 7 deletions

View File

@ -1,3 +1,4 @@
import fs = require('fs');
import * as tools from '../src/tools';
interface IData {
@ -533,7 +534,7 @@ describe('Tools tests', () => {
${'latest'} | ${'darwin'} | ${'releases/latest/download/castor.darwin-amd64.phar'}
${'0.5.1'} | ${'darwin'} | ${'releases/download/v0.5.1/castor.darwin-amd64.phar'}
${'latest'} | ${'win32'} | ${'releases/latest/download/castor.windows-amd64.phar'}
${'0.5.1'} | ${'win32'} | ${'releases/download/v0.5.1/castor.windows-amd64.phar'}
${'0.5.1'} | ${'win32'} | ${'releases/download/v0.5.1/castor.windows-amd64.phar castor -V'}
${'latest'} | ${'openbsd'} | ${'Platform openbsd is not supported'}
`('checking addCastor: $version, $os', async ({version, os, uri}) => {
const data = getData({
@ -543,7 +544,13 @@ describe('Tools tests', () => {
version: version,
os: os
});
if (os === 'win32' && version === '0.5.1') {
fs.writeFileSync('castor.php', '');
expect(await tools.addCastor(data)).toContain(uri);
fs.unlinkSync('castor.php');
} else {
expect(await tools.addCastor(data)).toContain(uri);
}
});
it.each`

3
dist/index.js vendored
View File

@ -841,6 +841,9 @@ async function addCastor(data) {
data['tool'] = 'castor.' + data['os'].replace('win32', 'windows') + '-amd64';
data['url'] = await getUrl(data);
data['tool'] = 'castor';
data['version_parameter'] = fs_1.default.existsSync('castor.php')
? data['version_parameter']
: '';
return await addArchive(data);
}
exports.addCastor = addCastor;

View File

@ -57,7 +57,7 @@ Function Get-ToolVersion() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
$tool,
[Parameter(Position = 1, Mandatory = $true)]
[Parameter(Position = 1, Mandatory = $false)]
$param
)
$alp = "[a-zA-Z0-9\.]"
@ -72,8 +72,10 @@ Function Get-ToolVersion() {
Set-Variable -Name 'composer_version' -Value $composer_version -Scope Global
return "$composer_version"
}
if($null -ne $param) {
return . $tool $param 2> $null | ForEach-Object { $_ -replace "composer $version_regex", '' } | Select-String -Pattern $version_regex | Select-Object -First 1 | ForEach-Object { $_.matches.Value }
}
}
# Helper function to configure tools.
Function Add-ToolsHelper() {
@ -135,8 +137,7 @@ Function Add-Tool() {
[Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNull()]
$tool,
[Parameter(Position = 2, Mandatory = $true)]
[ValidateNotNull()]
[Parameter(Position = 2, Mandatory = $false)]
$ver_param
)
if (Test-Path $bin_dir\$tool) {

View File

@ -19,7 +19,7 @@ get_tool_version() {
composer_version="$(grep -Ea "const\sVERSION" "$tool_path_dir/composer" | grep -Eo "$version_regex")"
fi
echo "$composer_version" | sudo tee /tmp/composer_version
else
elif [ -n "$param" ]; then
$tool "$param" 2>/dev/null | sed -Ee "s/[Cc]omposer(.)?$version_regex//g" | grep -Eo "$version_regex" | head -n 1
fi
}

View File

@ -239,6 +239,9 @@ export async function addCastor(data: RS): Promise<string> {
data['tool'] = 'castor.' + data['os'].replace('win32', 'windows') + '-amd64';
data['url'] = await getUrl(data);
data['tool'] = 'castor';
data['version_parameter'] = fs.existsSync('castor.php')
? data['version_parameter']
: '';
return await addArchive(data);
}