Skip to content

Commit

Permalink
Merge pull request #746 from pyrech/support-castor
Browse files Browse the repository at this point in the history
Add support for tool jolicode/castor
  • Loading branch information
shivammathur authored Jun 23, 2023
2 parents 4bd44f2 + 7ce22e0 commit a683e80
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ PHP extensions can be set up using the `extensions` input. It accepts a `string`

These tools can be set up globally using the `tools` input. It accepts a string in csv-format.

[`behat`], [`blackfire`], [`blackfire-player`], [`churn`], [`codeception`], [`composer`], [`composer-normalize`], [`composer-prefetcher`], [`composer-require-checker`], [`composer-unused`], [`cs2pr`], [`deployer`], [`flex`], [`grpc_php_plugin`], [`infection`], [`parallel-lint`], [`pecl`], [`phan`], [`phing`], [`phinx`], [`phive`], [`php-config`], [`php-cs-fixer`], [`phpcbf`], [`phpcpd`], [`phpcs`], [`phpdoc`] or [`phpDocumentor`], [`phpize`], [`phplint`], [`phpmd`], [`phpspec`], [`phpstan`], [`phpunit`], [`phpunit-bridge`], [`phpunit-polyfills`], [`pint`], [`prestissimo`], [`protoc`], [`psalm`], [`rector`], [`symfony`] or [`symfony-cli`], [`vapor`] or [`vapor-cli`], [`wp`] or [`wp-cli`]
[`behat`], [`blackfire`], [`blackfire-player`], [`castor`], [`churn`], [`codeception`], [`composer`], [`composer-normalize`], [`composer-prefetcher`], [`composer-require-checker`], [`composer-unused`], [`cs2pr`], [`deployer`], [`flex`], [`grpc_php_plugin`], [`infection`], [`parallel-lint`], [`pecl`], [`phan`], [`phing`], [`phinx`], [`phive`], [`php-config`], [`php-cs-fixer`], [`phpcbf`], [`phpcpd`], [`phpcs`], [`phpdoc`] or [`phpDocumentor`], [`phpize`], [`phplint`], [`phpmd`], [`phpspec`], [`phpstan`], [`phpunit`], [`phpunit-bridge`], [`phpunit-polyfills`], [`pint`], [`prestissimo`], [`protoc`], [`psalm`], [`rector`], [`symfony`] or [`symfony-cli`], [`vapor`] or [`vapor-cli`], [`wp`] or [`wp-cli`]

