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 2 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
25 changes: 11 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,23 @@ 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: |
### Changelog
fregante marked this conversation as resolved.
Show resolved Hide resolved

{commits}

{range}
commit-template:
description: Template for each commit entry in release notes
notlmn marked this conversation as resolved.
Show resolved Hide resolved
required: false
default: ''
default: '- {hash} {title}'
runs:
using: 'node12'
main: 'distribution/index.js'
39 changes: 15 additions & 24 deletions distribution/index.js

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

39 changes: 15 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,28 @@ 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('{version}', pushedTag)
fregante marked this conversation as resolved.
Show resolved Hide resolved
.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.
29 changes: 13 additions & 16 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,28 @@ 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: `''`

Content to append at the end of release notes.
Default:
``` yml
### Changelog
notlmn marked this conversation as resolved.
Show resolved Hide resolved

### include-hash
{commits}

Default: `false`
{range}
```

Prepend and link commit hash to each entry.
Markdown template to be included in release notes.
notlmn marked this conversation as resolved.
Show resolved Hide resolved

### include-range
### commit-template

Default: `true`
Default: `'- {hash} {title}'`

Adds a compare link between tags at end of release roles.
Template for each commit entry in release notes.

### exclude

Expand Down