diff --git a/action.yml b/action.yml index 1bb7942..f6469f0 100644 --- a/action.yml +++ b/action.yml @@ -11,26 +11,21 @@ inputs: token: description: Personal access token (PAT) used to create releases required: true - include-hash: - description: Prepend and link commit hash to each entry - required: false - default: false - include-range: - description: Adds a compare link between tags at end of release roles - required: false - default: true exclude: description: Regex to exclude commits based on their title (don't include the initial and final `/`) required: false default: '' - header: - description: Content to prepend at the start of release notes + template: + description: Markdown template to be included in release notes required: false - default: '' - footer: - description: Content to append at the end of release notes + default: | + {commits} + + {range} + commit-template: + description: Markdown template for each commit entry in release notes required: false - default: '' + default: '- {hash} {title}' runs: using: 'node12' main: 'distribution/index.js' diff --git a/distribution/index.js b/distribution/index.js index e7ddd63..3a61b32 100644 --- a/distribution/index.js +++ b/distribution/index.js @@ -172,13 +172,10 @@ async function run() { try { const {owner, repo} = context.repo; - const header = core.getInput('header'); - const footer = core.getInput('footer'); - - // @TODO: Fix boolean checks when https://github.com/actions/toolkit/issues/361 gets resolved - const includeHash = core.getInput('include-hash') === 'true'; - const includeRange = core.getInput('include-range') === 'true'; + const repoURL = process.env.GITHUB_SERVER_URL + '/' + process.env.GITHUB_REPOSITORY; + const releaseTemplate = core.getInput('template'); + const commitTemplate = core.getInput('commit-template'); const exclude = core.getInput('exclude'); // Fetch tags from remote @@ -212,7 +209,7 @@ async function run() { // Get commits between computed range let {stdout: commits} = await execFile('git', ['log', '--format=%H%s', range]); commits = commits.split('\n').filter(Boolean).map(line => ({ - hash: includeHash ? line.slice(0, 8) : '', + hash: line.slice(0, 8), title: line.slice(40) })); @@ -222,34 +219,27 @@ async function run() { } // Generate markdown content - const releaseBody = []; - - if (header) { - releaseBody.push(header + '\n'); - } - + const commitEntries = []; if (commits.length === 0) { - releaseBody.push('_Maintenance release_'); + commitEntries.push('_Maintenance release_'); } else { for (const {hash, title} of commits) { - releaseBody.push(`- ${hash} ${title}`); + const line = commitTemplate + .replace('{hash}', hash) + .replace('{title}', title) + .replace('{url}', repoURL + '/commit/' + hash); + commitEntries.push(line); } } - if (footer) { - releaseBody.push('\n' + footer); - } - - if (includeRange) { - releaseBody.push(`\n[\`${range}\`](https://github.com/${owner}/${repo}/compare/${range})`); - } - const octokit = getOctokit(core.getInput('token')); const createReleaseResponse = await octokit.repos.createRelease({ repo, owner, tag_name: pushedTag, // eslint-disable-line camelcase - body: releaseBody.join('\n'), + body: releaseTemplate + .replace('{commits}', commitEntries.join('\n')) + .replace('{range}', `[\`${range}\`](${repoURL}/compare/${range})`), draft: false, prerelease: false }); diff --git a/index.js b/index.js index e665b50..3620579 100644 --- a/index.js +++ b/index.js @@ -7,13 +7,10 @@ async function run() { try { const {owner, repo} = context.repo; - const header = core.getInput('header'); - const footer = core.getInput('footer'); - - // @TODO: Fix boolean checks when https://github.com/actions/toolkit/issues/361 gets resolved - const includeHash = core.getInput('include-hash') === 'true'; - const includeRange = core.getInput('include-range') === 'true'; + const repoURL = process.env.GITHUB_SERVER_URL + '/' + process.env.GITHUB_REPOSITORY; + const releaseTemplate = core.getInput('template'); + const commitTemplate = core.getInput('commit-template'); const exclude = core.getInput('exclude'); // Fetch tags from remote @@ -47,7 +44,7 @@ async function run() { // Get commits between computed range let {stdout: commits} = await execFile('git', ['log', '--format=%H%s', range]); commits = commits.split('\n').filter(Boolean).map(line => ({ - hash: includeHash ? line.slice(0, 8) : '', + hash: line.slice(0, 8), title: line.slice(40) })); @@ -57,34 +54,27 @@ async function run() { } // Generate markdown content - const releaseBody = []; - - if (header) { - releaseBody.push(header + '\n'); - } - + const commitEntries = []; if (commits.length === 0) { - releaseBody.push('_Maintenance release_'); + commitEntries.push('_Maintenance release_'); } else { for (const {hash, title} of commits) { - releaseBody.push(`- ${hash} ${title}`); + const line = commitTemplate + .replace('{hash}', hash) + .replace('{title}', title) + .replace('{url}', repoURL + '/commit/' + hash); + commitEntries.push(line); } } - if (footer) { - releaseBody.push('\n' + footer); - } - - if (includeRange) { - releaseBody.push(`\n[\`${range}\`](https://github.com/${owner}/${repo}/compare/${range})`); - } - const octokit = getOctokit(core.getInput('token')); const createReleaseResponse = await octokit.repos.createRelease({ repo, owner, tag_name: pushedTag, // eslint-disable-line camelcase - body: releaseBody.join('\n'), + body: releaseTemplate + .replace('{commits}', commitEntries.join('\n')) + .replace('{range}', `[\`${range}\`](${repoURL}/compare/${range})`), draft: false, prerelease: false }); diff --git a/media/releases.png b/media/releases.png index ca0a04b..b0720f8 100644 Binary files a/media/releases.png and b/media/releases.png differ diff --git a/readme.md b/readme.md index 950c953..136f844 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,8 @@ Creates reasonable enough GitHub releases for pushed tags, with the commit log as release body. +The action also has customizable release body, that support markdown, and template fields. See [template](#template) option to see how that works. + By no means is this an action with extensive configurable options except for the ones already provided. But I would love to add some more in the future. ## Usage @@ -31,33 +33,33 @@ The action expects you to do a deep clone of the repository using `actions/check ## Inputs -### header - -Default: `''` - -Content to prepend at the start of release notes. - ### token Required: [Personal access token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) used to create releases. -### footer +### template -Default: `''` +Default: +``` yml +{commits} -Content to append at the end of release notes. +{range} +``` -### include-hash +Markdown template to be included in release notes. Available replacements: -Default: `false` +- `{commits}` List of commits for this release, see [`commit-template`](#commit-template) below for format of each entry. +- `{range}` A link to diff on GitHub between the last and current release. -Prepend and link commit hash to each entry. +### commit-template -### include-range +Default: `'- {hash} {title}'` -Default: `true` +Markdown template for each commit entry in release notes. Available replacements: -Adds a compare link between tags at end of release roles. +- `{title}` A single line title of the commit. +- `{hash}` Abbreviated commit hash, gets linkified automatically in release notes. +- `{url}` Plain link to commit on GitHub. ### exclude