```yaml
- name: Setup PHP with tools
Expand Down Expand Up @@ -1028,6 +1028,7 @@ These companies generously provide setup-php their products and services to aid
[`behat`]: https://docs.behat.org/en/latest/
[`blackfire`]: https://blackfire.io/docs/php/index
[`blackfire-player`]: https://blackfire.io/docs/builds-cookbooks/player
[`castor`]: https://github.com/jolicode/castor
[`churn`]: https://github.com/bmitch/churn-php
[`codeception`]: https://codeception.com/
[`composer`]: https://getcomposer.org/
Expand Down
19 changes: 19 additions & 0 deletions __tests__/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,25 @@ describe('Tools tests', () => {
}
);

it.each`
version | os | uri
${'latest'} | ${'linux'} | ${'releases/latest/download/castor.linux-amd64.phar'}
${'0.5.1'} | ${'linux'} | ${'releases/download/v0.5.1/castor.linux-amd64.phar'}
${'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'}
${'latest'} | ${'openbsd'} | ${'Platform openbsd is not supported'}
`('checking addCastor: $version, $os', async ({version, os, uri}) => {
const data = getData({
tool: 'castor',
php_version: '8.1',
version: version,
os: os
});
expect(await tools.addCastor(data)).toContain(uri);
});

it.each`
tools_csv | script
${'none'} | ${''}
Expand Down
26 changes: 25 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addTools = exports.functionRecord = exports.getData = exports.addWPCLI = exports.addPHPUnitTools = exports.addPhive = exports.addPhing = exports.addPECL = exports.addDevTools = exports.addDeployer = exports.addComposer = exports.addBlackfirePlayer = exports.addPackage = exports.addArchive = exports.getPharUrl = exports.getUrl = exports.filterList = exports.getRelease = exports.getVersion = exports.getLatestVersion = exports.getSemverVersion = void 0;
exports.addTools = exports.functionRecord = exports.getData = exports.addWPCLI = exports.addPHPUnitTools = exports.addPhive = exports.addPhing = exports.addPECL = exports.addDevTools = exports.addDeployer = exports.addComposer = exports.addCastor = exports.addBlackfirePlayer = exports.addPackage = exports.addArchive = exports.getPharUrl = exports.getUrl = exports.filterList = exports.getRelease = exports.getVersion = exports.getLatestVersion = exports.getSemverVersion = void 0;
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const fetch = __importStar(__nccwpck_require__(2387));
Expand Down Expand Up @@ -837,6 +837,29 @@ async function addBlackfirePlayer(data) {
return addArchive(data);
}
exports.addBlackfirePlayer = addBlackfirePlayer;
async function addCastor(data) {
let filename;
switch (data['os']) {
case 'linux':
case 'darwin':
filename = 'castor.' + data['os'] + '-amd64.phar';
break;
case 'win32':
filename = 'castor.windows-amd64.phar';
break;
default:
return await utils.log('Platform ' + data['os'] + ' is not supported', data['os'], 'error');
}
if (data['version'] === 'latest') {
data['uri'] = ['releases/latest/download', filename].join('/');
}
else {
data['uri'] = ['releases/download', 'v' + data['version'], filename].join('/');
}
data['url'] = [data['domain'], data['repository'], data['uri']].join('/');
return await addArchive(data);
}
exports.addCastor = addCastor;
async function addComposer(data) {
const channel = data['version'].replace('latest', 'stable');
const github = data['github'];
Expand Down Expand Up @@ -1015,6 +1038,7 @@ async function getData(release, php_version, os) {
}
exports.getData = getData;
exports.functionRecord = {
castor: addCastor,
composer: addComposer,
deployer: addDeployer,
dev_tools: addDevTools,
Expand Down
6 changes: 6 additions & 0 deletions src/configs/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@
"version_prefix": "v",
"version_parameter": "-V"
},
"castor": {
"type": "custom-function",
"domain": "https://github.com",
"repository": "jolicode/castor",
"function": "castor"
},
"composer": {
"type": "custom-function",
"domain": "https://getcomposer.org",
Expand Down
34 changes: 34 additions & 0 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,39 @@ export async function addBlackfirePlayer(data: RS): Promise<string> {
return addArchive(data);
}

/**
* Function to add Castor
*
* @param data
*/
export async function addCastor(data: RS): Promise<string> {
let filename: string;
switch (data['os']) {
case 'linux':
case 'darwin':
filename = 'castor.' + data['os'] + '-amd64.phar';
break;
case 'win32':
filename = 'castor.windows-amd64.phar';
break;
default:
return await utils.log(
'Platform ' + data['os'] + ' is not supported',
data['os'],
'error'
);
}
if (data['version'] === 'latest') {
data['uri'] = ['releases/latest/download', filename].join('/');
} else {
data['uri'] = ['releases/download', 'v' + data['version'], filename].join(
'/'
);
}
data['url'] = [data['domain'], data['repository'], data['uri']].join('/');
return await addArchive(data);
}

/**
* Function to add composer
*
Expand Down Expand Up @@ -479,6 +512,7 @@ export async function getData(
}

export const functionRecord: Record<string, (data: RS) => Promise<string>> = {
castor: addCastor,
composer: addComposer,
deployer: addDeployer,
dev_tools: addDevTools,
Expand Down

0 comments on commit a683e80

Please sign in to comment.