Skip to content

Commit

Permalink
feat: add commit regex input (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Jul 10, 2022
1 parent e959ae3 commit 78dc140
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ jobs:
GITHUB_TOKEN: '${{ secrets.GH_TOKEN }}'
with:
path-to-asyncapi: ./x_asyncapi.json
commit-message: 'release: x-service v{{version}}'
commit-message: 'chore(release): x-service v{{version}}'
commit-release-commit-message-regex: 'chore\(release\): x-service v{{version}}'
```
### Through PR's
Expand Down Expand Up @@ -77,7 +78,7 @@ jobs:
skip-tag: 'true'
skip-commit: 'true'
# Match commit message from PR creation, to know what commit are bump release. Match `commit-message` from PR creation.
commit-message: 'chore\(release\): x-service v{{version}}'
commit-release-commit-message-regex: 'chore\(release\): x-service v{{version}}'
- if: steps.version_bump.outputs.wasBumped == 'true'
name: Create Pull Request with bumped version
uses: peter-evans/create-pull-request@v3
Expand Down Expand Up @@ -150,6 +151,7 @@ Access the new version of the AsyncAPI document after the version was bumped.
| target-branch | Set a custom target branch to use when bumping the version. Useful in cases such as updating the version on main after a tag has been set. | string | '' |
| pre-release-id | Set a custom pre-release id. | string | 'next' |
| commit-message | Set a custom commit message for version bump commit. Useful for skipping additional workflows run on push. Use {{version}} as a placeholder for the new version. | string | 'ci: version bump to {{version}}' |
| release-commit-message-regex | Set the regex to match release commit messages so the action knows which commit messages to use and which to ignore. Usually it is similar or the same as `commit-message`. Use {{version}} as a placeholder for the new version. Defaults to commit-message input. | string |

## Restrictions

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ inputs:
Use {{version}} as a placeholder for the new version.
default: 'ci: version bump to {{version}}'
required: false
release-commit-message-regex:
description: |
Set the regex to match release commit messages so the action knows which commit messages to use and which to ignore. Usually it is similar or the same as `commit-message`. Use {{version}} as a placeholder for the new version. Defaults to commit-message input.
required: false
outputs:
wasBumped:
description: 'Boolean to check if document was bumped'
Expand Down
5 changes: 3 additions & 2 deletions src/bumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = async (
targetBranch,
preReleaseId,
commitMessageToUse,
dryRun) => {
dryRun,
releaseCommitMessageRegex) => {
// eslint-disable-next-line security/detect-non-literal-require
const gitEvents = process.env.GITHUB_EVENT_PATH ? require(process.env.GITHUB_EVENT_PATH) : {};
logInfo(`Found the following git events: ${JSON.stringify(gitEvents, null, 4)}`);
Expand All @@ -46,7 +47,7 @@ module.exports = async (
const commitMessages = await getCommitMessages([pathToDocument, ...referencedFiles], gitEvents, token, workspace);
logInfo(`Found commit messages: ${JSON.stringify(commitMessages, null, 4)}`);

const relevantCommitMessages = getRelevantCommitMessages(commitMessages, commitMessageToUse, tagPrefix);
const relevantCommitMessages = getRelevantCommitMessages(commitMessages, releaseCommitMessageRegex, tagPrefix);
logInfo(`Relevant commit messages: ${JSON.stringify(relevantCommitMessages, null, 4)}`);
if (relevantCommitMessages.length === 0) {
exitSuccess('No action necessary because latest commit was a bump!');
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const { exitSuccess, logError, exitFailure } = require('./utils');
const targetBranch= core.getInput('target-branch');
const preReleaseId = core.getInput('pre-release-id');
const commitMessageToUse = core.getInput('commit-message');
let releaseCommitMessageRegex = core.getInput('release-commit-message-regex');
releaseCommitMessageRegex = releaseCommitMessageRegex === undefined || releaseCommitMessageRegex === '' ? commitMessageToUse : releaseCommitMessageRegex;
const wasBumped = await bumpVersion(tagPrefix,
minorWording,
majorWording,
Expand All @@ -29,7 +31,8 @@ const { exitSuccess, logError, exitFailure } = require('./utils');
targetBranch,
preReleaseId,
commitMessageToUse,
dryRun);
dryRun,
releaseCommitMessageRegex);
if (wasBumped) {
core.setOutput('wasBumped', wasBumped);
exitSuccess('Version bumped!');
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ async function getCommitMessages(relatedFiles, gitEvents, githubToken, workspace
* Get all the commits up until the release commit
*
* @param {*} commitMessages
* @param {*} commitMessageToUse
* @param {*} releaseCommitMessageRegex
* @param {*} tagPrefix
* @returns
*/
function getRelevantCommitMessages(commitMessages, commitMessageToUse, tagPrefix) {
function getRelevantCommitMessages(commitMessages, releaseCommitMessageRegex, tagPrefix) {
// eslint-disable-next-line security/detect-non-literal-regexp
const commitMessageRegex = new RegExp(commitMessageToUse.replace(/{{version}}/g, `${tagPrefix}\\d+\\.\\d+\\.\\d+`), 'ig');
const commitMessageRegex = new RegExp(releaseCommitMessageRegex.replace(/{{version}}/g, `${tagPrefix}\\d+\\.\\d+\\.\\d+`), 'ig');
let commitIndexOfBump = undefined;
// Find the latest commit that matches release commit message
for (const [index, commitMessage] of commitMessages.entries()) {
Expand Down

0 comments on commit 78dc140

Please sign in to comment.