Updated action to include default_prerelease_bump to separate out options.
This commit is contained in:
parent
a5ae58c758
commit
8614426b27
|
@ -43,7 +43,8 @@ jobs:
|
|||
|
||||
#### Customize the tag
|
||||
|
||||
- **default_bump** _(optional)_ - Which type of bump to use when [none is explicitly provided](#bumping) (default: `patch`). You can also set `false` to avoid generating a new tag when none is explicitly provided.
|
||||
- **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`.
|
||||
- **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`).
|
||||
|
|
|
@ -17,9 +17,13 @@ inputs:
|
|||
description: "Required for permission to tag the repo."
|
||||
required: true
|
||||
default_bump:
|
||||
description: "Which type of bump to use when none explicitly provided (default: `patch`)."
|
||||
description: "Which type of bump to use when none explicitly provided when commiting to a release branch (default: `patch`)."
|
||||
required: false
|
||||
default: "patch"
|
||||
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"
|
||||
tag_prefix:
|
||||
description: "A prefix to the tag name (default: `v`)."
|
||||
required: false
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"version": "5.3.0",
|
||||
"version": "5.6.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
|
|
|
@ -17,6 +17,7 @@ import { Await } from './ts';
|
|||
|
||||
export default async function main() {
|
||||
const defaultBump = core.getInput('default_bump') as ReleaseType | 'false';
|
||||
const defaultPreReleaseBump = core.getInput('default_prerelease_bump') as ReleaseType | 'false';
|
||||
const tagPrefix = core.getInput('tag_prefix');
|
||||
const customTag = core.getInput('custom_tag');
|
||||
const releaseBranches = core.getInput('release_branches');
|
||||
|
@ -124,26 +125,39 @@ export default async function main() {
|
|||
{ commits, logger: { log: console.info.bind(console) } }
|
||||
);
|
||||
|
||||
if (!bump && defaultBump === 'false') {
|
||||
// Determine if we should continue with tag creation based on main vs prerelease branch
|
||||
let shouldContinue = true;
|
||||
if (isPrerelease) {
|
||||
if (!bump && defaultPreReleaseBump === 'false') {
|
||||
shouldContinue = false;
|
||||
}
|
||||
} else {
|
||||
if (!bump && defaultBump === 'false') {
|
||||
shouldContinue = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Default bump is set to false and we did not find an automatic bump
|
||||
if (!shouldContinue) {
|
||||
core.debug(
|
||||
'No commit specifies the version bump. Skipping the tag creation.'
|
||||
'No commit specifies the version bump. Skipping the tag creation.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// If we don't have an automatic bump for the prerelease, just set our bump as the default
|
||||
if (isPrerelease && !bump) {
|
||||
bump = defaultPreReleaseBump;
|
||||
}
|
||||
|
||||
// If somebody uses custom release rules on a prerelease branch they might create a 'preprepatch' bump.
|
||||
const preReg = /^pre/;
|
||||
if (isPrerelease && preReg.test(bump)) {
|
||||
bump = bump.replace(preReg, '');
|
||||
}
|
||||
|
||||
// If we have no bump, but want to support incrementing the prerelease number
|
||||
if (isPrerelease && !bump && defaultBump === 'prerelease') {
|
||||
bump = 'release';
|
||||
}
|
||||
|
||||
const releaseType: ReleaseType = isPrerelease
|
||||
? `pre${bump || defaultBump}`
|
||||
? `pre${bump}`
|
||||
: bump || defaultBump;
|
||||
core.setOutput('release_type', releaseType);
|
||||
|
||||
|
|
|
@ -448,11 +448,46 @@ describe('github-tag-action', () => {
|
|||
setInput('pre_release_branches', 'prerelease');
|
||||
});
|
||||
|
||||
it('does not create tag without commits and default_bump set to false', async () => {
|
||||
/*
|
||||
* Given
|
||||
*/
|
||||
setInput('default_prerelease_bump', 'false');
|
||||
const commits: any[] = [];
|
||||
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).not.toBeCalled();
|
||||
expect(mockSetFailed).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('does create prerelease tag', async () => {
|
||||
/*
|
||||
* Given
|
||||
*/
|
||||
setInput('default_bump', 'prerelease');
|
||||
setInput('default_prerelease_bump', 'prerelease');
|
||||
const commits = [{ message: 'this is my first fix', hash: null }];
|
||||
jest
|
||||
.spyOn(utils, 'getCommits')
|
||||
|
@ -460,14 +495,7 @@ describe('github-tag-action', () => {
|
|||
|
||||
const validTags = [
|
||||
{
|
||||
name: 'v0.2.4-prerelease.0',
|
||||
commit: { sha: '012345', url: '' },
|
||||
zipball_url: '',
|
||||
tarball_url: 'string',
|
||||
node_id: 'string',
|
||||
},
|
||||
{
|
||||
name: 'v0.2.3-prerelease.0',
|
||||
name: 'v1.2.3',
|
||||
commit: { sha: '012345', url: '' },
|
||||
zipball_url: '',
|
||||
tarball_url: 'string',
|
||||
|
@ -487,7 +515,7 @@ describe('github-tag-action', () => {
|
|||
* Then
|
||||
*/
|
||||
expect(mockCreateTag).toHaveBeenCalledWith(
|
||||
'v0.2.4-prerelease.1',
|
||||
'v1.2.4-prerelease.0',
|
||||
expect.any(Boolean),
|
||||
expect.any(String)
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue