Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | import { setFailed, startGroup, info, endGroup, setOutput } from '@actions/core';
import { context } from '@actions/github';
import { getVersion, getCommitLog } from './utils';
import { getOptions, getTagRef, processCommits, handleBranchData, fetchCommits, handleNoBaseRef } from './utils-base';
const regexp = /^[.A-Za-z0-9_/-]*$/;
async function run() {
try {
const options = getOptions();
const { template, removeType, showEmoji, owner, repo, types, baseRef, headRef } = options || {};
// If the baseRef is not provided, we will try to get the default branch
if (!baseRef) {
await handleNoBaseRef(options);
}
// If the headRef is not provided, we will use the current sha
if (!headRef) {
options.headRef = context.sha;
}
info(`Commit Content: \x1b[34m${owner}/${repo}\x1b[0m`);
startGroup(`Ref: \x1b[34m${context.ref}\x1b[0m`);
info(`${JSON.stringify(context, null, 2)}`);
endGroup();
if ((context.ref || '').startsWith('refs/tags/')) {
options.tagRef = getVersion(context.ref);
}
if ((context.ref || '').startsWith('refs/heads/')) {
const branch = context.ref.replace(/.*(?=\/)\//, '');
setOutput('branch', branch);
info(`Branch: \x1b[34m${branch}\x1b[0m`);
}
info(`Ref: baseRef(\x1b[32m${options.baseRef}\x1b[0m), options.headRef(\x1b[32m${headRef}\x1b[0m), tagRef(\x1b[32m${options.tagRef}\x1b[0m)`);
await handleBranchData(options);
if ((options.baseRef || '').replace(/^[vV]/, '') === headRef) {
setOutput('tag', options.baseRef);
setOutput('version', options.baseRef.replace(/^[vV]/, ''));
info(`Done: options.baseRef(\x1b[33m${options.baseRef}\x1b[0m) === headRef(\x1b[32m${headRef}\x1b[0m)`);
return;
}
if (regexp.test(headRef) && regexp.test(options.baseRef)) {
const resultData = await fetchCommits(options);
const commitLog = processCommits(resultData, options);
const tagRef = await getTagRef(options);
const { changelog, changelogContent } = getCommitLog(commitLog, { types, showEmoji, removeType, template });
startGroup('Result Changelog');
info(`${changelog.join('\n')}`);
endGroup();
setOutput('changelog', changelogContent);
setOutput('tag', tagRef);
info(`Tag: \x1b[34m${tagRef || headRef || '-'}\x1b[0m`);
info(`Input head-ref: \x1b[34m${headRef}\x1b[0m`);
info(`Input base-ref: \x1b[34m${options.baseRef}\x1b[0m`);
setOutput('compareurl', `https://github.com/${owner}/${repo}/compare/${options.baseRef}...${tagRef || headRef}`);
setOutput('version', getVersion(tagRef || headRef || '').replace(/^v/, ''));
} else {
setFailed('Branch names must contain only numbers, strings, underscores, periods, forward slashes and dashes. (A-z 0-9 _ - / .)');
}
} catch (error) {
info(`path: ${error}`);
startGroup(`Error: \x1b[34m${(error as any).message || error}\x1b[0m`);
info(`${JSON.stringify(error, null, 2)}`);
endGroup();
if (error instanceof Error) {
setFailed(`Could not generate changelog between references because: ${error.message}`);
}
process.exit(1);
}
}
try {
run();
} catch (error) {
if (error instanceof Error) {
setFailed(error.message);
}
}
|