Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Provide force_bump and force_prerelease_bump options #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:

- **default_bump** _(optional)_ - Which type of bump to use when [none is explicitly provided](#bumping) when commiting to a release branch (default: `patch`). You can also set `false` to avoid generating a new tag when none is explicitly provided. Can be `patch, minor or major`.
- **default_prerelease_bump** _(optional)_ - Which type of bump to use when [none is explicitly provided](#bumping) when commiting to a prerelease branch (default: `prerelease`). You can also set `false` to avoid generating a new tag when none is explicitly provided. Can be `prerelease, prepatch, preminor or premajor`.
- **force_bump** _(optional)_ - If specified, it ignores the type of bump provided when committing to a release branch, as well as `default_bump`. You can also set `false` to avoid generating a new tag. Can be `patch, minor or major`.
- **force_prerelease_bump** _(optional)_ - If specified, it ignores the type of bump provided when committing to a release branch, as well as `default_bump`. You can also set `false` to avoid generating a new tag. Can be `prerelease, prepatch, preminor or premajor`.
- **custom_tag** _(optional)_ - Custom tag name. If specified, it overrides bump settings.
- **create_annotated_tag** _(optional)_ - Boolean to create an annotated rather than a lightweight one (default: `false`).
- **tag_prefix** _(optional)_ - A prefix to the tag name (default: `v`).
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ inputs:
description: "Which type of bump to use when none explicitly provided when commiting to a release branch (default: `patch`)."
required: false
default: "patch"
force_bump:
description: "A release type. If specified, it ignores the type of bump provided when committing to a release branch, as well as default_bump"
required: false
default_prerelease_bump:
description: "Which type of bump to use when none explicitly provided when commiting to a prerelease branch (default: `prerelease`)."
required: false
default: "prerelease"
force_prerelease_bump:
description: "A release type. If specified, it ignores the type of bump provided when committing to a prerelease branch, as well as default_prerelease_bump"
required: false
tag_prefix:
description: "A prefix to the tag name (default: `v`)."
required: false
Expand Down
13 changes: 13 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import { Await } from './ts';

export default async function main() {
const defaultBump = core.getInput('default_bump') as ReleaseType | 'false';
const forceBump = core.getInput('force_bump') as ReleaseType | 'false' | '';
const defaultPreReleaseBump = core.getInput('default_prerelease_bump') as
| ReleaseType
| 'false';
const forcePreReleaseBump = core.getInput('force_prerelease_bump') as
| ReleaseType
| 'false'
| '';
const tagPrefix = core.getInput('tag_prefix');
const customTag = core.getInput('custom_tag');
const releaseBranches = core.getInput('release_branches');
Expand Down Expand Up @@ -143,6 +148,14 @@ export default async function main() {
}
}

// Determine if we should override the bump to a given `force` version
if (isPrerelease && forcePreReleaseBump !== '') {
bump = forcePreReleaseBump;
}
if (!isPrerelease && forceBump !== '') {
bump = forceBump;
}

// Default bump is set to false and we did not find an automatic bump
if (!shouldContinue) {
core.debug(
Expand Down
82 changes: 82 additions & 0 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ describe('github-tag-action', () => {
jest.clearAllMocks();
setBranch('release');
setInput('release_branches', 'release');
setInput('force_bump', '');
});

it('does create patch tag', async () => {
Expand Down Expand Up @@ -302,6 +303,47 @@ describe('github-tag-action', () => {
expect(mockSetFailed).not.toBeCalled();
});

it('does create tag as specified by force_bump', async () => {
setInput('force_bump', 'patch');
/*
* Given
*/
const commits = [
{ message: 'feat: this is my first feature', hash: null },
];
jest
.spyOn(utils, 'getCommits')
.mockImplementation(async (sha) => commits);

const validTags = [
{
name: 'v1.2.3',
commit: { sha: '012345', url: '' },
zipball_url: '',
tarball_url: 'string',
node_id: 'string',
},
];
jest
.spyOn(utils, 'getValidTags')
.mockImplementation(async () => validTags);

/*
* When
*/
await action();

/*
* Then
*/
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.2.4',
expect.any(Boolean),
expect.any(String)
);
expect(mockSetFailed).not.toBeCalled();
});

it('does create major tag', async () => {
/*
* Given
Expand Down Expand Up @@ -451,6 +493,7 @@ describe('github-tag-action', () => {
jest.clearAllMocks();
setBranch('prerelease');
setInput('pre_release_branches', 'prerelease');
setInput('force_prerelease_bump', '');
});

it('does not create tag without commits and default_bump set to false', async () => {
Expand Down Expand Up @@ -488,6 +531,45 @@ describe('github-tag-action', () => {
expect(mockSetFailed).not.toBeCalled();
});

it('does create tag with force_prerelease_bump', async () => {
/*
* Given
*/
setInput('force_prerelease_bump', 'prerelease');
const commits = [{ message: 'this is my first fix', hash: null }];
jest
.spyOn(utils, 'getCommits')
.mockImplementation(async (sha) => commits);

const validTags = [
{
name: 'v1.2.3',
commit: { sha: '012345', url: '' },
zipball_url: '',
tarball_url: 'string',
node_id: 'string',
},
];
jest
.spyOn(utils, 'getValidTags')
.mockImplementation(async () => validTags);

/*
* When
*/
await action();

/*
* Then
*/
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.2.4-prerelease.0',
expect.any(Boolean),
expect.any(String)
);
expect(mockSetFailed).not.toBeCalled();
});

it('does create prerelease tag', async () => {
/*
* Given
Expand Down