Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
feat: build for release
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 28, 2021
1 parent 6a75199 commit 0bafdef
Show file tree
Hide file tree
Showing 21 changed files with 202 additions and 177 deletions.
2 changes: 1 addition & 1 deletion build.json
@@ -1 +1 @@
{"owner":"technote-space","repo":"get-diff-action","sha":"c5868edc6fec385c3da06d575bdcf587523cb627","ref":"refs/tags/test/v5.0.1.1161052224","tagName":"test/v5.0.1.1161052224","branch":"gh-actions","tags":["test/v5.0.1.1161052224","test/v5.0.1","test/v5.0","test/v5"],"updated_at":"2021-08-24T03:04:33.880Z"}
{"owner":"technote-space","repo":"get-diff-action","sha":"8b44d1a8545c6ebe54e1a2ccb758353c20341771","ref":"refs/tags/test/v5.0.1.1176308294","tagName":"test/v5.0.1.1176308294","branch":"gh-actions","tags":["test/v5.0.1.1176308294","test/v5.0.1","test/v5.0","test/v5"],"updated_at":"2021-08-28T03:04:40.889Z"}
10 changes: 5 additions & 5 deletions lib/main.js
Expand Up @@ -20,15 +20,15 @@ const constant_1 = require("./constant");
const run = () => __awaiter(void 0, void 0, void 0, function* () {
const logger = new github_action_log_helper_1.Logger();
const context = new context_1.Context();
github_action_helper_1.ContextHelper.showActionInfo(path_1.resolve(__dirname, '..'), logger, context);
if (!filter_github_action_1.isTargetEvent(constant_1.TARGET_EVENTS, context)) {
github_action_helper_1.ContextHelper.showActionInfo((0, path_1.resolve)(__dirname, '..'), logger, context);
if (!(0, filter_github_action_1.isTargetEvent)(constant_1.TARGET_EVENTS, context)) {
logger.info('This is not target event.');
yield process_1.execute(logger, context, true);
yield (0, process_1.execute)(logger, context, true);
return;
}
yield process_1.execute(logger, context);
yield (0, process_1.execute)(logger, context);
});
run().catch(error => {
console.log(error);
core_1.setFailed(error.message);
(0, core_1.setFailed)(error.message);
});
24 changes: 12 additions & 12 deletions lib/process.js
Expand Up @@ -19,13 +19,13 @@ const dumpDiffs = (diffs, logger) => {
};
exports.dumpDiffs = dumpDiffs;
const setResult = (diffs, skipped, logger) => {
const insertions = command_1.sumResults(diffs, item => item.insertions);
const deletions = command_1.sumResults(diffs, item => item.deletions);
const getValue = (setting) => skipped ? core_1.getInput(`${setting.name.toUpperCase()}_DEFAULT`) : `${setting.value()}`;
const insertions = (0, command_1.sumResults)(diffs, item => item.insertions);
const deletions = (0, command_1.sumResults)(diffs, item => item.deletions);
const getValue = (setting) => skipped ? (0, core_1.getInput)(`${setting.name.toUpperCase()}_DEFAULT`) : `${setting.value()}`;
const settings = [
{ name: 'diff', value: () => command_1.getDiffFiles(diffs, false), envNameSuffix: '' },
{ name: 'filtered_diff', value: () => command_1.getDiffFiles(diffs, true) },
{ name: 'matched_files', value: () => command_1.getMatchedFiles(diffs) },
{ name: 'diff', value: () => (0, command_1.getDiffFiles)(diffs, false), envNameSuffix: '' },
{ name: 'filtered_diff', value: () => (0, command_1.getDiffFiles)(diffs, true) },
{ name: 'matched_files', value: () => (0, command_1.getMatchedFiles)(diffs) },
{ name: 'count', value: () => diffs.length },
{ name: 'insertions', value: () => insertions },
{ name: 'deletions', value: () => deletions },
Expand All @@ -35,19 +35,19 @@ const setResult = (diffs, skipped, logger) => {
settings.forEach(setting => {
var _a;
const result = String(getValue(setting));
core_1.setOutput(setting.name, result);
const envName = core_1.getInput('SET_ENV_NAME' + ((_a = setting.envNameSuffix) !== null && _a !== void 0 ? _a : `_${setting.name.toUpperCase()}`));
(0, core_1.setOutput)(setting.name, result);
const envName = (0, core_1.getInput)('SET_ENV_NAME' + ((_a = setting.envNameSuffix) !== null && _a !== void 0 ? _a : `_${setting.name.toUpperCase()}`));
if (envName) {
core_1.exportVariable(envName, result);
(0, core_1.exportVariable)(envName, result);
}
console.log(`${setting.name}: ${result}`);
});
logger.endProcess();
};
exports.setResult = setResult;
const execute = (logger, context, skipped = false) => __awaiter(void 0, void 0, void 0, function* () {
const _diff = skipped ? [] : yield command_1.getGitDiff(logger, context);
exports.dumpDiffs(_diff, logger);
exports.setResult(_diff, skipped, logger);
const _diff = skipped ? [] : yield (0, command_1.getGitDiff)(logger, context);
(0, exports.dumpDiffs)(_diff, logger);
(0, exports.setResult)(_diff, skipped, logger);
});
exports.execute = execute;
38 changes: 19 additions & 19 deletions lib/utils/command.js
Expand Up @@ -22,28 +22,28 @@ const misc_1 = require("./misc");
const constant_1 = require("../constant");
const command = new github_action_helper_1.Command(new github_action_log_helper_1.Logger());
const getRawInput = (name) => process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
const getDot = () => core_1.getInput('DOT', { required: true });
const getFilter = () => core_1.getInput('DIFF_FILTER', { required: true });
const getRelativePath = () => core_1.getInput('RELATIVE');
const getDot = () => (0, core_1.getInput)('DOT', { required: true });
const getFilter = () => (0, core_1.getInput)('DIFF_FILTER', { required: true });
const getRelativePath = () => (0, core_1.getInput)('RELATIVE');
const getOutputFormatType = () => getRawInput('FORMAT');
const escapeWhenJsonFormat = () => github_action_helper_1.Utils.getBoolValue(getRawInput('ESCAPE_JSON'));
const getSeparator = () => getRawInput('SEPARATOR');
const getPatterns = () => github_action_helper_1.Utils.getArrayInput('PATTERNS', undefined, '');
const getFiles = () => github_action_helper_1.Utils.getArrayInput('FILES', undefined, '');
const getWorkspace = (relative) => github_action_helper_1.Utils.getBoolValue(core_1.getInput('ABSOLUTE')) ? (path_1.join(github_action_helper_1.Utils.getWorkspace(), relative) + '/') : '';
const getSummaryIncludeFilesFlag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('SUMMARY_INCLUDE_FILES'));
const isSuppressGitDiffError = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('SUPPRESS_ERROR'));
const isFilterIgnored = (item, files) => !!(files.length && files.includes(path_1.basename(item)));
const isMatched = (item, patterns, options) => !patterns.length || !!multimatch_1.default(item, patterns, options).length;
const toAbsolute = (item, workspace) => path_1.join(workspace, item);
const getWorkspace = (relative) => github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('ABSOLUTE')) ? ((0, path_1.join)(github_action_helper_1.Utils.getWorkspace(), relative) + '/') : '';
const getSummaryIncludeFilesFlag = () => github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('SUMMARY_INCLUDE_FILES'));
const isSuppressGitDiffError = () => github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('SUPPRESS_ERROR'));
const isFilterIgnored = (item, files) => !!(files.length && files.includes((0, path_1.basename)(item)));
const isMatched = (item, patterns, options) => !patterns.length || !!(0, multimatch_1.default)(item, patterns, options).length;
const toAbsolute = (item, workspace) => (0, path_1.join)(workspace, item);
const getMatchOptions = () => ({
nobrace: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_NOBRACE')),
noglobstar: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_NOGLOBSTAR')),
dot: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_DOT')),
noext: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_NOEXT')),
nocase: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_NOCASE')),
matchBase: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_MATCH_BASE')),
nonegate: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_NONEGATE')),
nobrace: github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('MINIMATCH_OPTION_NOBRACE')),
noglobstar: github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('MINIMATCH_OPTION_NOGLOBSTAR')),
dot: github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('MINIMATCH_OPTION_DOT')),
noext: github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('MINIMATCH_OPTION_NOEXT')),
nocase: github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('MINIMATCH_OPTION_NOCASE')),
matchBase: github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('MINIMATCH_OPTION_MATCH_BASE')),
nonegate: github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('MINIMATCH_OPTION_NONEGATE')),
});
const getCompareRef = (ref) => github_action_helper_1.Utils.isRef(ref) ? github_action_helper_1.Utils.getLocalRefspec(ref, constant_1.REMOTE_NAME) : ref;
const getFileDiff = (file, diffInfo, dot) => __awaiter(void 0, void 0, void 0, function* () {
Expand Down Expand Up @@ -72,7 +72,7 @@ const getGitDiff = (logger, context) => __awaiter(void 0, void 0, void 0, functi
logger.warn('Please checkout before call this action.');
return [];
}
const diffInfo = yield misc_1.getDiffInfo(github_action_helper_1.Utils.getOctokit(), context);
const diffInfo = yield (0, misc_1.getDiffInfo)(github_action_helper_1.Utils.getOctokit(), context);
if (diffInfo.base === diffInfo.head) {
return [];
}
Expand Down Expand Up @@ -116,15 +116,15 @@ const getGitDiff = (logger, context) => __awaiter(void 0, void 0, void 0, functi
isMatched: isMatched(item, patterns, options),
}))
.filter(item => item.filterIgnored || item.isMatched)
.map((item) => __awaiter(void 0, void 0, void 0, function* () { return (Object.assign(Object.assign({}, item), yield exports.getFileDiff(item, diffInfo, dot))); }))
.map((item) => __awaiter(void 0, void 0, void 0, function* () { return (Object.assign(Object.assign({}, item), yield (0, exports.getFileDiff)(item, diffInfo, dot))); }))
.reduce((prev, item) => __awaiter(void 0, void 0, void 0, function* () {
const acc = yield prev;
return acc.concat(yield item);
}), Promise.resolve([])))
.map(item => (Object.assign(Object.assign({}, item), { file: toAbsolute(item.file, workspace) })));
});
exports.getGitDiff = getGitDiff;
const format = (items) => getOutputFormatType() !== 'text' ? JSON.stringify(escapeWhenJsonFormat() ? misc_1.escape(items) : items) : misc_1.escape(items).join(getSeparator());
const format = (items) => getOutputFormatType() !== 'text' ? JSON.stringify(escapeWhenJsonFormat() ? (0, misc_1.escape)(items) : items) : (0, misc_1.escape)(items).join(getSeparator());
const getDiffFiles = (diffs, filter) => format(diffs.filter(item => !filter || item.isMatched).map(item => item.file));
exports.getDiffFiles = getDiffFiles;
const getMatchedFiles = (diffs) => format(diffs.filter(item => item.filterIgnored).map(item => item.file));
Expand Down
10 changes: 5 additions & 5 deletions lib/utils/misc.js
Expand Up @@ -29,12 +29,12 @@ const getDiffInfoForPR = (pull, context) => ({
exports.getDiffInfoForPR = getDiffInfoForPR;
const isDefaultBranch = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () { return (yield (new github_action_helper_1.ApiHelper(octokit, context)).getDefaultBranch()) === github_action_helper_1.Utils.getBranch(context); });
exports.isDefaultBranch = isDefaultBranch;
const getBase = (context) => core_1.getInput('BASE') || context.payload.before;
const getBase = (context) => (0, core_1.getInput)('BASE') || context.payload.before;
const getDiffInfoForPush = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
if (github_action_helper_1.Utils.isTagRef(context)) {
return { base: '', head: '' };
}
if (!(yield exports.isDefaultBranch(octokit, context))) {
if (!(yield (0, exports.isDefaultBranch)(octokit, context))) {
const pull = yield (new github_action_helper_1.ApiHelper(octokit, context)).findPullRequest(context.ref);
if (pull) {
if (checkOnlyCommit(github_action_helper_1.Utils.ensureNotNullValue(pull.draft, false))) {
Expand Down Expand Up @@ -62,7 +62,7 @@ const getDiffInfoForPush = (octokit, context) => __awaiter(void 0, void 0, void
};
});
exports.getDiffInfoForPush = getDiffInfoForPush;
const checkOnlyCommit = (isDraft) => isDraft && github_action_helper_1.Utils.getBoolValue(core_1.getInput('CHECK_ONLY_COMMIT_WHEN_DRAFT'));
const checkOnlyCommit = (isDraft) => isDraft && github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('CHECK_ONLY_COMMIT_WHEN_DRAFT'));
const getDiffInfo = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
if (context.payload.pull_request) {
if (checkOnlyCommit(context.payload.pull_request.draft)) {
Expand All @@ -71,11 +71,11 @@ const getDiffInfo = (octokit, context) => __awaiter(void 0, void 0, void 0, func
head: context.payload.after,
};
}
return exports.getDiffInfoForPR({
return (0, exports.getDiffInfoForPR)({
base: context.payload.pull_request.base,
head: context.payload.pull_request.head,
}, context);
}
return exports.getDiffInfoForPush(octokit, context);
return (0, exports.getDiffInfoForPush)(octokit, context);
});
exports.getDiffInfo = getDiffInfo;

0 comments on commit 0bafdef

Please sign in to comment.