Skip to content

Commit

Permalink
feat: create tag name regex option for more precise changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
quant-eagle committed Jan 17, 2021
1 parent a0795a1 commit e4b25b2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
13 changes: 7 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![version](https://img.shields.io/badge/version-1.0.4-yellow.svg)](https://semver.org)
[![version](https://img.shields.io/badge/version-1.0.5-yellow.svg)](https://semver.org)

### :pencil2: :page_with_curl: Conventional Commit Changelog Generator (GitHub Action)

Expand All @@ -9,17 +9,18 @@ The changelog is accessible as action output available to other actions via [out
## Example usage

```yaml
uses: Helmisek/conventional-changelog-generator@v1.0.4
uses: Helmisek/conventional-changelog-generator@v1.0.5
with:
token: ${{ secrets.GITHUB_TOKEN }}
```
## Inputs
| Name | Description | Required | Example |
| --------------- | -------------------------------- | -------- | ----------------------------- |
| `commit-types` | Commit -> changelog mapping | Yes | `feat:Features,bug:Bug Fixes` |
| `template-path` | Path to a custom template to use | No | `CHANGELOG.tpl.md` |
| Name | Description | Required | Example |
| --------------- | ------------------------------------ | -------- | ----------------------------- |
| `commit-types` | Commit -> changelog mapping | Yes | `feat:Features,bug:Bug Fixes` |
| `template-path` | Path to a custom template to use | No | `CHANGELOG.tpl.md` |
| `tag-regex` | A custom regex to filter versions by | No | `internal` |

## Outputs

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ inputs:
required: true
template-path:
description: Changelog template
required: true
required: false
tag-regex:
description: Specific regex to filter tags by and to version just between these (useful for SemVer labels)
required: false
outputs:
changelog:
description: Generated changelog for the latest push version tag
Expand Down
25 changes: 22 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5995,6 +5995,7 @@ const workspace = process.env.GITHUB_WORKSPACE;
const token = core.getInput("repo-token", { required: true });
const commitTypes = core.getInput("commit-types", { required: true });
const templateFilePath = core.getInput("template-path", { required: false });
const tagRegex = core.getInput("tag-regex", { required: false });

if (!token) {
throw Error('"token" input is missing!');
Expand All @@ -6010,6 +6011,7 @@ module.exports = {
commitTypes,
workspace,
templateFilePath,
tagRegex,
};


Expand Down Expand Up @@ -6161,7 +6163,7 @@ module.exports = generator;
const core = __webpack_require__(6024);
const compareVersions = __webpack_require__(7597);
const octokit = __webpack_require__(7323);
const { repo, owner } = __webpack_require__(348);
const { repo, owner, tagRegex } = __webpack_require__(348);
const rangedCommits = __webpack_require__(2259);

/**
Expand Down Expand Up @@ -6194,8 +6196,9 @@ const releaseCommitRange = async (releaseTags) => {
const currentReleaseIndex = 0;
const toSHA = releases[currentReleaseIndex].commit.sha;
core.info(`current release sha: "${toSHA}"`);
const previousReleaseIndex = releases.findIndex(
(release, index) => index > currentReleaseIndex
const previousReleaseIndex = findPreviousReleaseIndex(
releases,
currentReleaseIndex
);
const fromSHA = await findBaseSha(previousReleaseIndex, releases, toSHA);
core.info(`previous release sha: "${fromSHA}"`);
Expand All @@ -6205,6 +6208,22 @@ const releaseCommitRange = async (releaseTags) => {
};
};

/***
* If there is a `tagRegex` option set then perform a RegExp search while filtering release.
* Otherwise just find a release with higher index than `currentReleaseIndex`.
*/
function findPreviousReleaseIndex(releases, currentReleaseIndex) {
if (tagRegex == null) {
return releases.findIndex((_, index) => index > currentReleaseIndex);
} else {
const versionRegExp = new RegExp(`${tagRegex}`, "g");
return releases.findIndex(
(release, index) =>
index > currentReleaseIndex && release.name.match(versionRegExp) != null
);
}
}

/**
* If there is no previous release (thus meaning there is only a 1 tag in the repository) then
* set the base sha to the first commit in the repository.
Expand Down
2 changes: 2 additions & 0 deletions src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const workspace = process.env.GITHUB_WORKSPACE;
const token = core.getInput("repo-token", { required: true });
const commitTypes = core.getInput("commit-types", { required: true });
const templateFilePath = core.getInput("template-path", { required: false });
const tagRegex = core.getInput("tag-regex", { required: false });

if (!token) {
throw Error('"token" input is missing!');
Expand All @@ -40,4 +41,5 @@ module.exports = {
commitTypes,
workspace,
templateFilePath,
tagRegex,
};
23 changes: 20 additions & 3 deletions src/history-parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const core = require("@actions/core");
const compareVersions = require("compare-versions");
const octokit = require("./octokit");
const { repo, owner } = require("./context");
const { repo, owner, tagRegex } = require("./context");
const rangedCommits = require("./commits");

/**
Expand Down Expand Up @@ -34,8 +34,9 @@ const releaseCommitRange = async (releaseTags) => {
const currentReleaseIndex = 0;
const toSHA = releases[currentReleaseIndex].commit.sha;
core.info(`current release sha: "${toSHA}"`);
const previousReleaseIndex = releases.findIndex(
(release, index) => index > currentReleaseIndex
const previousReleaseIndex = findPreviousReleaseIndex(
releases,
currentReleaseIndex
);
const fromSHA = await findBaseSha(previousReleaseIndex, releases, toSHA);
core.info(`previous release sha: "${fromSHA}"`);
Expand All @@ -45,6 +46,22 @@ const releaseCommitRange = async (releaseTags) => {
};
};

/***
* If there is a `tagRegex` option set then perform a RegExp search while filtering release.
* Otherwise just find a release with higher index than `currentReleaseIndex`.
*/
function findPreviousReleaseIndex(releases, currentReleaseIndex) {
if (tagRegex == null) {
return releases.findIndex((_, index) => index > currentReleaseIndex);
} else {
const versionRegExp = new RegExp(`${tagRegex}`, "g");
return releases.findIndex(
(release, index) =>
index > currentReleaseIndex && release.name.match(versionRegExp) != null
);
}
}

/**
* If there is no previous release (thus meaning there is only a 1 tag in the repository) then
* set the base sha to the first commit in the repository.
Expand Down

0 comments on commit e4b25b2

Please sign in to comment.