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

Template for release body #13

Merged
merged 4 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
38 changes: 14 additions & 24 deletions distribution/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 14 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}));

Expand All @@ -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
});
Expand Down
Binary file modified media/releases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 17 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down