feat(branches): support branches of semantic-release v16+

support branches of semantic-release v16+

#24 #25
This commit is contained in:
cycjimmy 2020-03-21 16:47:29 +08:00
parent c7a37752d9
commit 706c0ef960
8 changed files with 97 additions and 26 deletions

View file

@ -1,29 +1,44 @@
const core = require('@actions/core');
const stringToJson = require('@cycjimmy/awesome-js-funcs/typeConversion/stringToJson').default;
const inputs = require('./inputs.json');
/**
* Handle Branch Option
* Handle Branches Option
* @returns {{}|{branch: string}}
*/
exports.handleBranchOption = () => {
const branchOption = {};
exports.handleBranchesOption = () => {
const branchesOption = {};
const branches = core.getInput(inputs.branches);
const branch = core.getInput(inputs.branch);
if (!branch) {
return branchOption;
}
core.debug(`branches input: ${branches}`);
core.debug(`branch input: ${branch}`);
const semanticVersion = require('semantic-release/package.json').version;
const semanticMajorVersion = Number(semanticVersion.replace(/\..+/g, ''));
core.debug(`semanticMajorVersion: ${semanticMajorVersion}`);
// older than v16
if (semanticMajorVersion < 16) {
branchOption.branch = branch;
} else {
branchOption.branches = [branch];
if (!branch) {
return branchesOption;
}
branchesOption.branch = branch;
return branchesOption;
}
return branchOption;
// above v16
const strNeedConvertToJson = branches || branch || '';
if (!strNeedConvertToJson) {
return branchesOption;
}
const jsonOrStr = stringToJson('' + strNeedConvertToJson);
core.debug(`Converted branches attribute: ${JSON.stringify(jsonOrStr)}`);
branchesOption.branches = jsonOrStr;
return branchesOption;
};
/**