Skip to content

Commit

Permalink
Merge pull request #16 from shivammathur/develop
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
shivammathur authored Oct 13, 2020
2 parents 154644c + f55a004 commit 3809746
Show file tree
Hide file tree
Showing 13 changed files with 906 additions and 581 deletions.
21 changes: 17 additions & 4 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,28 @@ jest.mock('@actions/core', () => ({
}));

describe('Utils tests', () => {
it('checking readEnv', async () => {
process.env['test'] = 'setup-php';
expect(await utils.readEnv('test')).toBe('setup-php');
expect(await utils.readEnv('undefined')).toBe('');
});

it('checking getInput', async () => {
process.env['test'] = 'cache-extensions';
process.env['undefined'] = '';
expect(await utils.getInput('test', false)).toBe('cache-extensions');
expect(await utils.getInput('undefined', false)).toBe('');
process.env['test'] = 'setup-php';
expect(await utils.getInput('test', false)).toBe('setup-php');
expect(await utils.getInput('cache-extensions', false)).toBe(
'cache-extensions'
);
expect(await utils.getInput('DoesNotExist', false)).toBe('');
expect(async () => {
await utils.getInput('DoesNotExist', true);
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
});

it('checking parseVersion', async () => {
expect(await utils.parseVersion('7')).toBe('7.0');
expect(await utils.parseVersion('7.4')).toBe('7.4');
expect(await utils.parseVersion('latest')).toBe('7.4');
});

it('checking filterExtensions', async () => {
Expand Down
55 changes: 46 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,25 +1054,63 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterExtensions = exports.getInput = void 0;
exports.filterExtensions = exports.parseVersion = exports.getInput = exports.readEnv = void 0;
const core = __importStar(__webpack_require__(470));
/**
* Function to read environment variable and return a string value.
*
* @param property
*/
async function readEnv(property) {
const value = process.env[property];
switch (value) {
case undefined:
return '';
default:
return value;
}
}
exports.readEnv = readEnv;
/**
* Function to get inputs from both with and env annotations.
*
* @param name
* @param mandatory
*/
async function getInput(name, mandatory) {
const input = process.env[name];
switch (input) {
case '':
case undefined:
return core.getInput(name, { required: mandatory });
default:
const input = core.getInput(name);
const env_input = await readEnv(name);
switch (true) {
case input != '':
return input;
case input == '' && env_input != '':
return env_input;
case input == '' && env_input == '' && mandatory:
throw new Error(`Input required and not supplied: ${name}`);
default:
return '';
}
}
exports.getInput = getInput;
/**
* Function to parse PHP version.
*
* @param version
*/
async function parseVersion(version) {
switch (version) {
case 'latest':
return '7.4';
default:
switch (true) {
case version.length > 1:
return version.slice(0, 3);
default:
return version + '.0';
}
}
}
exports.parseVersion = parseVersion;
/**
* Function to filter extensions
*
Expand Down Expand Up @@ -1687,8 +1725,7 @@ const utils = __importStar(__webpack_require__(163));
*/
async function run() {
try {
let version = await utils.getInput('php-version', true);
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
const version = await utils.parseVersion(await utils.getInput('php-version', true));
const extensions = await utils.filterExtensions(await utils.getInput('extensions', true));
const key = await utils.getInput('key', true);
const script_path = path.join(__dirname, '../src/extensions.sh');
Expand Down
Loading

0 comments on commit 3809746

Please sign in to comment.