Skip to content

Commit

Permalink
Merge pull request #11 from PaulHatch/feature/short-flag
Browse files Browse the repository at this point in the history
Add support for disabling short tags
  • Loading branch information
PaulHatch authored Dec 20, 2020
2 parents 32d6426 + 959e71f commit 80758ec
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ inputs:
namespace:
description: "Use to create a named sub-version. This value will be appended to tags created for this version."
required: false
short_tags:
description: "If false, only full versions, i.e. 'v1.0.0', will be supported as tags. If true, tags will support truncated minor and patch versions such as 'v1' (default)."
required: true
default: "true"
outputs:
major:
description: "Current major number"
Expand Down
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ const eol = '\n';

const tagPrefix = core.getInput('tag_prefix') || '';
const namespace = core.getInput('namespace') || '';
const shortTags = core.getInput('short_tags') === 'true';

const cmd = async (command, ...args) => {
let output = '', errors = '';
Expand Down Expand Up @@ -1061,7 +1062,7 @@ const setOutput = (major, minor, patch, increment, changed, branch, namespace) =
}

let tag;
if (major === 0 || patch !== 0) {
if (!shortTags || major === 0 || patch !== 0) {
// Always tag pre-release/major version 0 as full version
tag = `${tagPrefix}${major}.${minor}.${patch}`;
} else if (minor !== 0) {
Expand Down Expand Up @@ -1122,7 +1123,8 @@ async function run() {
const minorPattern = core.getInput('minor_pattern', { required: true });
const changePath = core.getInput('change_path') || '';

const releasePattern = namespace === '' ? `${tagPrefix}*[0-9.]` : `${tagPrefix}*[0-9.]-${namespace}`;
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
let major = 0, minor = 0, patch = 0, increment = 0;
let changed = true;

Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const eol = '\n';

const tagPrefix = core.getInput('tag_prefix') || '';
const namespace = core.getInput('namespace') || '';
const shortTags = core.getInput('short_tags') === 'true';

const cmd = async (command, ...args) => {
let output = '', errors = '';
Expand Down Expand Up @@ -40,7 +41,7 @@ const setOutput = (major, minor, patch, increment, changed, branch, namespace) =
}

let tag;
if (major === 0 || patch !== 0) {
if (!shortTags || major === 0 || patch !== 0) {
// Always tag pre-release/major version 0 as full version
tag = `${tagPrefix}${major}.${minor}.${patch}`;
} else if (minor !== 0) {
Expand Down Expand Up @@ -101,7 +102,8 @@ async function run() {
const minorPattern = core.getInput('minor_pattern', { required: true });
const changePath = core.getInput('change_path') || '';

const releasePattern = namespace === '' ? `${tagPrefix}*[0-9.]` : `${tagPrefix}*[0-9.]-${namespace}`;
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
let major = 0, minor = 0, patch = 0, increment = 0;
let changed = true;

Expand Down
18 changes: 17 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const defaultInputs = {
tag_prefix: "v",
major_pattern: "(MAJOR)",
minor_pattern: "(MINOR)",
format: "${major}.${minor}.${patch}"
format: "${major}.${minor}.${patch}",
short_tags: true
};

// Creates a randomly named git repository and returns a function to execute commands in it
Expand Down Expand Up @@ -445,5 +446,20 @@ test('Current tag is used', () => {

expect(result).toMatch('Version is 7.6.5+0');

repo.clean();
});

test('Short tag can be switched off', () => {
const repo = createTestRepo({ tag_prefix: '', short_tags: 'false' }); // 0.0.0

repo.makeCommit('Initial Commit');
repo.makeCommit('Second Commit');
repo.makeCommit('Third Commit');
repo.exec('git tag 7');

const result = repo.runAction();

expect(result).toMatch('Version is 0.0.1+2');

repo.clean();
});
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ it will be given the new version if the build were to be retriggered, for exampl
```yaml
- uses: paulhatch/[email protected]
with:
# The prefix to use to identify tags
branch: "master"
# The prefix to use to identify tags
tag_prefix: "v"
# A string which, if present in a git commit, indicates that a change represents a
Expand All @@ -80,6 +82,9 @@ it will be given the new version if the build were to be retriggered, for exampl
change_path: "src/my-service"
# Named version, will be used as suffix for name version tag
namespace: project-b
# Indicate whether short tags like 'v1' should be supported. If false only full
# tags like 'v1.0.0' will be recognized.
short_tags: true
```
## Using Multiple Versions in the Same Repository
Expand Down

0 comments on commit 80758ec

Please sign in to comment.